Optimize Inventory#clear

This commit is contained in:
Felix Cravic 2020-08-01 10:40:43 +02:00
parent d980b3f56c
commit 827526e200

View File

@ -286,6 +286,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
protected void setItemStackInternal(int slot, ItemStack itemStack) {
itemStacks[slot] = itemStack;
this.windowItemsBufferUpdated = false;
}
/**
@ -608,9 +609,11 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
}
public void clear() {
// TODO: optimize by sending whole inventory at once? (will need to change to setItemStackInternal)
// Clear the item array
for (int i = 0; i < getSize(); i++) {
setItemStack(i, ItemStack.getAirItem());
setItemStackInternal(i, ItemStack.getAirItem());
}
// Send the cleared inventory to viewers
update();
}
}