diff --git a/ClassicalSharp/Game/Inventory.cs b/ClassicalSharp/Game/Inventory.cs index faaab3893..81c71e36f 100644 --- a/ClassicalSharp/Game/Inventory.cs +++ b/ClassicalSharp/Game/Inventory.cs @@ -14,18 +14,23 @@ namespace ClassicalSharp { public void Init(Game game) { this.game = game; - SetDefaultMapping(); + Reset(game); + } + + public void Reset(Game game) { + SetDefaultMapping(); + CanChangeHeldBlock = true; + CanPick = true; } public void Ready(Game game) { } - public void Reset(Game game) { SetDefaultMapping(); } public void OnNewMap(Game game) { } public void OnNewMapLoaded(Game game) { } public void Dispose() { } int selectedI, offset; Game game; - public bool CanChangeHeldBlock = true; + public bool CanChangeHeldBlock, CanPick; public const int BlocksPerRow = 9, Rows = 9; public BlockID[] Hotbar = new BlockID[BlocksPerRow * Rows]; @@ -50,6 +55,7 @@ namespace ClassicalSharp { get { return selectedI; } set { if (!CanChangeSelected()) return; + CanPick = true; selectedI = value; game.Events.RaiseHeldBlockChanged(); } } @@ -70,6 +76,7 @@ namespace ClassicalSharp { get { return Hotbar[Offset + selectedI]; } set { if (!CanChangeSelected()) return; + CanPick = true; // Change the selected index if this block already in hotbar for (int i = 0; i < BlocksPerRow; i++) { @@ -100,7 +107,7 @@ namespace ClassicalSharp { BlockID DefaultMapping(int i) { #if USE16_BIT - if ((i >= Block.CpeCount && i < 256) || i == Block.Air) return Block.Invalid; + if ((i >= Block.CpeCount && i < 256) || i == Block.Air) return Block.Invalid; #else if (i >= Block.CpeCount || i == Block.Air) return Block.Invalid; #endif diff --git a/ClassicalSharp/Game/PickingHandler.cs b/ClassicalSharp/Game/PickingHandler.cs index afdaf8480..372d8b705 100644 --- a/ClassicalSharp/Game/PickingHandler.cs +++ b/ClassicalSharp/Game/PickingHandler.cs @@ -38,7 +38,7 @@ namespace ClassicalSharp { input.ButtonStateChanged(MouseButton.Middle, middle); } - if (game.Gui.ActiveScreen.HandlesAllInput || inv.Selected == Block.Invalid) return; + if (game.Gui.ActiveScreen.HandlesAllInput || !inv.CanPick) return; if (left) { if (game.Mode.PickingLeft()) return; diff --git a/ClassicalSharp/Network/Protocols/CPE.cs b/ClassicalSharp/Network/Protocols/CPE.cs index 40058df9b..fe85fcc3b 100644 --- a/ClassicalSharp/Network/Protocols/CPE.cs +++ b/ClassicalSharp/Network/Protocols/CPE.cs @@ -89,12 +89,12 @@ namespace ClassicalSharp.Network.Protocols { void HandleHoldThis() { BlockID block = reader.ReadUInt8(); - if (block == Block.Air) block = Block.Invalid; bool canChange = reader.ReadUInt8() == 0; game.Inventory.CanChangeHeldBlock = true; game.Inventory.Selected = block; game.Inventory.CanChangeHeldBlock = canChange; + game.Inventory.CanPick = block != Block.Air; } void HandleSetTextHotkey() { diff --git a/src/Client/Inventory.c b/src/Client/Inventory.c index b0cabef90..b9d70bf37 100644 --- a/src/Client/Inventory.c +++ b/src/Client/Inventory.c @@ -3,10 +3,12 @@ #include "Game.h" #include "Block.h" #include "Event.h" +#include "Chat.h" bool Inventory_CanChangeSelected(void) { if (!Inventory_CanChangeHeldBlock) { - //game.Chat.Add("&e/client: &cThe server has forbidden you from changing your held block."); + String msg = String_FromConst("&e/client: &cThe server has forbidden you from changing your held block."); + Chat_Add(&msg); return false; } return true; @@ -163,10 +165,15 @@ void Inventory_Insert(Int32 i, BlockID block) { Inventory_Map[i] = block; } +void Inventory_ResetState(void) { + Inventory_SetDefaultMapping(); + Inventory_CanChangeHeldBlock = true; + Inventory_CanPick = true; +} IGameComponent Inventory_MakeComponent(void) { IGameComponent comp = IGameComponent_MakeEmpty(); - comp.Init = Inventory_SetDefaultMapping; - comp.Reset = Inventory_SetDefaultMapping; + comp.Init = Inventory_ResetState; + comp.Reset = Inventory_ResetState; return comp; } \ No newline at end of file diff --git a/src/Client/Inventory.h b/src/Client/Inventory.h index 53a2f58e8..1d75cd5f7 100644 --- a/src/Client/Inventory.h +++ b/src/Client/Inventory.h @@ -21,7 +21,7 @@ Int32 Inventory_Offset; #define Inventory_Get(idx) (Inventory_Table[Inventory_Offset + (idx)]) #define Inventory_Set(idx, block) Inventory_Table[Inventory_Offset + (idx)] = block #define Inventory_SelectedBlock Inventory_Get(Inventory_SelectedIndex) -bool Inventory_CanChangeHeldBlock; +bool Inventory_CanChangeHeldBlock, Inventory_CanPick; bool Inventory_CanChangeSelected(void); void Inventory_SetSelectedIndex(Int32 index);