geforkt von Mirrors/Paper
Inventory getContents Cleanup
Dieser Commit ist enthalten in:
Ursprung
e17c3d285b
Commit
e04a1793ae
@ -50,6 +50,18 @@ public class CraftInventory implements Inventory {
|
|||||||
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
|
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
|
@Override
|
||||||
public ItemStack[] getStorageContents() {
|
public ItemStack[] getStorageContents() {
|
||||||
return getContents();
|
return getContents();
|
||||||
@ -61,14 +73,9 @@ public class CraftInventory implements Inventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
ItemStack[] items = new ItemStack[getSize()];
|
|
||||||
List<net.minecraft.server.ItemStack> mcItems = getInventory().getContents();
|
List<net.minecraft.server.ItemStack> mcItems = getInventory().getContents();
|
||||||
|
|
||||||
int size = Math.min(items.length, mcItems.size());
|
return asCraftMirror(mcItems);
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
items[i] = (mcItems.get(i).isEmpty()) ? null : CraftItemStack.asCraftMirror(mcItems.get(i));
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContents(ItemStack[] items) {
|
public void setContents(ItemStack[] items) {
|
||||||
|
@ -34,10 +34,8 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContents(ItemStack[] items) {
|
public void setContents(ItemStack[] items) {
|
||||||
int resultLen = getResultInventory().getContents().size();
|
if (getSize() > items.length) {
|
||||||
int len = getMatrixInventory().getContents().size() + resultLen;
|
throw new IllegalArgumentException("Invalid inventory size; expected " + getSize() + " or less");
|
||||||
if (len > items.length) {
|
|
||||||
throw new IllegalArgumentException("Invalid inventory size; expected " + len + " or less");
|
|
||||||
}
|
}
|
||||||
setContents(items[0], Arrays.copyOfRange(items, 1, items.length));
|
setContents(items[0], Arrays.copyOfRange(items, 1, items.length));
|
||||||
}
|
}
|
||||||
@ -88,13 +86,8 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
|
|||||||
|
|
||||||
public ItemStack[] getMatrix() {
|
public ItemStack[] getMatrix() {
|
||||||
List<net.minecraft.server.ItemStack> matrix = getMatrixInventory().getContents();
|
List<net.minecraft.server.ItemStack> matrix = getMatrixInventory().getContents();
|
||||||
ItemStack[] items = new ItemStack[matrix.size()];
|
|
||||||
|
|
||||||
for (int i = 0; i < matrix.size(); i++) {
|
return asCraftMirror(matrix);
|
||||||
items[i] = CraftItemStack.asCraftMirror(matrix.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getResult() {
|
public ItemStack getResult() {
|
||||||
@ -104,13 +97,11 @@ public class CraftInventoryCrafting extends CraftInventory implements CraftingIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setMatrix(ItemStack[] contents) {
|
public void setMatrix(ItemStack[] contents) {
|
||||||
if (getMatrixInventory().getContents().size() > contents.length) {
|
if (getMatrixInventory().getSize() > contents.length) {
|
||||||
throw new IllegalArgumentException("Invalid inventory size; expected " + getMatrixInventory().getContents().size() + " or less");
|
throw new IllegalArgumentException("Invalid inventory size; expected " + getMatrixInventory().getSize() + " or less");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<net.minecraft.server.ItemStack> mcItems = getMatrixInventory().getContents();
|
for (int i = 0; i < getMatrixInventory().getSize(); i++) {
|
||||||
|
|
||||||
for (int i = 0; i < mcItems.size(); i++) {
|
|
||||||
if (i < contents.length) {
|
if (i < contents.length) {
|
||||||
getMatrixInventory().setItem(i, CraftItemStack.asNMSCopy(contents[i]));
|
getMatrixInventory().setItem(i, CraftItemStack.asNMSCopy(contents[i]));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package org.bukkit.craftbukkit.inventory;
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
import net.minecraft.server.ITileEntityContainer;
|
|
||||||
import net.minecraft.server.ITileInventory;
|
import net.minecraft.server.ITileInventory;
|
||||||
import org.bukkit.block.DoubleChest;
|
import org.bukkit.block.DoubleChest;
|
||||||
import org.bukkit.inventory.DoubleChestInventory;
|
import org.bukkit.inventory.DoubleChestInventory;
|
||||||
@ -44,8 +43,8 @@ public class CraftInventoryDoubleChest extends CraftInventory implements DoubleC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContents(ItemStack[] items) {
|
public void setContents(ItemStack[] items) {
|
||||||
if (getInventory().getContents().size() < items.length) {
|
if (getInventory().getSize() < items.length) {
|
||||||
throw new IllegalArgumentException("Invalid inventory size; expected " + getInventory().getContents().size() + " or less");
|
throw new IllegalArgumentException("Invalid inventory size; expected " + getInventory().getSize() + " or less");
|
||||||
}
|
}
|
||||||
ItemStack[] leftItems = new ItemStack[left.getSize()], rightItems = new ItemStack[right.getSize()];
|
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));
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.bukkit.craftbukkit.inventory;
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import java.util.Arrays;
|
|
||||||
import net.minecraft.server.EntityPlayer;
|
import net.minecraft.server.EntityPlayer;
|
||||||
import net.minecraft.server.PacketPlayOutHeldItemSlot;
|
import net.minecraft.server.PacketPlayOutHeldItemSlot;
|
||||||
import net.minecraft.server.PacketPlayOutSetSlot;
|
import net.minecraft.server.PacketPlayOutSetSlot;
|
||||||
@ -25,10 +24,9 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack[] getStorageContents() {
|
public ItemStack[] getStorageContents() {
|
||||||
return Arrays.copyOfRange(getContents(), 0, getInventory().items.size());
|
return asCraftMirror(getInventory().items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemInMainHand() {
|
public ItemStack getItemInMainHand() {
|
||||||
return CraftItemStack.asCraftMirror(getInventory().getItemInHand());
|
return CraftItemStack.asCraftMirror(getInventory().getItemInHand());
|
||||||
@ -148,8 +146,7 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getArmorContents() {
|
public ItemStack[] getArmorContents() {
|
||||||
int start = getInventory().items.size();
|
return asCraftMirror(getInventory().armor);
|
||||||
return Arrays.copyOfRange(getContents(), start, start + getInventory().armor.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSlots(ItemStack[] items, int baseSlot, int length) {
|
private void setSlots(ItemStack[] items, int baseSlot, int length) {
|
||||||
@ -179,8 +176,7 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack[] getExtraContents() {
|
public ItemStack[] getExtraContents() {
|
||||||
int start = getInventory().items.size() + getInventory().armor.size();
|
return asCraftMirror(getInventory().extraSlots);
|
||||||
return Arrays.copyOfRange(getContents(), start, start + getInventory().extraSlots.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren