use of com.bergerkiller.generated.net.minecraft.server.ItemStackHandle in project BKCommonLib by bergerhealer.
the class IInventoryProxyHook method splitStack.
/* Questionable implementations taken over from EntityMinecartContainer */
@HookMethod("public ItemStack splitStack(int i, int j)")
public Object splitStack(int i, int j) {
if ((i < 0) || (i >= inventory.getSize()) || (j <= 0)) {
return ItemStackHandle.EMPTY_ITEM.getRaw();
}
org.bukkit.inventory.ItemStack item = this.inventory.getItem(i);
if (ItemUtil.isEmpty(item)) {
return ItemStackHandle.EMPTY_ITEM.getRaw();
}
ItemStackHandle nmsItem = ItemStackHandle.fromBukkit(item);
if (nmsItem == null) {
return ItemStackHandle.EMPTY_ITEM.getRaw();
}
return ItemStackHandle.getRaw(nmsItem.cloneAndSubtract(j));
}
use of com.bergerkiller.generated.net.minecraft.server.ItemStackHandle in project BKCommonLib by bergerhealer.
the class NMSItemStack method newInstance.
public static Object newInstance(Material type, int data, int amount) {
// Why is Bukkit unable to create proper constructors? Really? -,-
ItemStackHandle instance;
if (ItemStackHandle.T.constr_type_amount_durability_convert.isAvailable()) {
instance = ItemStackHandle.T.constr_type_amount_durability_convert.newInstance(Material.STONE, 1, 0, false);
} else {
instance = ItemStackHandle.createNew(Material.STONE, 1, 0);
}
instance.setTypeField(type);
instance.setDurabilityField(data);
instance.setAmountField(amount);
return instance.getRaw();
}
use of com.bergerkiller.generated.net.minecraft.server.ItemStackHandle in project BKCommonLib by bergerhealer.
the class InventoryTest method testBaseInventory.
@Test
public void testBaseInventory() {
InventoryBaseImpl inventory = new InventoryBaseImpl(9 * 3);
assertEquals(9 * 3, inventory.getSize());
for (int i = 0; i < inventory.getSize(); i++) {
assertNull(inventory.getItem(i));
}
// Verify that the IInventory handle returns non-null items (uses EMPTY constant)
IInventoryHandle handle = IInventoryHandle.createHandle(HandleConversion.toIInventoryHandle(inventory));
assertEquals(9 * 3, handle.getSize());
for (int i = 0; i < handle.getSize(); i++) {
assertTrue(ItemStackHandle.EMPTY_ITEM.equals(handle.getItem(i)));
}
List<ItemStackHandle> handleContents = handle.getContents();
assertEquals(9 * 3, handleContents.size());
for (int i = 0; i < handleContents.size(); i++) {
assertTrue(ItemStackHandle.EMPTY_ITEM.equals(handle.getItem(i)));
}
ItemStack testItem1 = new ItemStack(Material.WOOD, 1);
inventory.setItem(2, testItem1);
assertItemEquals(testItem1, inventory.getItem(2));
ItemStack testItem2 = new ItemStack(Material.STONE, 16);
int cnt = 0;
for (int n = 0; n < 4; n++) {
cnt += 16;
inventory.addItem(testItem2);
assertItemEquals(new ItemStack(Material.STONE, cnt), inventory.getItem(0));
}
inventory.addItem(testItem2);
assertItemEquals(new ItemStack(Material.STONE, 64), inventory.getItem(0));
assertItemEquals(new ItemStack(Material.STONE, 16), inventory.getItem(1));
}
Aggregations