public static Collection<ICarpenterRecipe> getRecipes(ItemStack itemStack) { if (itemStack.isEmpty()) { return Collections.emptyList(); } return recipes.stream().filter(recipe -> { ItemStack output = recipe.getCraftingGridRecipe().getOutput(); return ItemStackUtil.isIdenticalItem(itemStack, output); }).collect(Collectors.toList()); }
@Nullable public static String[][] matches(IDescriptiveRecipe recipe, IInventory inventoryCrafting) { NonNullList<NonNullList<ItemStack>> recipeIngredients = recipe.getRawIngredients(); NonNullList<String> oreDicts = recipe.getOreDicts(); int width = recipe.getWidth(); int height = recipe.getHeight(); return matches(recipeIngredients, oreDicts, width, height, inventoryCrafting); }
@Override protected void onIndexUpdate(int index, ICarpenterRecipe recipe) { selectedElement.add(new TankElement(91, 1, null, () -> new FluidTankInfo(recipe.getFluidResource(), Constants.PROCESSOR_TANK_CAPACITY), CARPENTER_TANK_OVERLAY)); IDescriptiveRecipe gridRecipe = recipe.getCraftingGridRecipe(); NonNullList<NonNullList<ItemStack>> ingredients = gridRecipe.getRawIngredients(); 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(1 + x * 19, 3 + y * 19, Ingredient.fromStacks(items.toArray(new ItemStack[items.size()])))); } } selectedElement.item(71, 41, gridRecipe.getOutput()); } }
@Override public void setRecipe(IRecipeLayout recipeLayout, CarpenterRecipeWrapper recipeWrapper, IIngredients ingredients) { IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks(); IGuiFluidStackGroup guiFluidStacks = recipeLayout.getFluidStacks(); guiItemStacks.init(boxSlot, true, 73, 3); guiItemStacks.init(craftOutputSlot, false, 70, 34); for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { int index = craftInputSlot + x + y * 3; guiItemStacks.init(index, true, x * 18, 3 + y * 18); } } guiFluidStacks.init(inputTank, true, 141, 1, 16, 58, 10000, false, tankOverlay); ICarpenterRecipe recipe = recipeWrapper.getRecipe(); ItemStack box = recipe.getBox(); if (!box.isEmpty()) { guiItemStacks.set(boxSlot, box); } List<List<ItemStack>> outputs = ingredients.getOutputs(ItemStack.class); guiItemStacks.set(craftOutputSlot, outputs.get(0)); IDescriptiveRecipe craftingGridRecipe = recipe.getCraftingGridRecipe(); List<List<ItemStack>> craftingInputs = recipeWrapper.getInputStacks(); craftingGridHelper.setInputs(guiItemStacks, craftingInputs, craftingGridRecipe.getWidth(), craftingGridRecipe.getHeight()); List<List<FluidStack>> fluidInputs = ingredients.getInputs(FluidStack.class); if (!fluidInputs.isEmpty()) { guiFluidStacks.set(inputTank, fluidInputs.get(0)); } }
public CarpenterRecipeWrapper(ICarpenterRecipe recipe) { super(recipe); IDescriptiveRecipe craftingGridRecipe = recipe.getCraftingGridRecipe(); NonNullList<NonNullList<ItemStack>> inputs = craftingGridRecipe.getRawIngredients(); this.inputStacks = new ArrayList<>(); for (List<ItemStack> stacks : inputs) { List<ItemStack> copy = new ArrayList<>(); copy.addAll(stacks); this.inputStacks.add(copy); } }
@Override protected String getRecipeInfo() { return recipe.getCraftingGridRecipe().getOutput().getDisplayName(); } }
@Override public void getIngredients(IIngredients ingredients) { ICarpenterRecipe recipe = getRecipe(); IDescriptiveRecipe craftingGridRecipe = recipe.getCraftingGridRecipe(); List<List<ItemStack>> inputStacks = new ArrayList<>(); ItemStack box = recipe.getBox(); if (!box.isEmpty()) { inputStacks.add(Collections.singletonList(box)); } inputStacks.addAll(getInputStacks()); ingredients.setInputLists(ItemStack.class, inputStacks); FluidStack fluidResource = recipe.getFluidResource(); if (fluidResource != null) { ingredients.setInputs(FluidStack.class, Collections.singletonList(fluidResource)); } ItemStack recipeOutput = craftingGridRecipe.getOutput(); ingredients.setOutput(ItemStack.class, recipeOutput); }
@Override public boolean checkIsRecipe(ICarpenterRecipe recipe) { if(recipe.getCraftingGridRecipe().getOutput().isItemEqual(output)) { if(fluidInput == null) { return true; } else { return fluidInput.isFluidEqual(recipe.getFluidResource()); } } return false; }
@Override public boolean workCycle() { if (!removeLiquidResources(true)) { return false; } if (!removeItemResources(true)) { return false; } if (currentRecipe != null) { ItemStack pendingProduct = currentRecipe.getCraftingGridRecipe().getOutput(); InventoryUtil.tryAddStack(this, pendingProduct, InventoryCarpenter.SLOT_PRODUCT, InventoryCarpenter.SLOT_PRODUCT_COUNT, true); } return true; }
@Override public boolean hasWork() { if (updateOnInterval(20)) { checkRecipe(); } boolean hasRecipe = currentRecipe != null; boolean hasLiquidResources = true; boolean hasItemResources = true; boolean canAdd = true; if (hasRecipe) { hasLiquidResources = removeLiquidResources(false); hasItemResources = removeItemResources(false); ItemStack pendingProduct = currentRecipe.getCraftingGridRecipe().getOutput(); canAdd = InventoryUtil.tryAddStack(this, pendingProduct, InventoryCarpenter.SLOT_PRODUCT, InventoryCarpenter.SLOT_PRODUCT_COUNT, true, false); } IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE); errorLogic.setCondition(!hasLiquidResources, EnumErrorCode.NO_RESOURCE_LIQUID); errorLogic.setCondition(!hasItemResources, EnumErrorCode.NO_RESOURCE_INVENTORY); errorLogic.setCondition(!canAdd, EnumErrorCode.NO_SPACE_INVENTORY); return hasRecipe && hasItemResources && hasLiquidResources && canAdd; }
public void checkRecipe() { if (world.isRemote) { return; } if (CarpenterRecipeManager.matches(currentRecipe, resourceTank.getFluid(), getBoxStack(), craftingInventory) == null) { RecipePair<ICarpenterRecipe> recipePair = CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory); currentRecipe = recipePair.getRecipe(); oreDicts = recipePair.getOreDictEntries(); if (!recipePair.isEmpty()) { int recipeTime = currentRecipe.getPackagingTime(); setTicksPerWorkCycle(recipeTime * TICKS_PER_RECIPE_TIME); setEnergyPerWorkCycle(recipeTime * ENERGY_PER_RECIPE_TIME); ItemStack craftingResult = currentRecipe.getCraftingGridRecipe().getOutput(); craftPreviewInventory.setInventorySlotContents(0, craftingResult); } else { craftPreviewInventory.setInventorySlotContents(0, ItemStack.EMPTY); } } }