In short, the NBT data of a tile entity isn't being loaded properly.
I've been messing with making a generator block which generates energy if given a certain type of fuel. That actual process of burning an item to generate power works fine, and it's saved to the tile entity fine too. I can burn something, exit the UI, reopen and everything is as it should be.
When I leave the game, the NBT data appears to be saved correctly too, because I added a debug print upon writing NBT data that outputs the current energy value. Having burned one item, this is always non-zero (as it should be).
If I rejoin the game though, I get various outputs. I also added a debug print when loading NBT data to output NBT data, but while the game is loading, it's called various times. I've added an output log in the spoiler below, so you can see exactly when the value is reset.
Output log:
TileEntityRubyGenerator:
CustomEnergyStorage:
If relevant, ContainerRubyGenerator:
BlockTileEntity, which is essentially what the block class is of the ruby generator:
If anyone knows what causes this odd behaviour, please let me know. If I've forgotten to share the necessary information to debug this issue, my apologies. I'm quite new to this scene.