Lightwell needs to be broken to produce a different fluid
grompe opened this issue ยท 4 comments
Lightwell doesn't produce anything if a catalyst for a different fluid was placed in it without breaking and replacing the Lightwell first. This is unexpected and can especially be a problem when catalyst is a hard to obtain item.
I propose setting the tank to a new liquid type if its amount is zero.
Intentional, because the lightwell is frequently being emptied in most circumstances during use. The tome will be made more clear about this in the future, but thrashing the state via your proposed fix isn't exactly great for performance.
@Doomgull lets consider just how cheap an operation these two methods are:
public void setFluid(@Nullable Fluid fluid) {
boolean update = false;
if (fluid != this.fluid) {
this.amount = 0;
update = true;
}
this.fluid = fluid;
if (update && this.onUpdate != null) {
this.onUpdate.run();
}
}
@Override
public int getFluidAmount() {
return MathHelper.floor(amount);
}
So to check the fluid ammount we have floor(ammount), okay, I get a nice integer back with a method call, the setting up the method stack here is the expensive part, most of the time we don't care about method calls in compsci as they are considered cheap enough.
Okay, lets look at the other one. We create a boolean variable, a single cycle, we check if the fluid is the same as the one already in there via Java object comparison (which will match if fluid is the same), in the case they match, we change the field and then check that boolean then exit. Again, we are looking at cheap, to the point that the method setup and teardown of the stack frame is more expensive.
Ony in the case the fluid actually changes is this doing anything here, there is no NBT save beyond what has happened to set the amount to 0 before we are even in this method, or packet send to send to the client if need be.
I don't mean to reset tank liquid type as soon as its amount reaches zero, but allowing it to accept new type of liquid if it were to generate.