Search in sources :

Example 1 with InventoryProjectTableCrafting

use of com.bluepowermod.container.inventory.InventoryProjectTableCrafting in project BluePower by Qmunity.

the class TileAutoProjectTable method removeItem.

@Override
public ItemStack removeItem(int slot, int amount) {
    if (slot == OUTPUT_SLOT) {
        InventoryProjectTableCrafting craftingInv = new InventoryProjectTableCrafting(null, this, 3, 3);
        ItemStack itemstack = ItemStack.EMPTY;
        Optional<ICraftingRecipe> optional = level.getServer().getRecipeManager().getRecipeFor(IRecipeType.CRAFTING, craftingInv, level);
        if (optional.isPresent()) {
            ICraftingRecipe icraftingrecipe = optional.get();
            itemstack = icraftingrecipe.assemble(craftingInv);
        }
        for (int i = 0; i < 9; i++) {
            ItemStack slotStack = craftingGrid.get(i);
            if (slotStack.getCount() == 1) {
                // Get items from the Inventory to Craft
                for (int ptSlot = 0; ptSlot < 19; ++ptSlot) {
                    if (ptSlot == 18) {
                        // No available items so end here to keep template
                        return ItemStack.EMPTY;
                    }
                    ItemStack ptStack = getItem(ptSlot);
                    if (ptStack.getItem() == slotStack.getItem() && ptStack.getTag() == slotStack.getTag()) {
                        slotStack.setCount(2);
                        craftingGrid.set(i, slotStack);
                        removeItem(ptSlot, 1);
                        break;
                    }
                }
            }
        }
        for (int i = 0; i < 9; i++) {
            ItemStack currentItem = craftingGrid.get(i);
            currentItem.setCount(currentItem.getCount() - 1);
            craftingGrid.set(i, currentItem);
        }
        return itemstack;
    } else {
        return super.removeItem(slot, amount);
    }
}
Also used : ICraftingRecipe(net.minecraft.item.crafting.ICraftingRecipe) InventoryProjectTableCrafting(com.bluepowermod.container.inventory.InventoryProjectTableCrafting) ItemStack(net.minecraft.item.ItemStack)

Example 2 with InventoryProjectTableCrafting

use of com.bluepowermod.container.inventory.InventoryProjectTableCrafting in project BluePower by Qmunity.

the class TileAutoProjectTable method getItem.

@Override
public ItemStack getItem(int i) {
    if (i == OUTPUT_SLOT) {
        InventoryProjectTableCrafting craftingInv = new InventoryProjectTableCrafting(null, this, 3, 3);
        ItemStack itemstack = ItemStack.EMPTY;
        Optional<ICraftingRecipe> optional = level.getServer().getRecipeManager().getRecipeFor(IRecipeType.CRAFTING, craftingInv, level);
        if (optional.isPresent()) {
            ICraftingRecipe icraftingrecipe = optional.get();
            itemstack = icraftingrecipe.assemble(craftingInv);
        }
        return itemstack;
    } else {
        return super.getItem(i);
    }
}
Also used : ICraftingRecipe(net.minecraft.item.crafting.ICraftingRecipe) InventoryProjectTableCrafting(com.bluepowermod.container.inventory.InventoryProjectTableCrafting) ItemStack(net.minecraft.item.ItemStack)

Aggregations

InventoryProjectTableCrafting (com.bluepowermod.container.inventory.InventoryProjectTableCrafting)2 ItemStack (net.minecraft.item.ItemStack)2 ICraftingRecipe (net.minecraft.item.crafting.ICraftingRecipe)2