diff --git a/2D/Screens/BlockSelectScreen.cs b/2D/Screens/BlockSelectScreen.cs index b4a29d42e..8af953f53 100644 --- a/2D/Screens/BlockSelectScreen.cs +++ b/2D/Screens/BlockSelectScreen.cs @@ -186,11 +186,7 @@ namespace ClassicalSharp { public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) { if( button == MouseButton.Left && selectedIndex != -1 ) { BlockDrawInfo info = blocksTable[selectedIndex]; - try { - Window.HeldBlock = info.BlockId; - } catch( InvalidOperationException ) { - Window.AddChat( "&e/client: &cThe server has forbidden you from changing your held block." ); - } + Window.HeldBlock = info.BlockId; Window.SetNewScreen( new NormalScreen( Window ) ); } return true; diff --git a/2D/Widgets/BlockHotbarWidget.cs b/2D/Widgets/BlockHotbarWidget.cs index 9fcd206d5..7753d7f16 100644 --- a/2D/Widgets/BlockHotbarWidget.cs +++ b/2D/Widgets/BlockHotbarWidget.cs @@ -18,11 +18,7 @@ namespace ClassicalSharp { public override bool HandlesKeyDown( Key key ) { if( key >= Key.Number1 && key <= Key.Number9 ) { - try { - Window.HeldBlockIndex = (int)key - (int)Key.Number1; - } catch( InvalidOperationException ) { - Window.AddChat( "&e/client: &cThe server has forbidden you from changing your held block." ); - } + Window.HeldBlockIndex = (int)key - (int)Key.Number1; return true; } return false; diff --git a/Game/Game.InputHandling.cs b/Game/Game.InputHandling.cs index 5c60971c7..9ba84f465 100644 --- a/Game/Game.InputHandling.cs +++ b/Game/Game.InputHandling.cs @@ -38,9 +38,17 @@ namespace ClassicalSharp { void MouseButtonDown( object sender, MouseButtonEventArgs e ) { if( activeScreen == null || !activeScreen.HandlesMouseClick( e.X, e.Y, e.Button ) ) { - bool left = e.Button == MouseButton.Left; - bool right = e.Button == MouseButton.Right; - PickBlocks( false, left, right ); + if( e.Button == MouseButton.Middle ) { + if( SelectedPos == null || !Map.IsValidPos( SelectedPos.BlockPos ) ) return; + byte block = Map.GetBlock( SelectedPos.BlockPos ); + if( CanPlace[block] || CanDelete[block] ) { + HeldBlock = (Block)block; + } + } else { + bool left = e.Button == MouseButton.Left; + bool right = e.Button == MouseButton.Right; + PickBlocks( false, left, right ); + } } else { lastClick = DateTime.UtcNow; } diff --git a/Game/Game.cs b/Game/Game.cs index 61ca33046..49bd5d104 100644 --- a/Game/Game.cs +++ b/Game/Game.cs @@ -57,8 +57,10 @@ namespace ClassicalSharp { public int HeldBlockIndex { get { return hotbarIndex; } set { - if( !CanChangeHeldBlock ) - throw new InvalidOperationException( "Server has forbidden changing held block." ); + if( !CanChangeHeldBlock ) { + AddChat( "&e/client: &cThe server has forbidden you from changing your held block." ); + return; + } hotbarIndex = value; RaiseHeldBlockChanged(); } @@ -67,8 +69,10 @@ namespace ClassicalSharp { public Block HeldBlock { get { return BlocksHotbar[hotbarIndex]; } set { - if( !CanChangeHeldBlock ) - throw new InvalidOperationException( "Server has forbidden changing held block." ); + if( !CanChangeHeldBlock ) { + AddChat( "&e/client: &cThe server has forbidden you from changing your held block." ); + return; + } BlocksHotbar[hotbarIndex] = value; RaiseHeldBlockChanged(); }