@Override public void getIngredients(IIngredients ingredients) { IFabricatorRecipe recipe = getRecipe(); NonNullList<NonNullList<ItemStack>> itemInputs = recipe.getIngredients(); List<List<ItemStack>> inputStacks = new ArrayList<>(); for (List<ItemStack> stacks : itemInputs) { List<ItemStack> copy = new ArrayList<>(); copy.addAll(stacks); inputStacks.add(copy); } ingredients.setInputLists(ItemStack.class, inputStacks); ingredients.setInputs(FluidStack.class, Collections.singletonList(getRecipe().getLiquid())); ingredients.setOutput(ItemStack.class, recipe.getRecipeOutput()); } }
@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; }
Fluid recipeFluid = recipe.getLiquid().getFluid(); for (IFabricatorSmeltingRecipe s : getSmeltingInputs().get(recipeFluid)) { smeltingInput.add(s.getResource());
@Override protected void onIndexUpdate(int index, IFabricatorRecipe recipe) { selectedElement.add(new TankElement(1, 33, null, () -> new FluidTankInfo(recipe.getLiquid(), 2000), FABRICATOR_TANK_OVERLAY, 16, 16)); NonNullList<NonNullList<ItemStack>> ingredients = recipe.getIngredients(); for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { int ingredientIndex = y * 3 + x; if (ingredientIndex >= ingredients.size()) { continue; } NonNullList<ItemStack> items = ingredients.get(ingredientIndex); selectedElement.add(new IngredientElement(21 + x * 19, 1 + y * 19, Ingredient.fromStacks(items.toArray(new ItemStack[items.size()])))); } } ItemStack plan = recipe.getPlan(); if (!plan.isEmpty()) { selectedElement.item(91, 1, plan); } selectedElement.item(91, 39, recipe.getRecipeOutput()); NonNullList<ItemStack> smeltingInput = NonNullList.create(); Fluid recipeFluid = recipe.getLiquid().getFluid(); for (IFabricatorSmeltingRecipe s : getSmeltingInputs().get(recipeFluid)) { smeltingInput.add(s.getResource()); } if (!smeltingInput.isEmpty()) { selectedElement.add(new IngredientElement(1, 6, smeltingInput)); } }
@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; }
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); } } } }