If we try to set inventory slot to already used slot, push the old block to the free IDs.

This commit is contained in:
UnknownShadow200 2017-08-16 20:45:08 +10:00
parent e9b6a97987
commit 96c11b3206
2 changed files with 19 additions and 1 deletions

View File

@ -170,5 +170,23 @@ namespace ClassicalSharp {
if (Map[i] == block) Map[i] = Block.Invalid;
}
}
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);
Map[i] = block;
}
void PushToFreeSlots(int i) {
BlockID block = Map[i];
for (int j = block; j < Map.Length; j++) {
if (Map[j] == Block.Invalid) { Map[j] = block; return; }
}
for (int j = 1; j < block; j++) {
if (Map[j] == Block.Invalid) { Map[j] = block; return; }
}
}
}
}

View File

@ -412,7 +412,7 @@ namespace ClassicalSharp.Network.Protocols {
game.Inventory.Remove(block);
if (order != Block.Invalid) {
game.Inventory.Map[order] = block;
game.Inventory.Insert(order, block);
}
}