Permalink
Browse files

allow you to hold block ID 255 in inventory

  • Loading branch information...
UnknownShadow200 committed Dec 7, 2017
1 parent b2cacf6 commit f5e508ceb121ca8fddd148483c12ae620ecd7155
@@ -14,18 +14,23 @@ public sealed class Inventory : IGameComponent {
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 @@ public sealed class Inventory : IGameComponent {
get { return selectedI; }
set {
if (!CanChangeSelected()) return;
CanPick = true;
selectedI = value; game.Events.RaiseHeldBlockChanged();
}
}
@@ -70,6 +76,7 @@ public sealed class Inventory : IGameComponent {
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 @@ public sealed class Inventory : IGameComponent {
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
@@ -38,7 +38,7 @@ public sealed class PickingHandler {
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;
@@ -89,12 +89,12 @@ public sealed class CPEProtocol : IProtocol {
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() {
View
@@ -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;
}
View
@@ -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);

0 comments on commit f5e508c

Please sign in to comment.