Archiviert
13
0

Updated CraftInventory to make use of the proper generics in the Inventory interface.

Updated loads of return values to now return actual Craft* objects.
Added a shitton of constructors to CraftItemStack so you can now finally properly make your ItemStacks.
Dieser Commit ist enthalten in:
Erik Broes 2011-01-17 01:55:53 +01:00
Ursprung 0c492912de
Commit 80a59397cb
3 geänderte Dateien mit 56 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -84,12 +84,12 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
return false;
}
public HashMap<Integer, ItemStack> all(int materialId) {
HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>();
public HashMap<Integer, CraftItemStack> all(int materialId) {
HashMap<Integer, CraftItemStack> slots = new HashMap<Integer, CraftItemStack>();
ItemStack[] inventory = getContents();
CraftItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) {
ItemStack item = inventory[i];
CraftItemStack item = inventory[i];
if (item.getTypeId() == materialId) {
slots.put( i, item );
}
@ -97,24 +97,24 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
return slots;
}
public HashMap<Integer, ItemStack> all(Material material) {
public HashMap<Integer, CraftItemStack> all(Material material) {
return all(material.getId());
}
public HashMap<Integer, ItemStack> all(ItemStack item) {
HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>();
public HashMap<Integer, CraftItemStack> all(ItemStack item) {
HashMap<Integer, CraftItemStack> slots = new HashMap<Integer, CraftItemStack>();
ItemStack[] inventory = getContents();
CraftItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) {
if (item.equals(inventory[i])) {
slots.put( i, item );
slots.put( i, inventory[i] );
}
}
return slots;
}
public int first(int materialId) {
ItemStack[] inventory = getContents();
CraftItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) {
if (inventory[i].getTypeId() == materialId) {
return i;
@ -128,7 +128,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
}
public int first(ItemStack item) {
ItemStack[] inventory = getContents();
CraftItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) {
if (item.equals(inventory[i])) {
return i;
@ -142,9 +142,9 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
}
public int firstPartial(int materialId) {
ItemStack[] inventory = getContents();
CraftItemStack[] inventory = getContents();
for (int i = 0; i < inventory.length; i++) {
ItemStack item = inventory[i];
CraftItemStack item = inventory[i];
if (item != null && item.getTypeId() == materialId && item.getAmount() < item.getMaxStackSize()) {
return i;
}
@ -187,7 +187,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
} else {
// More than a single stack!
if (item.getAmount() > getMaxItemStack()) {
setItem( firstFree, new ItemStack(item.getTypeId(), getMaxItemStack()));
setItem( firstFree, new CraftItemStack(item.getTypeId(), getMaxItemStack()));
item.setAmount(item.getAmount() - getMaxItemStack());
} else {
// Just store it
@ -197,7 +197,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
}
} else {
// So, apparently it might only partially fit, well lets do just that
ItemStack partialItem = getItem(firstPartial);
CraftItemStack partialItem = getItem(firstPartial);
int amount = item.getAmount();
int partialAmount = partialItem.getAmount();

Datei anzeigen

@ -62,9 +62,9 @@ public class CraftInventoryPlayer extends CraftInventory implements PlayerInvent
setItem( getSize() + 3, boots );
}
public ItemStack[] getArmorContents() {
public CraftItemStack[] getArmorContents() {
net.minecraft.server.ItemStack[] mcItems = getInventory().getArmorContents();
ItemStack[] ret = new ItemStack[mcItems.length];
CraftItemStack[] ret = new CraftItemStack[mcItems.length];
for (int i = 0; i < mcItems.length; i++ ) {
ret[i] = new CraftItemStack(mcItems[i]);

Datei anzeigen

@ -7,11 +7,47 @@ public class CraftItemStack extends ItemStack {
protected net.minecraft.server.ItemStack item;
public CraftItemStack(net.minecraft.server.ItemStack item) {
super(item != null ? item.c : 0, item != null ? item.a : 0,
(byte)(item != null ? item.d : 0));
super(
item != null ? item.c : 0,
item != null ? item.a : 0,
(byte)(item != null ? item.d : 0)
);
this.item = item;
}
/* 'Overwritten' constructors from ItemStack, yay for Java sucking */
public CraftItemStack(final int type) {
this(type, 0);
}
public CraftItemStack(final Material type) {
this(type, 0);
}
public CraftItemStack(final int type, final int amount) {
this(type, amount, (byte) 0);
}
public CraftItemStack(final Material type, final int amount) {
this(type.getId(), amount);
}
public CraftItemStack(final int type, final int amount, final byte damage) {
this(type, amount, damage, null);
}
public CraftItemStack(final Material type, final int amount, final byte damage) {
this(type.getId(), amount, damage);
}
public CraftItemStack(final Material type, final int amount, final byte damage, final Byte data) {
this(type.getId(), amount, damage, data);
}
public CraftItemStack(int type, int amount, byte damage, Byte data) {
this(new net.minecraft.server.ItemStack(type, amount, data != null ? data : damage));
}
/*
* Unsure if we have to sync before each of these calls the values in 'item'
* are all public.