mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-27 14:34:57 +01:00
SPIGOT-1567: Rework setItems to set slots correctly regardless of array reference.
This commit is contained in:
parent
4831c56cdb
commit
69e196f796
1 changed files with 5 additions and 7 deletions
|
@ -61,17 +61,15 @@ public class CraftInventory implements Inventory {
|
|||
}
|
||||
|
||||
public void setContents(ItemStack[] items) {
|
||||
if (getInventory().getContents().length < items.length) {
|
||||
throw new IllegalArgumentException("Invalid inventory size; expected " + getInventory().getContents().length + " or less");
|
||||
if (getSize() < items.length) {
|
||||
throw new IllegalArgumentException("Invalid inventory size; expected " + getSize() + " or less");
|
||||
}
|
||||
|
||||
net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();
|
||||
|
||||
for (int i = 0; i < mcItems.length; i++) {
|
||||
for (int i = 0; i < getSize(); i++) {
|
||||
if (i >= items.length) {
|
||||
mcItems[i] = null;
|
||||
setItem(i, null);
|
||||
} else {
|
||||
mcItems[i] = CraftItemStack.asNMSCopy(items[i]);
|
||||
setItem(i, items[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue