From 9022c0f16699228d98bb9f4ea7c689827c337024 Mon Sep 17 00:00:00 2001 From: bruberu <80226372+bruberu@users.noreply.github.com> Date: Sat, 13 Jan 2024 22:52:49 -0600 Subject: [PATCH] Overload AbstractRecipeLogic functions (#2311) Co-authored-by: alongstringofnumbers --- .../capability/impl/AbstractRecipeLogic.java | 63 ++++++++++++++++--- .../LargeTurbineWorkableHandler.java | 2 +- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index cc2ce878aee..e00cdc21235 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -1,7 +1,11 @@ package gregtech.api.capability.impl; import gregtech.api.GTValues; -import gregtech.api.capability.*; +import gregtech.api.capability.GregtechDataCodes; +import gregtech.api.capability.GregtechTileCapabilities; +import gregtech.api.capability.IMultiblockController; +import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.IWorkable; import gregtech.api.metatileentity.MTETrait; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.multiblock.CleanroomType; @@ -432,34 +436,53 @@ protected boolean checkCleanroomRequirement(@NotNull Recipe recipe) { *
    *
  1. The recipe is run in parallel if possible.
  2. *
  3. The potentially parallel recipe is then checked to exist.
  4. - *
  5. If it exists, it checks if the recipe is runnable with the current inputs.
  6. + *
  7. If it exists, it checks if the recipe is runnable with the inputs provided.
  8. *
* If the above conditions are met, the recipe is engaged to be run * - * @param recipe the recipe to prepare + * @param recipe the recipe to prepare + * @param inputInventory the inventory to draw items from + * @param inputFluidInventory the fluid tanks to draw fluid from * @return true if the recipe was successfully prepared, else false */ - protected boolean prepareRecipe(Recipe recipe) { + public boolean prepareRecipe(Recipe recipe, IItemHandlerModifiable inputInventory, + IMultipleTankHandler inputFluidInventory) { recipe = Recipe.trimRecipeOutputs(recipe, getRecipeMap(), metaTileEntity.getItemOutputLimit(), metaTileEntity.getFluidOutputLimit()); // Pass in the trimmed recipe to the parallel logic recipe = findParallelRecipe( recipe, - getInputInventory(), - getInputTank(), + inputInventory, + inputFluidInventory, getOutputInventory(), getOutputTank(), getMaxParallelVoltage(), getParallelLimit()); - if (recipe != null && setupAndConsumeRecipeInputs(recipe, getInputInventory())) { + if (recipe != null && setupAndConsumeRecipeInputs(recipe, inputInventory, inputFluidInventory)) { setupRecipe(recipe); return true; } return false; } + /** + * Prepares the recipe to be run. + *
    + *
  1. The recipe is run in parallel if possible.
  2. + *
  3. The potentially parallel recipe is then checked to exist.
  4. + *
  5. If it exists, it checks if the recipe is runnable with the current inputs.
  6. + *
+ * If the above conditions are met, the recipe is engaged to be run + * + * @param recipe the recipe to prepare + * @return true if the recipe was successfully prepared from the default inventory, else false + */ + public boolean prepareRecipe(Recipe recipe) { + return prepareRecipe(recipe, getInputInventory(), getInputTank()); + } + /** * DO NOT use the parallelLimit field directly, EVER * @@ -549,11 +572,14 @@ protected static boolean areItemStacksEqual(@NotNull ItemStack stackA, @NotNull * @param recipe - The Recipe that will be consumed from the inputs and ran in the machine * @param importInventory - The inventory that the recipe should be consumed from. * Used mainly for Distinct bus implementation for multiblocks to specify - * a specific bus + * a specific bus, or for addons to use external inventories. + * @param importFluids - The tanks that the recipe should be consumed from + * Used currently in addons to use external tanks. * @return - true if the recipe is successful, false if the recipe is not successful */ protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe, - @NotNull IItemHandlerModifiable importInventory) { + @NotNull IItemHandlerModifiable importInventory, + @NotNull IMultipleTankHandler importFluids) { this.overclockResults = calculateOverclock(recipe); modifyOverclockPost(overclockResults, recipe.getRecipePropertyStorage()); @@ -563,7 +589,6 @@ protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe, } IItemHandlerModifiable exportInventory = getOutputInventory(); - IMultipleTankHandler importFluids = getInputTank(); IMultipleTankHandler exportFluids = getOutputTank(); // We have already trimmed outputs and chanced outputs at this time @@ -589,6 +614,24 @@ protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe, return false; } + /** + * Determines if the provided recipe is possible to run from the provided inventory, or if there is anything + * preventing + * the Recipe from being completed. + *

+ * Will consume the inputs of the Recipe if it is possible to run. + * + * @param recipe - The Recipe that will be consumed from the inputs and ran in the machine + * @param importInventory - The inventory that the recipe should be consumed from. + * Used mainly for Distinct bus implementation for multiblocks to specify + * a specific bus + * @return - true if the recipe is successful, false if the recipe is not successful + */ + protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe, + @NotNull IItemHandlerModifiable importInventory) { + return setupAndConsumeRecipeInputs(recipe, importInventory, this.getInputTank()); + } + /** * @param resultOverclock the overclock data to use. Format: {@code [EUt, duration]}. * @return true if there is enough energy to continue recipe progress diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java b/src/main/java/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java index db414ae4da7..f9f393216e6 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java @@ -131,7 +131,7 @@ protected boolean checkPreviousRecipe() { } @Override - protected boolean prepareRecipe(Recipe recipe) { + public boolean prepareRecipe(Recipe recipe) { IRotorHolder rotorHolder = ((MetaTileEntityLargeTurbine) metaTileEntity).getRotorHolder(); if (rotorHolder == null || !rotorHolder.hasRotor()) return false;