mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -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) {
|
public void Init(Game game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
Reset(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset(Game game) {
|
||||||
SetDefaultMapping();
|
SetDefaultMapping();
|
||||||
|
CanChangeHeldBlock = true;
|
||||||
|
CanPick = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Ready(Game game) { }
|
public void Ready(Game game) { }
|
||||||
public void Reset(Game game) { SetDefaultMapping(); }
|
|
||||||
public void OnNewMap(Game game) { }
|
public void OnNewMap(Game game) { }
|
||||||
public void OnNewMapLoaded(Game game) { }
|
public void OnNewMapLoaded(Game game) { }
|
||||||
public void Dispose() { }
|
public void Dispose() { }
|
||||||
|
|
||||||
int selectedI, offset;
|
int selectedI, offset;
|
||||||
Game game;
|
Game game;
|
||||||
public bool CanChangeHeldBlock = true;
|
public bool CanChangeHeldBlock, CanPick;
|
||||||
|
|
||||||
public const int BlocksPerRow = 9, Rows = 9;
|
public const int BlocksPerRow = 9, Rows = 9;
|
||||||
public BlockID[] Hotbar = new BlockID[BlocksPerRow * Rows];
|
public BlockID[] Hotbar = new BlockID[BlocksPerRow * Rows];
|
||||||
@ -50,6 +55,7 @@ namespace ClassicalSharp {
|
|||||||
get { return selectedI; }
|
get { return selectedI; }
|
||||||
set {
|
set {
|
||||||
if (!CanChangeSelected()) return;
|
if (!CanChangeSelected()) return;
|
||||||
|
CanPick = true;
|
||||||
selectedI = value; game.Events.RaiseHeldBlockChanged();
|
selectedI = value; game.Events.RaiseHeldBlockChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,6 +76,7 @@ namespace ClassicalSharp {
|
|||||||
get { return Hotbar[Offset + selectedI]; }
|
get { return Hotbar[Offset + selectedI]; }
|
||||||
set {
|
set {
|
||||||
if (!CanChangeSelected()) return;
|
if (!CanChangeSelected()) return;
|
||||||
|
CanPick = true;
|
||||||
|
|
||||||
// Change the selected index if this block already in hotbar
|
// Change the selected index if this block already in hotbar
|
||||||
for (int i = 0; i < BlocksPerRow; i++) {
|
for (int i = 0; i < BlocksPerRow; i++) {
|
||||||
|
@ -38,7 +38,7 @@ namespace ClassicalSharp {
|
|||||||
input.ButtonStateChanged(MouseButton.Middle, middle);
|
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 (left) {
|
||||||
if (game.Mode.PickingLeft()) return;
|
if (game.Mode.PickingLeft()) return;
|
||||||
|
@ -89,12 +89,12 @@ namespace ClassicalSharp.Network.Protocols {
|
|||||||
|
|
||||||
void HandleHoldThis() {
|
void HandleHoldThis() {
|
||||||
BlockID block = reader.ReadUInt8();
|
BlockID block = reader.ReadUInt8();
|
||||||
if (block == Block.Air) block = Block.Invalid;
|
|
||||||
bool canChange = reader.ReadUInt8() == 0;
|
bool canChange = reader.ReadUInt8() == 0;
|
||||||
|
|
||||||
game.Inventory.CanChangeHeldBlock = true;
|
game.Inventory.CanChangeHeldBlock = true;
|
||||||
game.Inventory.Selected = block;
|
game.Inventory.Selected = block;
|
||||||
game.Inventory.CanChangeHeldBlock = canChange;
|
game.Inventory.CanChangeHeldBlock = canChange;
|
||||||
|
game.Inventory.CanPick = block != Block.Air;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleSetTextHotkey() {
|
void HandleSetTextHotkey() {
|
||||||
|
@ -3,10 +3,12 @@
|
|||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "Block.h"
|
#include "Block.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
#include "Chat.h"
|
||||||
|
|
||||||
bool Inventory_CanChangeSelected(void) {
|
bool Inventory_CanChangeSelected(void) {
|
||||||
if (!Inventory_CanChangeHeldBlock) {
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -163,10 +165,15 @@ void Inventory_Insert(Int32 i, BlockID block) {
|
|||||||
Inventory_Map[i] = block;
|
Inventory_Map[i] = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Inventory_ResetState(void) {
|
||||||
|
Inventory_SetDefaultMapping();
|
||||||
|
Inventory_CanChangeHeldBlock = true;
|
||||||
|
Inventory_CanPick = true;
|
||||||
|
}
|
||||||
|
|
||||||
IGameComponent Inventory_MakeComponent(void) {
|
IGameComponent Inventory_MakeComponent(void) {
|
||||||
IGameComponent comp = IGameComponent_MakeEmpty();
|
IGameComponent comp = IGameComponent_MakeEmpty();
|
||||||
comp.Init = Inventory_SetDefaultMapping;
|
comp.Init = Inventory_ResetState;
|
||||||
comp.Reset = Inventory_SetDefaultMapping;
|
comp.Reset = Inventory_ResetState;
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ Int32 Inventory_Offset;
|
|||||||
#define Inventory_Get(idx) (Inventory_Table[Inventory_Offset + (idx)])
|
#define Inventory_Get(idx) (Inventory_Table[Inventory_Offset + (idx)])
|
||||||
#define Inventory_Set(idx, block) Inventory_Table[Inventory_Offset + (idx)] = block
|
#define Inventory_Set(idx, block) Inventory_Table[Inventory_Offset + (idx)] = block
|
||||||
#define Inventory_SelectedBlock Inventory_Get(Inventory_SelectedIndex)
|
#define Inventory_SelectedBlock Inventory_Get(Inventory_SelectedIndex)
|
||||||
bool Inventory_CanChangeHeldBlock;
|
bool Inventory_CanChangeHeldBlock, Inventory_CanPick;
|
||||||
|
|
||||||
bool Inventory_CanChangeSelected(void);
|
bool Inventory_CanChangeSelected(void);
|
||||||
void Inventory_SetSelectedIndex(Int32 index);
|
void Inventory_SetSelectedIndex(Int32 index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user