mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Get rid of InventoryPermissions and just use bool array instead
This commit is contained in:
parent
c23ba90c1f
commit
5a03fda9bd
12 changed files with 34 additions and 52 deletions
|
@ -175,9 +175,9 @@ namespace ClassicalSharp.Gui.Screens {
|
|||
buffer.Append(ref index, " (ID ");
|
||||
buffer.AppendNum(ref index, block);
|
||||
buffer.Append(ref index, "&f, place ");
|
||||
buffer.Append(ref index, game.Inventory.CanPlace[block] ? "&aYes" : "&cNo");
|
||||
buffer.Append(ref index, BlockInfo.CanPlace[block] ? "&aYes" : "&cNo");
|
||||
buffer.Append(ref index, "&f, delete ");
|
||||
buffer.Append(ref index, game.Inventory.CanDelete[block] ? "&aYes" : "&cNo");
|
||||
buffer.Append(ref index, BlockInfo.CanDelete[block] ? "&aYes" : "&cNo");
|
||||
buffer.Append(ref index, "&f)");
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,10 @@ namespace ClassicalSharp {
|
|||
public static SoundType[] DigSounds = new SoundType[Block.Count];
|
||||
|
||||
public static SoundType[] StepSounds = new SoundType[Block.Count];
|
||||
|
||||
public static bool[] CanPlace = new bool[Block.Count];
|
||||
|
||||
public static bool[] CanDelete = new bool[Block.Count];
|
||||
|
||||
/// <summary> Gets whether the given block has a tinting colour applied to it when rendered. </summary>
|
||||
/// <remarks> The tinting colour used is the block's fog colour. </remarks>
|
||||
|
@ -130,17 +134,17 @@ namespace ClassicalSharp {
|
|||
}
|
||||
|
||||
/// <summary> Initialises the default blocks the player is allowed to place and delete. </summary>
|
||||
public static void SetDefaultPerms(InventoryPermissions place, InventoryPermissions delete) {
|
||||
public static void SetDefaultPerms() {
|
||||
for (int block = Block.Stone; block <= Block.MaxDefinedBlock; block++) {
|
||||
place[block] = true;
|
||||
delete[block] = true;
|
||||
CanPlace[block] = true;
|
||||
CanPlace[block] = true;
|
||||
}
|
||||
|
||||
place[Block.Lava] = false; delete[Block.Lava] = false;
|
||||
place[Block.Water] = false; delete[Block.Water] = false;
|
||||
place[Block.StillLava] = false; delete[Block.StillLava] = false;
|
||||
place[Block.StillWater] = false; delete[Block.StillWater] = false;
|
||||
place[Block.Bedrock] = false; delete[Block.Bedrock] = false;
|
||||
CanPlace[Block.Lava] = false; CanDelete[Block.Lava] = false;
|
||||
CanPlace[Block.Water] = false; CanDelete[Block.Water] = false;
|
||||
CanPlace[Block.StillLava] = false; CanDelete[Block.StillLava] = false;
|
||||
CanPlace[Block.StillWater] = false; CanDelete[Block.StillWater] = false;
|
||||
CanPlace[Block.Bedrock] = false; CanDelete[Block.Bedrock] = false;
|
||||
}
|
||||
|
||||
public static void SetCollide(BlockID block, byte collide) {
|
||||
|
|
|
@ -104,14 +104,13 @@ namespace ClassicalSharp.Entities {
|
|||
public void SetUserType(byte value) {
|
||||
bool isOp = value >= 100 && value <= 127;
|
||||
UserType = value;
|
||||
Inventory inv = game.Inventory;
|
||||
inv.CanPlace[Block.Bedrock] = isOp;
|
||||
inv.CanDelete[Block.Bedrock] = isOp;
|
||||
BlockInfo.CanPlace[Block.Bedrock] = isOp;
|
||||
BlockInfo.CanDelete[Block.Bedrock] = isOp;
|
||||
|
||||
inv.CanPlace[Block.Water] = isOp;
|
||||
inv.CanPlace[Block.StillWater] = isOp;
|
||||
inv.CanPlace[Block.Lava] = isOp;
|
||||
inv.CanPlace[Block.StillLava] = isOp;
|
||||
BlockInfo.CanPlace[Block.Water] = isOp;
|
||||
BlockInfo.CanPlace[Block.StillWater] = isOp;
|
||||
BlockInfo.CanPlace[Block.Lava] = isOp;
|
||||
BlockInfo.CanPlace[Block.StillLava] = isOp;
|
||||
CanSeeAllNames = isOp;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace ClassicalSharp {
|
|||
Animations = AddComponent(new Animations());
|
||||
Inventory = AddComponent(new Inventory());
|
||||
|
||||
BlockInfo.SetDefaultPerms(Inventory.CanPlace, Inventory.CanDelete);
|
||||
BlockInfo.SetDefaultPerms();
|
||||
World = new World(this);
|
||||
LocalPlayer = AddComponent(new LocalPlayer(this));
|
||||
Entities[EntityList.SelfID] = LocalPlayer;
|
||||
|
|
|
@ -340,7 +340,7 @@ namespace ClassicalSharp {
|
|||
if (BlockInfo.Collide[block] != CollideType.Liquid) return true;
|
||||
|
||||
return !ModifiableLiquids ? false :
|
||||
Inventory.CanPlace[block] && Inventory.CanDelete[block];
|
||||
BlockInfo.CanPlace[block] && BlockInfo.CanDelete[block];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ using BlockID = System.Byte;
|
|||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Contains the hotbar of blocks, as well as the permissions for placing and deleting all blocks. </summary>
|
||||
/// <summary> Manages the hotbar and inventory of blocks. </summary>
|
||||
public sealed class Inventory : IGameComponent {
|
||||
|
||||
public void Init(Game game) {
|
||||
|
@ -29,8 +29,6 @@ namespace ClassicalSharp {
|
|||
|
||||
public const int BlocksPerRow = 9, Rows = 9;
|
||||
public BlockID[] Hotbar = new BlockID[BlocksPerRow * Rows];
|
||||
public InventoryPermissions CanPlace = new InventoryPermissions();
|
||||
public InventoryPermissions CanDelete = new InventoryPermissions();
|
||||
|
||||
/// <summary> Gets or sets the block at the given index within the current row. </summary>
|
||||
public BlockID this[int index] {
|
||||
|
@ -126,22 +124,4 @@ namespace ClassicalSharp {
|
|||
Map[Block.MossyRocks] = Block.TNT;
|
||||
}
|
||||
}
|
||||
|
||||
public class InventoryPermissions {
|
||||
|
||||
byte[] values = new byte[Block.Count];
|
||||
public bool this[int index] {
|
||||
get { return (values[index] & 1) != 0; }
|
||||
set {
|
||||
if (values[index] >= 0x80) return;
|
||||
values[index] &= 0xFE; // reset perm bit
|
||||
values[index] |= (byte)(value ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetNotOverridable(bool value, int index) {
|
||||
values[index] &= 0xFE; // reset perm bit
|
||||
values[index] |= (byte)(value ? 0x81 : 0x80); // set 'don't override' bit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace ClassicalSharp {
|
|||
if (!game.World.IsValidPos(pos)) return;
|
||||
|
||||
BlockID old = game.World.GetBlock(pos);
|
||||
if (BlockInfo.Draw[old] == DrawType.Gas || !inv.CanDelete[old]) return;
|
||||
if (BlockInfo.Draw[old] == DrawType.Gas || !BlockInfo.CanDelete[old]) return;
|
||||
game.Mode.PickLeft(old);
|
||||
} else if (right) {
|
||||
Vector3I pos = game.SelectedPos.TranslatedPos;
|
||||
|
@ -71,7 +71,7 @@ namespace ClassicalSharp {
|
|||
if (game.AutoRotate)
|
||||
block = AutoRotate.RotateBlock(game, block);
|
||||
|
||||
if (game.CanPick(old) || !inv.CanPlace[block]) return;
|
||||
if (game.CanPick(old) || !BlockInfo.CanPlace[block]) return;
|
||||
if (!PickingHandler.CheckIsFree(game, block)) return;
|
||||
game.Mode.PickRight(old, block);
|
||||
}
|
||||
|
|
|
@ -174,8 +174,8 @@ namespace ClassicalSharp.Map {
|
|||
game.Events.RaiseBlockDefinitionChanged();
|
||||
BlockInfo.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));
|
||||
|
||||
game.Inventory.CanPlace.SetNotOverridable(true, id);
|
||||
game.Inventory.CanDelete.SetNotOverridable(true, id);
|
||||
BlockInfo.CanPlace[id] = true;
|
||||
BlockInfo.CanDelete[id] = true;
|
||||
game.Events.RaiseBlockPermissionsChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace ClassicalSharp.Mode {
|
|||
public void PickMiddle(BlockID old) {
|
||||
Inventory inv = game.Inventory;
|
||||
if (BlockInfo.Draw[old] == DrawType.Gas) return;
|
||||
if (!(inv.CanPlace[old] || inv.CanDelete[old])) return;
|
||||
if (!(BlockInfo.CanPlace[old] || BlockInfo.CanDelete[old])) return;
|
||||
if (!inv.CanChangeSelected()) return;
|
||||
|
||||
// Is the currently selected block an empty slot
|
||||
|
|
|
@ -115,7 +115,6 @@ namespace ClassicalSharp.Network {
|
|||
continue;
|
||||
}
|
||||
|
||||
Console.BufferHeight = short.MaxValue - 10;
|
||||
if (opcode > maxHandledPacket) {
|
||||
ErrorHandler.LogError("NetworkProcessor.Tick", "received invalid opcode: " + opcode);
|
||||
reader.Skip(1);
|
||||
|
|
|
@ -211,12 +211,12 @@ namespace ClassicalSharp.Network.Protocols {
|
|||
if (blockId == 0) {
|
||||
int count = game.UseCPEBlocks ? Block.CpeCount : Block.OriginalCount;
|
||||
for (int i = 1; i < count; i++) {
|
||||
inv.CanPlace.SetNotOverridable(canPlace, i);
|
||||
inv.CanDelete.SetNotOverridable(canDelete, i);
|
||||
BlockInfo.CanPlace[i] = canPlace;
|
||||
BlockInfo.CanDelete[i] = canDelete;
|
||||
}
|
||||
} else {
|
||||
inv.CanPlace.SetNotOverridable(canPlace, blockId);
|
||||
inv.CanDelete.SetNotOverridable(canDelete, blockId);
|
||||
BlockInfo.CanPlace[blockId] = canPlace;
|
||||
BlockInfo.CanDelete[blockId] = canDelete;
|
||||
}
|
||||
game.Events.RaiseBlockPermissionsChanged();
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ namespace ClassicalSharp.Singleplayer {
|
|||
game.UseCPEBlocks = game.UseCPE;
|
||||
int max = game.UseCPEBlocks ? Block.MaxCpeBlock : Block.MaxOriginalBlock;
|
||||
for (int i = 1; i <= max; i++) {
|
||||
game.Inventory.CanPlace[i] = true;
|
||||
game.Inventory.CanDelete[i] = true;
|
||||
BlockInfo.CanPlace[i] = true;
|
||||
BlockInfo.CanDelete[i] = true;
|
||||
}
|
||||
game.AsyncDownloader.DownloadSkin(game.LocalPlayer.SkinIdentifier,
|
||||
game.LocalPlayer.SkinName);
|
||||
|
|
Loading…
Reference in a new issue