mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
If we try to set inventory slot to already used slot, push the old block to the free IDs.
This commit is contained in:
parent
e9b6a97987
commit
96c11b3206
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user