public static boolean matches(IFermenterRecipe recipe, ItemStack res, FluidStack liqu) { ItemStack resource = recipe.getResource(); if (!ItemStackUtil.isCraftingEquivalent(resource, res, recipe.getResourceOreName(), false)) { return false; } FluidStack fluid = recipe.getFluidResource(); return liqu.isFluidEqual(fluid); }
@Override public boolean addRecipe(IFermenterRecipe recipe) { FluidStack liquid = recipe.getFluidResource(); recipeFluidInputs.add(liquid.getFluid()); Fluid output = recipe.getOutput(); recipeFluidOutputs.add(output); return recipes.add(recipe); }
public static boolean isResource(ItemStack resource) { if (resource.isEmpty()) { return false; } for (IFermenterRecipe recipe : recipes) { if (ItemStackUtil.isCraftingEquivalent(recipe.getResource(), resource, recipe.getResourceOreName(), false)) { return true; } } return false; }
@Override public void getIngredients(IIngredients ingredients) { List<ItemStack> fuelInputs = new ArrayList<>(); for (FermenterFuel fuel : FuelManager.fermenterFuel.values()) { fuelInputs.add(fuel.getItem()); } ingredients.setInputLists(ItemStack.class, Arrays.asList( Collections.singletonList(fermentable), fuelInputs )); FluidStack fluidInput = getRecipe().getFluidResource().copy(); fluidInput.amount = getRecipe().getFermentationValue(); ingredients.setInput(FluidStack.class, fluidInput); int amount = Math.round(getRecipe().getFermentationValue() * getRecipe().getModifier()); if (fermentable.getItem() instanceof IVariableFermentable) { amount *= ((IVariableFermentable) fermentable.getItem()).getFermentationModifier(fermentable); } FluidStack fluidOutput = new FluidStack(getRecipe().getOutput(), amount); ingredients.setOutput(FluidStack.class, fluidOutput); } }
@Override public boolean workCycle() { if (currentRecipe == null) { return false; } int fermented = Math.min(fermentationTime, fuelCurrentFerment); int productAmount = Math.round(fermented * currentRecipe.getModifier() * currentResourceModifier); productTank.fillInternal(new FluidStack(currentRecipe.getOutput(), productAmount), true); fuelBurnTime--; resourceTank.drain(fermented, true); fermentationTime -= fermented; // Not done yet if (fermentationTime > 0) { return false; } currentRecipe = null; return true; }
@Override public String getRecipeInfo() { return recipe.getOutput().getName(); } }
private void checkRecipe() { if (currentRecipe != null) { return; } ItemStack resource = getStackInSlot(InventoryFermenter.SLOT_RESOURCE); FluidStack fluid = resourceTank.getFluid(); if (fluid != null) { currentRecipe = FermenterRecipeManager.findMatchingRecipe(resource, fluid); } fermentationTotalTime = fermentationTime = currentRecipe == null ? 0 : currentRecipe.getFermentationValue(); if (currentRecipe != null) { currentResourceModifier = determineResourceMod(resource); decrStackSize(InventoryFermenter.SLOT_RESOURCE, 1); } }
public static List<FermenterRecipeWrapper> getFermenterRecipes(IStackHelper stackHelper) { List<FermenterRecipeWrapper> recipes = new ArrayList<>(); for (IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) { if (!recipe.getResource().isEmpty()) { addWrapperToList(stackHelper, recipe, recipe.getResource(), recipes); } else if (recipe.getResourceOreName() != null) { NonNullList<ItemStack> itemStacks = OreDictionary.getOres(recipe.getResourceOreName()); if (!itemStacks.isEmpty()) { for (ItemStack resource : itemStacks) { addWrapperToList(stackHelper, recipe, resource, recipes); } } } else { Log.error("Empty resource for recipe"); } } return recipes; }
@Override public boolean hasWork() { checkRecipe(); checkFuel(); int fermented = Math.min(fermentationTime, fuelCurrentFerment); boolean hasRecipe = currentRecipe != null; boolean hasFuel = fuelBurnTime > 0; boolean hasResource = fermentationTime > 0 || !getStackInSlot(InventoryFermenter.SLOT_RESOURCE).isEmpty(); FluidStack drained = resourceTank.drain(fermented, false); boolean hasFluidResource = drained != null && drained.amount == fermented; boolean hasFluidSpace = true; if (hasRecipe) { int productAmount = Math.round(fermented * currentRecipe.getModifier() * currentResourceModifier); Fluid output = currentRecipe.getOutput(); FluidStack fluidStack = new FluidStack(output, productAmount); hasFluidSpace = productTank.fillInternal(fluidStack, false) == fluidStack.amount; } IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE); errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL); errorLogic.setCondition(!hasResource, EnumErrorCode.NO_RESOURCE); errorLogic.setCondition(!hasFluidResource, EnumErrorCode.NO_RESOURCE_LIQUID); errorLogic.setCondition(!hasFluidSpace, EnumErrorCode.NO_SPACE_TANK); return hasRecipe && hasFuel && hasResource && hasFluidResource && hasFluidSpace; }
@Override public boolean checkIsRecipe(IFermenterRecipe recipe) { if(isInOreDictOreIsThatOreDict(input, recipe.getResourceOreName())) { return true; } // check for input items if(matches(input, toIItemStack(recipe.getResource()))) { return true; } // check for input liquids return matches(input, toILiquidStack(recipe.getFluidResource())); } }
@Override public boolean removeRecipe(IFermenterRecipe recipe) { FluidStack liquid = recipe.getFluidResource(); recipeFluidInputs.remove(liquid.getFluid()); Fluid output = recipe.getOutput(); recipeFluidOutputs.remove(output); return recipes.remove(recipe); }