Search in sources :

Example 1 with ICraftingPlan

use of forestry.core.items.ICraftingPlan in project ForestryMC by ForestryMC.

the class TileFabricator method craftResult.

private void craftResult() {
    RecipePair<IFabricatorRecipe> myRecipePair = getRecipe();
    ItemStack craftResult = getResult(myRecipePair);
    IFabricatorRecipe myRecipe = myRecipePair.getRecipe();
    if (myRecipe != null && !craftResult.isEmpty() && getStackInSlot(InventoryFabricator.SLOT_RESULT).isEmpty()) {
        FluidStack liquid = myRecipe.getLiquid();
        // Remove resources
        NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
        if (removeFromInventory(crafting, myRecipePair, false)) {
            FluidStack drained = moltenTank.drainInternal(liquid, false);
            if (drained != null && drained.isFluidStackIdentical(liquid)) {
                removeFromInventory(crafting, myRecipePair, true);
                moltenTank.drain(liquid.amount, true);
                // Damage plan
                if (!getStackInSlot(InventoryFabricator.SLOT_PLAN).isEmpty()) {
                    Item planItem = getStackInSlot(InventoryFabricator.SLOT_PLAN).getItem();
                    if (planItem instanceof ICraftingPlan) {
                        ItemStack planUsed = ((ICraftingPlan) planItem).planUsed(getStackInSlot(InventoryFabricator.SLOT_PLAN), craftResult);
                        setInventorySlotContents(InventoryFabricator.SLOT_PLAN, planUsed);
                    }
                }
                setInventorySlotContents(InventoryFabricator.SLOT_RESULT, craftResult);
            }
        }
    }
}
Also used : Item(net.minecraft.item.Item) ICraftingPlan(forestry.core.items.ICraftingPlan) FluidStack(net.minecraftforge.fluids.FluidStack) IFabricatorRecipe(forestry.api.recipes.IFabricatorRecipe) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IFabricatorRecipe (forestry.api.recipes.IFabricatorRecipe)1 ICraftingPlan (forestry.core.items.ICraftingPlan)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1