GregTechCE / GregTech

GregTech rewrite for modern versions of Minecraft
GNU Lesser General Public License v3.0
269 stars 149 forks source link

[BUG] Does not save pipe buffer #1357

Open eve0415 opened 3 years ago

eve0415 commented 3 years ago

Describe the bug When the server restarted / reloading the world or chunk, the pipe buffer gets empty.

This make it hard for people like me when you are using steam boiler, with two pipes (In: water from pump, Out: steam) When I reload the world (entering the game), the pipe buffer get empty resulting back-flow of steam where it should be water.

Versions Forge: forge-14.23.5.2854 GTCE: Modpack: ArchitPack Greg Modified:

  1. Remove GTCE Bees & Greg's Construct & Shadows of Greg.
  2. Update GregTech Community Edition & gtce2oc to the latest version.

Setup Played both, multiplayer and solo.

Steps To Reproduce 1) Place some pipes. 2) Input something (steam, water, can be anything I hope). 3) Remove the source of input (just make the pipe alone with full of liquid). 4) Re-enter the world (solo) or restart the server. 5) See empty pipes which was full before re-entering.

Expected behavior The pipe's buffer should not be empty when reloading the chunks/world.

Screenshots Before: image After: image

warjort commented 3 years ago

Looking at the code, the fluid in the pipes is never persisted.

This is a simple patch that fixes the immediate problem, by storing the FluidNetTank in the world saved data: ''' diff --git a/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidPipeNet.java b/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidPipeNet.java old mode 100644 new mode 100755 index db8cb1be..e70d8955 --- a/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidPipeNet.java +++ b/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidPipeNet.java @@ -154,4 +154,19 @@ public class FluidPipeNet extends MonolithicPipeNet { return new FluidPipeProperties(maxTemperature, throughput, gasProof); }

This fixes the immediate problem for single player and on the server.

But the client will always see the wrong amounts in the pipes since there is no mechanism to synchronize the FluidNetTank between the server and client.

If the client has TOP like in the above image, they will still see an empty pipe after relogging or unloading chunks, etc. But connecting it to a tank will magically make the missing fluid reappear when the tank is filled on the server and resyncs with the client.

This is still better than what happens now, which is the fluid disappearing into the void when restarting single player or the server.

warjort commented 3 years ago

Better formatted patch?

diff --git a/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidPipeNet.java b/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidPipeNet.java
old mode 100644
new mode 100755
index db8cb1be..e70d8955
--- a/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidPipeNet.java
+++ b/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidPipeNet.java
@@ -154,4 +154,19 @@ public class FluidPipeNet extends MonolithicPipeNet<FluidPipeProperties> {
         return new FluidPipeProperties(maxTemperature, throughput, gasProof);
     }

+    @Override
+    public NBTTagCompound serializeNBT() {
+        final NBTTagCompound nbt = super.serializeNBT();
+        nbt.setTag("FluidNetTank", this.fluidNetTank.writeToNBT(new NBTTagCompound()));
+        return nbt;
+    }
+
+    @Override
+    public void deserializeNBT(final NBTTagCompound nbt) {
+        super.deserializeNBT(nbt);
+        final NBTTagCompound tankData = nbt.getCompoundTag("FluidNetTank");
+        if (tankData != null)
+            this.fluidNetTank.readFromNBT(tankData);
+    }
+
 }
LAGIdiot commented 3 years ago

Accepted based on provided information and current code.

@warjort Seems like you already try fixing it. Why don't you create PR with provided code?

warjort commented 3 years ago

PR seems like a lot of work for a 10 line fix?