Skip to content

Commit b5ddb56

Browse files
TechLord22serenibyss
authored andcommitted
only access worldpipenet on server (#2310)
1 parent 2bc744b commit b5ddb56

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/main/java/gregtech/api/pipenet/WorldPipeNet.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package gregtech.api.pipenet;
22

3+
import gregtech.api.util.GTLog;
4+
35
import net.minecraft.nbt.NBTTagCompound;
46
import net.minecraft.nbt.NBTTagList;
57
import net.minecraft.util.EnumFacing;
@@ -12,7 +14,11 @@
1214
import org.jetbrains.annotations.NotNull;
1315

1416
import java.lang.ref.WeakReference;
15-
import java.util.*;
17+
import java.util.ArrayList;
18+
import java.util.Collections;
19+
import java.util.HashMap;
20+
import java.util.List;
21+
import java.util.Map;
1622

1723
public abstract class WorldPipeNet<NodeDataType, T extends PipeNet<NodeDataType>> extends WorldSavedData {
1824

@@ -35,9 +41,16 @@ protected void setWorldAndInit(World world) {
3541
}
3642
}
3743

38-
public static String getDataID(final String baseID, final World world) {
39-
if (world == null || world.isRemote)
40-
throw new RuntimeException("WorldPipeNet should only be created on the server!");
44+
public static @NotNull String getDataID(@NotNull final String baseID, @NotNull final World world) {
45+
// noinspection ConstantValue
46+
if (world == null || world.isRemote) {
47+
GTLog.logger.error("WorldPipeNet should only be created on the server!", new Throwable());
48+
// noinspection ConstantValue
49+
if (world == null) {
50+
return baseID;
51+
}
52+
}
53+
4154
int dimension = world.provider.getDimension();
4255
return dimension == 0 ? baseID : baseID + '.' + dimension;
4356
}

src/main/java/gregtech/api/pipenet/tile/TileEntityPipeBase.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,12 @@ public boolean shouldRefresh(@NotNull World world, @NotNull BlockPos pos, IBlock
544544
@Override
545545
public void onChunkUnload() {
546546
super.onChunkUnload();
547-
WorldPipeNet<?, ?> worldPipeNet = getPipeBlock().getWorldPipeNet(getWorld());
548-
PipeNet<?> net = worldPipeNet.getNetFromPos(pos);
549-
if (net != null) {
550-
net.onChunkUnload();
547+
if (!world.isRemote) {
548+
WorldPipeNet<?, ?> worldPipeNet = getPipeBlock().getWorldPipeNet(getWorld());
549+
PipeNet<?> net = worldPipeNet.getNetFromPos(pos);
550+
if (net != null) {
551+
net.onChunkUnload();
552+
}
551553
}
552554
}
553555

0 commit comments

Comments
 (0)