Search in sources :

Example 1 with IFabricatorRecipe

use of forestry.api.recipes.IFabricatorRecipe in project ForestryMC by ForestryMC.

the class TileFabricator method hasWork.

@Override
public boolean hasWork() {
    boolean hasRecipe = true;
    boolean hasLiquidResources = true;
    boolean hasResources = true;
    ItemStack plan = getStackInSlot(InventoryFabricator.SLOT_PLAN);
    RecipePair<IFabricatorRecipe> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
    if (!recipePair.isEmpty()) {
        IFabricatorRecipe recipe = recipePair.getRecipe();
        NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
        hasResources = removeFromInventory(crafting, recipePair, false);
        FluidStack toDrain = recipe.getLiquid();
        FluidStack drained = moltenTank.drainInternal(toDrain, false);
        hasLiquidResources = drained != null && drained.isFluidStackIdentical(toDrain);
    } else {
        hasRecipe = false;
    }
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
    errorLogic.setCondition(!hasLiquidResources, EnumErrorCode.NO_RESOURCE_LIQUID);
    errorLogic.setCondition(!hasResources, EnumErrorCode.NO_RESOURCE_INVENTORY);
    return hasRecipe;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) IFabricatorRecipe(forestry.api.recipes.IFabricatorRecipe) IErrorLogic(forestry.api.core.IErrorLogic)

Example 2 with IFabricatorRecipe

use of forestry.api.recipes.IFabricatorRecipe in project ForestryMC by ForestryMC.

the class FabricatorRecipeCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, FabricatorRecipeWrapper recipeWrapper, IIngredients ingredients) {
    IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
    IGuiFluidStackGroup guiFluidStacks = recipeLayout.getFluidStacks();
    guiItemStacks.init(planSlot, true, 118, 0);
    guiItemStacks.init(smeltingInputSlot, true, 5, 4);
    guiItemStacks.init(craftOutputSlot, false, 118, 36);
    for (int y = 0; y < 3; ++y) {
        for (int x = 0; x < 3; ++x) {
            int index = craftInputSlot + x + y * 3;
            guiItemStacks.init(index, true, 46 + x * 18, y * 18);
        }
    }
    guiFluidStacks.init(inputTank, true, 6, 32, 16, 16, 2000, false, null);
    IFabricatorRecipe recipe = recipeWrapper.getRecipe();
    ItemStack plan = recipe.getPlan();
    if (!plan.isEmpty()) {
        guiItemStacks.set(planSlot, plan);
    }
    List<ItemStack> smeltingInput = new ArrayList<>();
    Fluid recipeFluid = recipe.getLiquid().getFluid();
    for (IFabricatorSmeltingRecipe s : getSmeltingInputs().get(recipeFluid)) {
        smeltingInput.add(s.getResource());
    }
    if (!smeltingInput.isEmpty()) {
        guiItemStacks.set(smeltingInputSlot, smeltingInput);
    }
    List<List<ItemStack>> itemOutputs = ingredients.getOutputs(ItemStack.class);
    guiItemStacks.set(craftOutputSlot, itemOutputs.get(0));
    List<List<ItemStack>> itemStackInputs = ingredients.getInputs(ItemStack.class);
    craftingGridHelper.setInputs(guiItemStacks, itemStackInputs, recipe.getWidth(), recipe.getHeight());
    List<List<FluidStack>> fluidInputs = ingredients.getInputs(FluidStack.class);
    if (!fluidInputs.isEmpty()) {
        guiFluidStacks.set(inputTank, fluidInputs.get(0));
    }
}
Also used : IFabricatorSmeltingRecipe(forestry.api.recipes.IFabricatorSmeltingRecipe) IGuiFluidStackGroup(mezz.jei.api.gui.IGuiFluidStackGroup) Fluid(net.minecraftforge.fluids.Fluid) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IFabricatorRecipe(forestry.api.recipes.IFabricatorRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IFabricatorRecipe

use of forestry.api.recipes.IFabricatorRecipe in project ForestryMC by ForestryMC.

the class FabricatorRecipeManager method addRecipe.

@Override
public void addRecipe(ItemStack plan, FluidStack molten, ItemStack result, Object[] pattern) {
    ShapedRecipeCustom patternRecipe = new ShapedRecipeCustom(result, pattern);
    NonNullList<NonNullList<ItemStack>> ingredients = patternRecipe.getRawIngredients();
    IFabricatorRecipe recipe = new FabricatorRecipe(plan, molten, result, ingredients, patternRecipe.getOreDicts(), patternRecipe.getWidth(), patternRecipe.getHeight());
    addRecipe(recipe);
}
Also used : NonNullList(net.minecraft.util.NonNullList) IFabricatorRecipe(forestry.api.recipes.IFabricatorRecipe) IFabricatorRecipe(forestry.api.recipes.IFabricatorRecipe) ShapedRecipeCustom(forestry.core.recipes.ShapedRecipeCustom)

Example 4 with IFabricatorRecipe

use of forestry.api.recipes.IFabricatorRecipe 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)

Example 5 with IFabricatorRecipe

use of forestry.api.recipes.IFabricatorRecipe in project ForestryMC by ForestryMC.

the class TileFabricator method getRecipe.

@Nullable
private RecipePair getRecipe() {
    IInventoryAdapter inventory = getInternalInventory();
    ItemStack plan = inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN);
    FluidStack liquid = moltenTank.getFluid();
    RecipePair<IFabricatorRecipe> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
    IFabricatorRecipe recipe = recipePair.getRecipe();
    if (liquid != null && recipe != null && !liquid.containsFluid(recipe.getLiquid())) {
        return RecipePair.EMPTY;
    }
    return recipePair;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IInventoryAdapter(forestry.core.inventory.IInventoryAdapter) ItemStack(net.minecraft.item.ItemStack) IFabricatorRecipe(forestry.api.recipes.IFabricatorRecipe) Nullable(javax.annotation.Nullable)

Aggregations

IFabricatorRecipe (forestry.api.recipes.IFabricatorRecipe)6 ItemStack (net.minecraft.item.ItemStack)5 FluidStack (net.minecraftforge.fluids.FluidStack)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NonNullList (net.minecraft.util.NonNullList)2 IErrorLogic (forestry.api.core.IErrorLogic)1 IFabricatorSmeltingRecipe (forestry.api.recipes.IFabricatorSmeltingRecipe)1 IInventoryAdapter (forestry.core.inventory.IInventoryAdapter)1 ICraftingPlan (forestry.core.items.ICraftingPlan)1 ShapedRecipeCustom (forestry.core.recipes.ShapedRecipeCustom)1 Nullable (javax.annotation.Nullable)1 IGuiFluidStackGroup (mezz.jei.api.gui.IGuiFluidStackGroup)1 IGuiItemStackGroup (mezz.jei.api.gui.IGuiItemStackGroup)1 Item (net.minecraft.item.Item)1 Fluid (net.minecraftforge.fluids.Fluid)1