@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 public static RecipePair<IFabricatorRecipe> findMatchingRecipe(ItemStack plan, IInventory resources) { ItemStack[][] gridResources = RecipeUtil.getResources(resources); for (IFabricatorRecipe recipe : recipes) { if (!recipe.getPlan().isEmpty() && !ItemStackUtil.isCraftingEquivalent(recipe.getPlan(), plan)) { continue; } String[][] oreDicts = RecipeUtil.matches(recipe.getIngredients(), recipe.getOreDicts(), recipe.getWidth(), recipe.getHeight(), gridResources); if (oreDicts != null) { return new RecipePair<>(recipe, oreDicts); } } return RecipePair.EMPTY; }
@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)); } }
ItemStack plan = recipe.getPlan(); if (!plan.isEmpty()) { guiItemStacks.set(planSlot, plan); Fluid recipeFluid = recipe.getLiquid().getFluid(); for (IFabricatorSmeltingRecipe s : getSmeltingInputs().get(recipeFluid)) { smeltingInput.add(s.getResource()); craftingGridHelper.setInputs(guiItemStacks, itemStackInputs, recipe.getWidth(), recipe.getHeight());
@Override public String getRecipeInfo() { return LogHelper.getStackDescription(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; }
public static boolean isPlan(ItemStack plan) { for (IFabricatorRecipe recipe : recipes) { if (ItemStackUtil.isIdenticalItem(recipe.getPlan(), plan)) { return true; } } return false; }
public static Collection<IFabricatorRecipe> getRecipes(ItemStack itemStack) { if (itemStack.isEmpty()) { return Collections.emptyList(); } return recipes.stream().filter(recipe -> { ItemStack output = recipe.getRecipeOutput(); return ItemStackUtil.isIdenticalItem(itemStack, output); }).collect(Collectors.toList()); } }
@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; }
public ItemStack getResult(RecipePair<IFabricatorRecipe> myRecipePair) { IFabricatorRecipe myRecipe = myRecipePair.getRecipe(); if (myRecipe == null) { return ItemStack.EMPTY; } return myRecipe.getRecipeOutput().copy(); }
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); } } } }
@Override public boolean checkIsRecipe(IFabricatorRecipe recipe) { return recipe != null && matches(product, toIItemStack(recipe.getRecipeOutput())); } }