Search in sources :

Example 1 with InventoryBaseImpl

use of com.bergerkiller.bukkit.common.inventory.InventoryBaseImpl 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));
}
Also used : InventoryBaseImpl(com.bergerkiller.bukkit.common.inventory.InventoryBaseImpl) IInventoryHandle(com.bergerkiller.generated.net.minecraft.server.IInventoryHandle) ItemStackHandle(com.bergerkiller.generated.net.minecraft.server.ItemStackHandle) ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test)

Example 2 with InventoryBaseImpl

use of com.bergerkiller.bukkit.common.inventory.InventoryBaseImpl in project BKCommonLib by bergerhealer.

the class RecipeTest method testCrafting.

@Test
public void testCrafting() {
    Inventory testInventory = new InventoryBaseImpl(64);
    CraftRecipe recipe = RecipeUtil.getCraftingRequirements(Material.DIODE, 0)[0];
    // Add enough resources to craft 2 diodes, and a little more but not enough for a third
    // Also add some garbage items
    testInventory.addItem(new ItemStack(Material.REDSTONE, 64));
    testInventory.addItem(new ItemStack(Material.COBBLESTONE, 64));
    testInventory.addItem(new ItemStack(Material.STONE, 8));
    testInventory.addItem(new ItemStack(Material.REDSTONE_TORCH_ON, 5));
    testInventory.addItem(new ItemStack(Material.WOOD, 12));
    assertTrue(recipe.craft(testInventory));
    assertTrue(recipe.craft(testInventory));
    assertFalse(recipe.craft(testInventory));
    // Verify the items in the inventory
    assertEquals(testInventory.getItem(0), new ItemStack(Material.REDSTONE, 62));
    assertEquals(testInventory.getItem(1), new ItemStack(Material.COBBLESTONE, 64));
    assertEquals(testInventory.getItem(2), new ItemStack(Material.STONE, 2));
    assertEquals(testInventory.getItem(3), new ItemStack(Material.REDSTONE_TORCH_ON, 1));
    assertEquals(testInventory.getItem(4), new ItemStack(Material.WOOD, 12));
    assertEquals(testInventory.getItem(5), new ItemStack(Material.DIODE, 2));
}
Also used : InventoryBaseImpl(com.bergerkiller.bukkit.common.inventory.InventoryBaseImpl) ItemStack(org.bukkit.inventory.ItemStack) CraftRecipe(com.bergerkiller.bukkit.common.inventory.CraftRecipe) Inventory(org.bukkit.inventory.Inventory) Test(org.junit.Test)

Aggregations

InventoryBaseImpl (com.bergerkiller.bukkit.common.inventory.InventoryBaseImpl)2 ItemStack (org.bukkit.inventory.ItemStack)2 Test (org.junit.Test)2 CraftRecipe (com.bergerkiller.bukkit.common.inventory.CraftRecipe)1 IInventoryHandle (com.bergerkiller.generated.net.minecraft.server.IInventoryHandle)1 ItemStackHandle (com.bergerkiller.generated.net.minecraft.server.ItemStackHandle)1 Inventory (org.bukkit.inventory.Inventory)1