Skip to content

Commit

Permalink
Overload AbstractRecipeLogic functions (GregTechCEu#2311)
Browse files Browse the repository at this point in the history
Co-authored-by: alongstringofnumbers <[email protected]>
  • Loading branch information
bruberu and ALongStringOfNumbers authored Jan 14, 2024
1 parent e0434c7 commit 9022c0f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
63 changes: 53 additions & 10 deletions src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -432,34 +436,53 @@ protected boolean checkCleanroomRequirement(@NotNull Recipe recipe) {
* <ol>
* <li>The recipe is run in parallel if possible.</li>
* <li>The potentially parallel recipe is then checked to exist.</li>
* <li>If it exists, it checks if the recipe is runnable with the current inputs.</li>
* <li>If it exists, it checks if the recipe is runnable with the inputs provided.</li>
* </ol>
* 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.
* <ol>
* <li>The recipe is run in parallel if possible.</li>
* <li>The potentially parallel recipe is then checked to exist.</li>
* <li>If it exists, it checks if the recipe is runnable with the current inputs.</li>
* </ol>
* 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
*
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -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.
* <p>
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9022c0f

Please sign in to comment.