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()); }
@Override protected String getRecipeInfo() { return recipe.getCraftingGridRecipe().getOutput().getDisplayName(); } }
@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 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 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; }
@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()); } }
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); } } }