mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 03:55:19 -04:00
allow you to hold block ID 255 in inventory
This commit is contained in:
parent
b2cacf6dc0
commit
f5e508ceb1
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user