3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 04:50:05 +01:00

Inventory getContents Cleanup

Dieser Commit ist enthalten in:
Lukas Hennig 2017-04-17 18:09:15 +10:00 committet von md_5
Ursprung e17c3d285b
Commit e04a1793ae
4 geänderte Dateien mit 25 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -50,6 +50,18 @@ public class CraftInventory implements Inventory {
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
}
protected ItemStack[] asCraftMirror(List<net.minecraft.server.ItemStack> mcItems) {
int size = mcItems.size();
ItemStack[] items = new ItemStack[size];
for (int i = 0; i < size; i++) {
net.minecraft.server.ItemStack mcItem = mcItems.get(i);
items[i] = (mcItem.isEmpty()) ? null : CraftItemStack.asCraftMirror(mcItem);
}
return items;
}
@Override
public ItemStack[] getStorageContents() {
return getContents();
@ -61,14 +73,9 @@ public class CraftInventory implements Inventory {
}
public ItemStack[] getContents() {
ItemStack[] items = new ItemStack[getSize()];
List<net.minecraft.server.ItemStack> mcItems = getInventory().getContents();
int size = Math.min(items.length, mcItems.size());
for (int i = 0; i < size; i++) {
items[i] = (mcItems.get(i).isEmpty()) ? null : CraftItemStack.asCraftMirror(mcItems.get(i));
}
return items;
return asCraftMirror(mcItems);
}
public void setContents(ItemStack[] items) {

Datei anzeigen

@ -34,10 +34,8 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
@Override
public void setContents(ItemStack[] items) {
int resultLen = getResultInventory().getContents().size();
int len = getMatrixInventory().getContents().size() + resultLen;
if (len > items.length) {
throw new IllegalArgumentException("Invalid inventory size; expected " + len + " or less");
if (getSize() > items.length) {
throw new IllegalArgumentException("Invalid inventory size; expected " + getSize() + " or less");
}
setContents(items[0], Arrays.copyOfRange(items, 1, items.length));
}
@ -88,13 +86,8 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
public ItemStack[] getMatrix() {
List<net.minecraft.server.ItemStack> matrix = getMatrixInventory().getContents();
ItemStack[] items = new ItemStack[matrix.size()];
for (int i = 0; i < matrix.size(); i++) {
items[i] = CraftItemStack.asCraftMirror(matrix.get(i));
}
return items;
return asCraftMirror(matrix);
}
public ItemStack getResult() {
@ -104,13 +97,11 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
}
public void setMatrix(ItemStack[] contents) {
if (getMatrixInventory().getContents().size() > contents.length) {
throw new IllegalArgumentException("Invalid inventory size; expected " + getMatrixInventory().getContents().size() + " or less");
if (getMatrixInventory().getSize() > contents.length) {
throw new IllegalArgumentException("Invalid inventory size; expected " + getMatrixInventory().getSize() + " or less");
}
List<net.minecraft.server.ItemStack> mcItems = getMatrixInventory().getContents();
for (int i = 0; i < mcItems.size(); i++) {
for (int i = 0; i < getMatrixInventory().getSize(); i++) {
if (i < contents.length) {
getMatrixInventory().setItem(i, CraftItemStack.asNMSCopy(contents[i]));
} else {

Datei anzeigen

@ -1,6 +1,5 @@
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.ITileEntityContainer;
import net.minecraft.server.ITileInventory;
import org.bukkit.block.DoubleChest;
import org.bukkit.inventory.DoubleChestInventory;
@ -44,11 +43,11 @@ public class CraftInventoryDoubleChest extends CraftInventory implements DoubleC
@Override
public void setContents(ItemStack[] items) {
if (getInventory().getContents().size() < items.length) {
throw new IllegalArgumentException("Invalid inventory size; expected " + getInventory().getContents().size() + " or less");
if (getInventory().getSize() < items.length) {
throw new IllegalArgumentException("Invalid inventory size; expected " + getInventory().getSize() + " or less");
}
ItemStack[] leftItems = new ItemStack[left.getSize()], rightItems = new ItemStack[right.getSize()];
System.arraycopy(items, 0, leftItems, 0, Math.min(left.getSize(),items.length));
System.arraycopy(items, 0, leftItems, 0, Math.min(left.getSize(), items.length));
left.setContents(leftItems);
if (items.length >= left.getSize()) {
System.arraycopy(items, left.getSize(), rightItems, 0, Math.min(right.getSize(), items.length - left.getSize()));

Datei anzeigen

@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Preconditions;
import java.util.Arrays;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.PacketPlayOutHeldItemSlot;
import net.minecraft.server.PacketPlayOutSetSlot;
@ -25,10 +24,9 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
@Override
public ItemStack[] getStorageContents() {
return Arrays.copyOfRange(getContents(), 0, getInventory().items.size());
return asCraftMirror(getInventory().items);
}
@Override
public ItemStack getItemInMainHand() {
return CraftItemStack.asCraftMirror(getInventory().getItemInHand());
@ -148,8 +146,7 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
}
public ItemStack[] getArmorContents() {
int start = getInventory().items.size();
return Arrays.copyOfRange(getContents(), start, start + getInventory().armor.size());
return asCraftMirror(getInventory().armor);
}
private void setSlots(ItemStack[] items, int baseSlot, int length) {
@ -179,8 +176,7 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
@Override
public ItemStack[] getExtraContents() {
int start = getInventory().items.size() + getInventory().armor.size();
return Arrays.copyOfRange(getContents(), start, start + getInventory().extraSlots.size());
return asCraftMirror(getInventory().extraSlots);
}
@Override