@Override public boolean workCycle() { if (currentRecipe == null) { return false; } if (!inventory.removeResources(currentRecipe.getResources())) { return false; } FluidStack resultFluid = currentRecipe.getFluidOutput(); productTank.fillInternal(resultFluid, true); if (!currentRecipe.getRemnants().isEmpty() && world.rand.nextFloat() < currentRecipe.getRemnantsChance()) { ItemStack remnant = currentRecipe.getRemnants().copy(); inventory.addRemnant(remnant, true); } return true; }
@Override public void getIngredients(IIngredients ingredients) { NonNullList<ItemStack> resources = getRecipe().getResources(); ingredients.setInputs(ItemStack.class, resources); ItemStack remnants = getRecipe().getRemnants(); if (!remnants.isEmpty()) { ingredients.setOutput(ItemStack.class, remnants); } ingredients.setOutput(FluidStack.class, getRecipe().getFluidOutput()); }
@Override public boolean checkIsRecipe(ISqueezerRecipe recipe) { if(!StackHelper.matches(liquid, InputHelper.toILiquidStack(recipe.getFluidOutput()))) { return false; } if(ingredients != null) { boolean matched = true; if(ingredients.length != recipe.getResources().size()) { return false; } for(int i = 0; i < ingredients.length; i++) { if(!matches(ingredients[i], toIItemStack(recipe.getResources().get(i)))) matched = false; } return matched; } else { return true; } }
@Override public boolean hasWork() { checkRecipe(); boolean hasResources = inventory.hasResources(); boolean hasRecipe = true; boolean canFill = true; boolean canAdd = true; if (hasResources) { hasRecipe = currentRecipe != null; if (hasRecipe) { FluidStack resultFluid = currentRecipe.getFluidOutput(); canFill = productTank.fillInternal(resultFluid, false) == resultFluid.amount; if (!currentRecipe.getRemnants().isEmpty()) { canAdd = inventory.addRemnant(currentRecipe.getRemnants(), false); } } } IErrorLogic errorLogic = getErrorLogic(); errorLogic.setCondition(!hasResources, EnumErrorCode.NO_RESOURCE); errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE); errorLogic.setCondition(!canFill, EnumErrorCode.NO_SPACE_TANK); errorLogic.setCondition(!canAdd, EnumErrorCode.NO_SPACE_INVENTORY); return hasResources && hasRecipe && canFill && canAdd; }
private static boolean matches(ISqueezerRecipe recipe, ItemStack inputStack) { for (ItemStack obj : recipe.getResources()) { if (inputStack.isItemEqual(obj)) { return true; } } return false; } }
private boolean checkRecipe() { ISqueezerRecipe matchingRecipe = null; if (inventory.hasResources()) { NonNullList<ItemStack> resources = inventory.getResources(); if (currentRecipe != null && ItemStackUtil.containsSets(currentRecipe.getResources(), resources, true, false) > 0) { matchingRecipe = currentRecipe; } else { matchingRecipe = SqueezerRecipeManager.findMatchingRecipe(resources); } } if (currentRecipe != matchingRecipe) { currentRecipe = matchingRecipe; if (currentRecipe != null) { int recipeTime = currentRecipe.getProcessingTime(); setTicksPerWorkCycle(recipeTime * TICKS_PER_RECIPE_TIME); setEnergyPerWorkCycle(recipeTime * ENERGY_PER_RECIPE_TIME); } } getErrorLogic().setCondition(currentRecipe == null, EnumErrorCode.NO_RECIPE); return currentRecipe != null; }
@Override public String getRecipeInfo() { return LogHelper.getStackDescription(recipe.getFluidOutput()); } }
public static void getSqueezerOutputs(ItemStack inputStack, NonNullList<ItemStack> outputItems) { for (ISqueezerRecipe recipe : RecipeManagers.squeezerManager.recipes()) { if (matches(recipe, inputStack)) { if (!recipe.getRemnants().isEmpty()) { outputItems.add(recipe.getRemnants()); } } } }
@Override public float getRemnantsChance() { return getRecipe().getRemnantsChance(); } }
final ItemStack input = entry.getResources().get(0); final FluidStack output = entry.getFluidOutput(); if (!ItemStack.areItemStacksEqual(stack, input) && !OreDictionary.itemMatches(input, stack, true)) { continue;
public static boolean canUse(ItemStack itemStack) { for (ISqueezerRecipe recipe : recipes) { for (ItemStack recipeInput : recipe.getResources()) { if (ItemStackUtil.isCraftingEquivalent(recipeInput, itemStack, true, false)) { return true; } } } return SqueezerRecipeManager.findMatchingContainerRecipe(itemStack) != null; }
public static void getSqueezerFluidOutputs(ItemStack inputStack, NonNullList<FluidStack> outputFluids) { for (ISqueezerRecipe recipe : RecipeManagers.squeezerManager.recipes()) { if (matches(recipe, inputStack)) { outputFluids.add(recipe.getFluidOutput()); } } }
@Nullable public static ISqueezerRecipe findMatchingRecipe(NonNullList<ItemStack> items) { // Find container recipes for (ItemStack itemStack : items) { ISqueezerContainerRecipe containerRecipe = findMatchingContainerRecipe(itemStack); if (containerRecipe != null) { ISqueezerRecipe recipe = containerRecipe.getSqueezerRecipe(itemStack); if (recipe != null) { return recipe; } } } for (ISqueezerRecipe recipe : recipes) { if (ItemStackUtil.containsSets(recipe.getResources(), items, false, false) > 0) { return recipe; } } return null; }