mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Added CraftInventory.setContents(); made CraftInventory.setItem(), CraftInventory.getItem(), and CraftItemStack() damage-aware.
By: sk89q <the.sk89q@gmail.com>
This commit is contained in:
parent
6ebeca35fe
commit
dbc9e0eb55
2 changed files with 23 additions and 2 deletions
|
@ -41,8 +41,28 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setContents(ItemStack[] items) {
|
||||||
|
if (getInventory().getContents().length != items.length) {
|
||||||
|
throw new IllegalArgumentException("Invalid inventory size; expected "
|
||||||
|
+ getInventory().getContents().length);
|
||||||
|
}
|
||||||
|
|
||||||
|
net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();
|
||||||
|
|
||||||
|
for (int i = 0; i < items.length; i++ ) {
|
||||||
|
ItemStack item = items[i];
|
||||||
|
if (item == null) {
|
||||||
|
mcItems[i] = null;
|
||||||
|
} else {
|
||||||
|
mcItems[i] = new net.minecraft.server.ItemStack(
|
||||||
|
item.getTypeId(), item.getAmount(), item.getDamage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setItem(int index, ItemStack item) {
|
public void setItem(int index, ItemStack item) {
|
||||||
getInventory().a( index, new net.minecraft.server.ItemStack( item.getTypeId(), item.getAmount(), 0));
|
getInventory().a(index, new net.minecraft.server.ItemStack(
|
||||||
|
item.getTypeId(), item.getAmount(), item.getDamage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(int materialId) {
|
public boolean contains(int materialId) {
|
||||||
|
|
|
@ -7,7 +7,8 @@ public class CraftItemStack extends ItemStack {
|
||||||
protected net.minecraft.server.ItemStack item;
|
protected net.minecraft.server.ItemStack item;
|
||||||
|
|
||||||
public CraftItemStack(net.minecraft.server.ItemStack item) {
|
public CraftItemStack(net.minecraft.server.ItemStack item) {
|
||||||
super(item != null ? item.c : 0, item != null ? item.a : 0);
|
super(item != null ? item.c : 0, item != null ? item.a : 0,
|
||||||
|
(byte)(item != null ? item.d : 0));
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue