-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix large turbine recipe selection #2324
Fix large turbine recipe selection #2324
Conversation
...a/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java
Outdated
Show resolved
Hide resolved
...a/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java
Outdated
Show resolved
Hide resolved
...a/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java
Outdated
Show resolved
Hide resolved
src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java
Outdated
Show resolved
Hide resolved
I don't think the added overloaded methods to // In LargeTurbineWorkableHandler...
// override findRecipe() from ARL
@Override
protected @Nullable Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs,
IMultipleTankHandler fluidInputs) {
return findRecipe(maxVoltage, inputs, fluidInputs, this::canDoRecipeConsideringParallel);
}
// local method for finding the recipe along with a new predicate
protected @Nullable Recipe findRecipe(long maxVoltage, IItemHandlerModifiable inputs,
IMultipleTankHandler fluidInputs, Predicate<Recipe> parallelCheck) {
RecipeMap<?> map = getRecipeMap();
if (map == null || !isRecipeMapValid(map)) {
return null;
}
final List<ItemStack> items = GTUtility.itemHandlerToList(inputs)
.stream().filter(s -> !s.isEmpty()).collect(Collectors.toList());
final List<FluidStack> fluids = GTUtility.fluidHandlerToList(fluidInputs)
.stream().filter(f -> f != null && f.amount != 0).collect(Collectors.toList());
return map.find(items, fluids, recipe -> {
if (recipe.getEUt() > maxVoltage) return false;
return recipe.matches(false, inputs, fluidInputs) &&
(parallelCheck == null || parallelCheck.test(recipe));
});
} This essentially does what I also think
// In LargeTurbineWorkableHandler...
public FluidStack getInputFluidStack() {
// Previous Recipe is always null on first world load, so try to acquire a new recipe
if (previousRecipe == null) {
Recipe recipe = findRecipe(Integer.MAX_VALUE, getInputInventory(), getInputTank(), null);
return recipe == null ? null : getInputTank().drain(
new FluidStack(recipe.getFluidInputs().get(0).getInputFluidStack().getFluid(), Integer.MAX_VALUE),
false);
}
FluidStack fuelStack = previousRecipe.getFluidInputs().get(0).getInputFluidStack();
return getInputTank().drain(new FluidStack(fuelStack.getFluid(), Integer.MAX_VALUE), false);
} Otherwise, I've tested the changes (both mine and this PR) in-game and the issue is fixed. |
Ah, yeah - I was trying to avoid copy- 🍝 the internals of getting the recipie map and constructing the lists. Figured the overloads were a reasonable tradeoff for that, but I can flip it around.
Lol it used to be
👍 |
@ghzdude looking at your change to |
maybe
I mean, it's possible that the method could be moved to ARL for addons to use, but idk what tech or sereni thinks about that.
@josiah-roberts i've found that if you use the predicate, then it won't show any fuel once the turbine is formed, because there wouldn't be enough of anything to get a recipe |
Sorry, I'm not following. It won't show any fuel where? |
Yeah just discovered that. I don't think that calling without a predicate is a viable solution though; imagine a case where enumerate recipes:
If we run the fluid stack without the predicate logic, we'll pull the wrong fluid stack on prepare. It sounds like we want the behavior of, "if there's not enough to actually run something, but we have some, then show that", then we need to do the equivelent of This is kinda gross though; we're potentially showing a fluid input stack for a recipe we don't think is valid. But it's the most-correct approach that comes to mind right now. |
it would only be incorrect if |
How about this? b19a2a9 |
And removed the overloads here: 1faffbc |
...a/gregtech/common/metatileentities/multi/electric/generator/LargeTurbineWorkableHandler.java
Outdated
Show resolved
Hide resolved
mkay, this looks good to me now. I'm gonna wait and let the other devs look at this and see what they think. |
Great, thanks for walking me through my first PR. 🙌🏻 |
7029fd1
to
04e149b
Compare
What
Large turbines have a disagreement between recipe selection and recipe execution.
fuel inputs
are availablefuel inputs * parallel
availableThis leads to cases where turbines get stuck thinking they can run a recipe (
findRecipe
,checkPreviousRecipe
), but fail to actually run the recipe (prepareRecipe
). Because there is a disagreement about what it means to have a valid recipe, the turbine won't switch to other fuels even if they are available.Implementation Details
This PR updates
LargeTurbineWorkableHandler
to consider the parallelism of the turbine when implementingfindRecipe
andcheckPreviousRecipe
. This ensures that recipes with enough fuel for base but not enough for parallel are not selected / retained.Note that this has the drawback of requiring a handshake between
findRecipe + checkPreviousRecipe
andprepareRecipe
. There is no hard guarantee that they will agree (this PR fixes such a disagreement).Alternatives considered (discussed in Discord):
recipe * parallel
instead ofrecipe
parallel * normal
runtimeOutcome
base < fuel < base * parallel
fuelA number of new overloads forRemoved and simply copied underlying function implementation based on @ghzdude's reviewfindRecipe
taking optional recipe predicatesAdditional Information
LargeTurbineWorkableHandler.excessVoltage
isn't misbehaving when used prior toprepareRecipe
, and figure out the reason it's a stateful class-level field to begin with.For efficiency adjustment in fuel consumption; impl should be right.
There doesen't appear to be, beyond
see
, which I'm not a big fan of here.LargeTurbineWorkableHandler
.Done
Potential Compatibility Issues
Some turbines that jammed previously should run now. I don't think that should be a problem.