-
Notifications
You must be signed in to change notification settings - Fork 181
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
Re-implement FluidTankList & OverlayedFluidHandler #1695
Conversation
…tityMultiFluidHatch to use regular tank lists
src/main/java/gregtech/api/capability/IMultipleTankHandler.java
Outdated
Show resolved
Hide resolved
src/main/java/gregtech/api/capability/IMultipleTankHandler.java
Outdated
Show resolved
Hide resolved
src/main/java/gregtech/api/capability/IPropertyFluidFilter.java
Outdated
Show resolved
Hide resolved
src/main/java/gregtech/api/capability/IThermalFluidHandlerItemStack.java
Show resolved
Hide resolved
src/main/java/gregtech/api/capability/impl/ThermalFluidHandlerItemStack.java
Show resolved
Hide resolved
Getting this JEI integration error when launching the game, https://pastebin.com/VjaGBEf3 |
In addition to the changes in FluidTankList and OverlayedFluidHandler, new changes in API were introduced.
|
JEI integration error should be resolved now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In progress review
int getMaxFluidTemperature(); | ||
|
||
/** | ||
* This is always checked, regardless of the contained fluid being a {@link MaterialFluid} or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get a bit more clarification on this and the above javadoc, This is always checked, as it is implemented by vanilla, regardless...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically implemented by forge, since the whole fluid thing is mod-introduced system, but I'll expand the docs a bit.
@Nonnull | ||
public static FluidStack getLava(int amount) { | ||
return new FluidStack(FluidRegistry.LAVA, amount); | ||
return stack == null || CommonFluidFilters.BOILER_FLUID.test(stack); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you have this deprecated, but this is a logic change, in case people were still calling this. Before if the stack was null, this returned false. Now it will return true if the stack is null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another stupid mistake by me 😃😎
* @param fluid fluid | ||
* @return whether the fluid in fluid stack and fluid parameter are equal | ||
*/ | ||
public static boolean matchesFluid(@Nonnull FluidStack fluidStack, @Nonnull Fluid fluid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be a case where we want a FluidStack and FluidStack matches method? Say for example the fluid regulator or fluid voiding cover where you can specify exact amounts of fluid in the filter to be operated upon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FluidStack to FluidStack match is handled by FluidStack#isFluidEqual
. Those two CommonFluidFilters#matchesFluid
are just methods that simulates FluidStack#isFluidEqual
without needing to create new FluidStack.
Also FluidStack#isFluidEqual
doesn't check the amount of fluid, so if you want to match the amount of fluid you would need to create custom implementation of IFilter
that calls a different match function.
* @param fluidStack Fluid stack to search index | ||
* @return Index corresponding to tank at {@link #getFluidTanks()} with matching | ||
*/ | ||
default int getIndexOfFluid(@Nullable FluidStack fluidStack) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would also have been an issue with the old implementation, but if allowSameFluidFill
is true, couldn't the passed in fluid be in multiple slots?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method was a part of NotifiableFluidTankFromList
jank and can be removed, but I chose to keep it in. Still, this method is never called outside of that specific class. Also the contract of the method is not particularily associated to insertion logic so I don't think it's a problem.
/** | ||
* @return {@code false} if insertion to this fluid handler enforces input to be | ||
* filled in one slot at max. {@code true} if it bypasses the rule. | ||
*/ | ||
boolean allowSameFluidFill(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we rename this? This is one of the method names from CE that I really don't like, and doesn't really match well with the javadoc of its implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b...but compatbilty 🥺
I guess we could just make a new method and link this method to the new one, but I don't have any strong idea for a new name so feel free to suggest some.
Could you add a |
The javadoc tag |
# Conflicts: # src/main/java/gregtech/api/unification/material/properties/FluidPipeProperties.java # src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityDrum.java
Using jetbrains annotations when 😔 |
What
This PR rewrites
FluidTankList
andOverlayedFluidHandler
for a much cleaner implementation with new algorithm fully covered by unit tests.Implementation Details
Although previous iteration of
FluidTankList
allowed creation of nested tank lists (FluidTankList inside FluidTankList), it didn't handle it correctly - specifically, differingallowSameFluidFill
flag between parent and children. This led to creation of an abomination with a name ofNotifiableFluidTankFromList
, which was an extremely hacky solution to retain the parentIMultipleTankHandler
and handleallowSameFluidFill
setting manually during insertion calls. This questionable design decision then propagated toOverlayedFluidHandler
which gave birth to per-fluid tank cache of distinct fluids.In this PR,
IMultipleTankHandler
received a major redesign to accommodate behavior of nestedFluidTankList
s, and provide better API for usage. The insertion algorithm ofFluidTankList
was changed to handle nested tanks.OverlayedFluidHandler
, or rather a simulator for consecutive fill operations onIMultipleTankHandler
, also received a major refactor. One notable change in API perspective is that theinsertStackedFluidKey
no longer receivesFluidKey
s. Since the algorithm can handle consecutive fill of same fluids now, it is possible to fillFluidStack
s without worrying about redundant entry breaking recipe checks. As a result, usage ofGTHashMaps#fromFluidCollection
got completely phased out.Since handling of nested tanks is no longer needed, implementation of
MetaTileEntityMultiFluidHatch
was changed to use standardNotifiableFluidTank
s. I didn't test it yet. I just assumed it works flawlessly. 😃NotifiableFluidTankFromList
was marked as deprecated.Test cases cover all insertion/extraction logic in both
FluidTankList
andOverlayedFluidHandler
.Additional Information
The distinct insertion logic of
FluidTankList
andOverlayedFluidHandler
has a behavior change:Distinct insertion on second iteration is unchanged.
Serialization result of FluidTankLists have a minor change of
TankAmount
field being removed. As the information was redundant in reading the contents of list tag, I just removed the field.Potential Compatibility Issues
As all of the classes except multi fluid hatches are API, this PR is API breaking change. The actual severity of compat break depends on its usage.
FluidTankList
, like instantiation or callingIFluidHandler
methods, should remain unharmed.OverlayedFluidHandler
should also remain.FluidTankList#getFluidTanks()
still works I think. At least on code it works. Not sure about binary compat.FluidTankList#getTankAt()
should retain their functions; but any instance-specific operations, like casting the object or instance checking with refeq will need updates.FluidTankList#getFluidTanks()
in a field with type ofList<IFluidTank>
will produce compilation error on code, due to how generics work. I think it's fine on binary.OverlayedFluidHandler#insertStackedFluidKey
will break after update.FluidTankList#validateTankIndex()
no longer exists; although I don't think anyone actually uses the method, it is technically an API break.