Reborn Core is a library used for many of the Tech Reborn team's mods, including Tech Reborn, Quantum Storage, Fluxed Redstone, Hardcore Map Reset, and many more.
MIT License
44
stars
51
forks
source link
MachineBaseBlockEntity: Don't rely on getTank() being non-null #150
This fixes FluidConfiguration not surviving a server restart.
Every machine block subclass with a tank calls super.fromTag()
first before doing its own deserialization, however only after
the subclass fromTag() code has run, can a Tank instance possibly
be instantiated. This means that getTank() != null in
MachineBaseBlockEntity#fromTag will always evaluate to false.
For loading the FluidConfiguration however we don't have to care
about the tank instance, because a subclass without tank would
never have resulted in a FluidConfiguration being written to
the NBT in the first place. In case a tank does exist but the
NBT contains no FluidConfiguration, #onLoad will take care of
creating a default instance.
I was considering a couple different approaches, including having subclasses of MachineBaseBlockEntity "statically" communicate whether they are tank-bearing (via a simple overridden bool method), but I think ultimately this is the least invasive approach.
Server restart is basically the same as saving and later loading the game in single player, so if you always played in multiplayer, you would hardly run into this problem.
This fixes FluidConfiguration not surviving a server restart.
Every machine block subclass with a tank calls
super.fromTag()
first before doing its own deserialization, however only after the subclassfromTag()
code has run, can a Tank instance possibly be instantiated. This means thatgetTank() != null
inMachineBaseBlockEntity#fromTag
will always evaluate to false.For loading the
FluidConfiguration
however we don't have to care about the tank instance, because a subclass without tank would never have resulted in aFluidConfiguration
being written to the NBT in the first place. In case a tank does exist but the NBT contains noFluidConfiguration
,#onLoad
will take care of creating a default instance.I was considering a couple different approaches, including having subclasses of MachineBaseBlockEntity "statically" communicate whether they are tank-bearing (via a simple overridden bool method), but I think ultimately this is the least invasive approach.
Server restart is basically the same as saving and later loading the game in single player, so if you always played in multiplayer, you would hardly run into this problem.