Permalink
Browse files

fix block ID 255 not showing in inventory

  • Loading branch information...
UnknownShadow200 committed Dec 7, 2017
1 parent f5e508c commit 8bdecb71fc39c7895089a668eef67b9c7c40f7dc
Showing with 15 additions and 15 deletions.
  1. +1 −1 ClassicalSharp/2D/Widgets/TableWidget.cs
  2. +7 −7 ClassicalSharp/Game/Inventory.cs
  3. +7 −7 src/Client/Inventory.c
@@ -232,7 +232,7 @@ public sealed class TableWidget : Widget {
}
bool Show(BlockID block) {
if (block == Block.Invalid) return false;
if (block == Block.Air) return false;
if (block < Block.CpeCount) {
int count = game.UseCPEBlocks ? Block.CpeCount : Block.OriginalCount;
@@ -100,16 +100,16 @@ public sealed class Inventory : IGameComponent {
for (int i = 0; i < Map.Length; i++) Map[i] = (BlockID)i;
for (int i = 0; i < Map.Length; i++) {
BlockID mapping = DefaultMapping(i);
if (game.PureClassic && IsHackBlock(mapping)) mapping = Block.Invalid;
if (game.PureClassic && IsHackBlock(mapping)) mapping = Block.Air;
if (mapping != i) Map[i] = mapping;
}
}
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.Air;
#else
if (i >= Block.CpeCount || i == Block.Air) return Block.Invalid;
if (i >= Block.CpeCount || i == Block.Air) return Block.Air;
#endif
if (!game.ClassicMode) return (BlockID)i;
@@ -178,14 +178,14 @@ public sealed class Inventory : IGameComponent {
public void Remove(BlockID block) {
for (int i = 0; i < Map.Length; i++) {
if (Map[i] == block) Map[i] = Block.Invalid;
if (Map[i] == block) Map[i] = Block.Air;
}
}
public void Insert(int i, BlockID block) {
if (Map[i] == block) return;
// Need to push the old block to a different slot if different block
if (Map[i] != Block.Invalid) PushToFreeSlots(i);
if (Map[i] != Block.Air) PushToFreeSlots(i);
Map[i] = block;
}
@@ -199,10 +199,10 @@ public sealed class Inventory : IGameComponent {
}
for (int j = block; j < Map.Length; j++) {
if (Map[j] == Block.Invalid) { Map[j] = block; return; }
if (Map[j] == Block.Air) { Map[j] = block; return; }
}
for (int j = 1; j < block; j++) {
if (Map[j] == Block.Invalid) { Map[j] = block; return; }
if (Map[j] == Block.Air) { Map[j] = block; return; }
}
}
}
View
@@ -47,9 +47,9 @@ bool Inventory_IsHackBlock(BlockID b) {
BlockID Inventory_DefaultMapping(Int32 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_AIR;
#else
if (i >= BLOCK_CPE_COUNT || i == BLOCK_AIR) return BLOCK_INVALID;
if (i >= BLOCK_CPE_COUNT || i == BLOCK_AIR) return BLOCK_AIR;
#endif
if (!Game_ClassicMode) return (BlockID)i;
@@ -101,7 +101,7 @@ void Inventory_SetDefaultMapping(void) {
for (i = 0; i < Array_NumElements(Inventory_Map); i++) {
BlockID mapping = Inventory_DefaultMapping(i);
if (Game_PureClassic && Inventory_IsHackBlock(mapping)) {
mapping = BLOCK_INVALID;
mapping = BLOCK_AIR;
}
if (mapping != i) Inventory_Map[i] = mapping;
}
@@ -133,7 +133,7 @@ void Inventory_Remove(BlockID block) {
Int32 i;
for (i = 0; i < Array_NumElements(Inventory_Map); i++) {
if (Inventory_Map[i] != block) continue;
Inventory_Map[i] = BLOCK_INVALID;
Inventory_Map[i] = BLOCK_AIR;
}
}
@@ -147,12 +147,12 @@ void Inventory_PushToFreeSlots(Int32 i) {
}
for (j = block; j < Array_NumElements(Inventory_Map); j++) {
if (Inventory_Map[j] == BLOCK_INVALID) {
if (Inventory_Map[j] == BLOCK_AIR) {
Inventory_Map[j] = block; return;
}
}
for (j = 1; j < block; j++) {
if (Inventory_Map[j] == BLOCK_INVALID) {
if (Inventory_Map[j] == BLOCK_AIR) {
Inventory_Map[j] = block; return;
}
}
@@ -161,7 +161,7 @@ void Inventory_PushToFreeSlots(Int32 i) {
void Inventory_Insert(Int32 i, BlockID block) {
if (Inventory_Map[i] == block) return;
/* Need to push the old block to a different slot if different block. */
if (Inventory_Map[i] != BLOCK_INVALID) Inventory_PushToFreeSlots(i);
if (Inventory_Map[i] != BLOCK_AIR) Inventory_PushToFreeSlots(i);
Inventory_Map[i] = block;
}

0 comments on commit 8bdecb7

Please sign in to comment.