SuperMartijn642's Core Lib

SuperMartijn642's Core Lib

82M Downloads

[Bug] 1.18 does not use `BlockEntity.save()` like it used to..

EwyBoy opened this issue ยท 3 comments

commented

Version Info

  • Minecraft: 1.18
  • Core Lib: latest 1.18

@Override
public CompoundTag save(CompoundTag compound){
super.save(compound);
CompoundTag data = this.writeData();
if(data != null && !data.isEmpty())
compound.put("data", data);
return compound;
}

Description of the Bug
See #3 Tanks do not retain fluid after saving world

commented

Using BlockEntity#saveAdditional instead of BlockEntity#save seems to do the trick for me.
That also appears to be the way vanilla BlockEntity's save their data.

Apart from that, just be sure to call BlockEntity#setChanged. If it's not called, the world thinks the chunk hasn't changed and thus it isn't "rewritten" to disk.
This would match your explanation as placing another block would cause the chunk to be saved again, thus the first tank would be saved when the second tank is placed and the second tank does not get saved.

commented

Thank you I will give this a try.

commented

That seems to do the trick. Thank you!
Closing this now.