Dremoline / PortableTanks

1 stars 0 forks source link

[Bug] Tanks do not retain fluid after saving world. #3

Closed EwyBoy closed 2 years ago

EwyBoy commented 2 years ago

Version info Minecraft 1.18 Portable Tanks portabletanks-1.1.2-mc1.18

Describe the bug Hello, I am currently working on my tank mod ITank for 1.18 and I have this bug here where my fluid is not stored in the tank upon saving and exiting the world. This is due to the new save system in Minecraft. You know have to override and use saveAdditional(). Like:

@Override
protected void saveAdditional(CompoundTag tag) {
      // save() code here..
}

But I also have some problems with the new saveAdditional(). That is that it does not run upon saving the world.. WTF It only loads when sometimes if you place first 1 tank down and fill that up and then place another tank and fill that one. Then it will run on the first tank you placed on save that to disk but when you log back in the second tank you placed will be empty while the first tank will be filled.

Been tearing my hair out about this bug for hours now, then I saw you guys released a tank mod for 1.18 so I though I check it out how you guys did it. Looked at the source code for the library mod and saw you where only using the regular save() and though maybe you got it working in some weird way. So downloaded the mod from CF and ran it and indeed you got the exact same bug as me. Decided to report it here and maybe we can work together to find a solution to this. Not sure if there is a good way of implementing this or if it needs to be fixed on forges end.

Gigaherz pinned this message in the forge discord:

Some notes about BlockEntity saving: 1.18 doesn't really use save() in the same way older versions used to. If you continue overriding save, it will not work. Instead, you should override saveAdditional. If you are storing BlockEntities somewhere, don't call save. Call saveWithFullMetadata(), saveWithId() or saveWithoutMetadata(), depending on your needs.

and we (Mowmaster and me) found out that this is the order things compound tags are saved and loaded:

* load()
* saveAdditional()
* getUpdateTag()
* load()
* saveAdditional()
* then if i exit the world it wont save again(assuming its because it just did?)
* but if i exit the area it'll fire saveAdditional() 

To Reproduce

  1. Place tank on ground
  2. Fill it up with any liquid
  3. Press ESC
  4. Press Save & Exit
  5. Select the world and join back in
  6. There is no more water in the tank.

What do you think? Please keep me posted if you need any more info on this subject and if you can work out a reliable solution. Not sure if I have just botched the implementation for this or if we need to create a issue over at Minecraft Forge.

BTW: here is my source for 1.18 tank block entity, I still cannot get it to reliably save for me.. https://github.com/EwyBoy/ITank/blob/1.18/src/main/java/com/ewyboy/itank/common/content/tank/TankTile.java

EwyBoy commented 2 years ago

Problem is here in SuperMartijn642sCoreLib.BaseTileEntity.save() https://github.com/SuperMartijn642/SuperMartijn642sCoreLib/blob/56d1c373f2b351438133e74880226b55b26564c7/src/main/java/com/supermartijn642/core/block/BaseTileEntity.java#L63-L70

SuperMartijn642 commented 2 years ago

This has been fixed now in version 1.0.15a of my core library.

I have created a pull request to remove BlockEntity#save(CompoundTag). If that works out, it hopefully causes less confusion in the future. https://github.com/MinecraftForge/MinecraftForge/pull/8235

Thank you for reporting the issue!