Search in sources :

Example 1 with CraftRecipe

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

the class RecipeTest method assertRequirements.

public void assertRequirements(Material outputType, ItemStack... inputs) {
    CraftRecipe[] recipes = RecipeUtil.getCraftingRequirements(outputType, 0);
    assertEquals(1, recipes.length);
    assertEquals(inputs.length, recipes[0].getInputSlots().length);
    for (int i = 0; i < inputs.length; i++) {
        ItemStack item2 = recipes[0].getInputSlots()[i].getDefaultChoice();
        if (item2.getType() != inputs[i].getType() || item2.getAmount() != inputs[i].getAmount()) {
            fail("Item at [" + i + "] expected " + inputs[i] + ", but was " + item2);
        }
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) CraftRecipe(com.bergerkiller.bukkit.common.inventory.CraftRecipe)

Example 2 with CraftRecipe

use of com.bergerkiller.bukkit.common.inventory.CraftRecipe 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

CraftRecipe (com.bergerkiller.bukkit.common.inventory.CraftRecipe)2 ItemStack (org.bukkit.inventory.ItemStack)2 InventoryBaseImpl (com.bergerkiller.bukkit.common.inventory.InventoryBaseImpl)1 Inventory (org.bukkit.inventory.Inventory)1 Test (org.junit.Test)1