From 0bd52347f97a60fa2eb434ca3613093cc11e20a4 Mon Sep 17 00:00:00 2001 From: TechLord22 <37029404+TechLord22@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:46:25 -0500 Subject: [PATCH] only access worldpipenet on server (#2310) --- .../gregtech/api/pipenet/WorldPipeNet.java | 21 +++++++++++++++---- .../api/pipenet/tile/TileEntityPipeBase.java | 10 +++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/gregtech/api/pipenet/WorldPipeNet.java b/src/main/java/gregtech/api/pipenet/WorldPipeNet.java index 23860461888..03211cc377c 100644 --- a/src/main/java/gregtech/api/pipenet/WorldPipeNet.java +++ b/src/main/java/gregtech/api/pipenet/WorldPipeNet.java @@ -1,5 +1,7 @@ package gregtech.api.pipenet; +import gregtech.api.util.GTLog; + import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumFacing; @@ -12,7 +14,11 @@ import org.jetbrains.annotations.NotNull; import java.lang.ref.WeakReference; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public abstract class WorldPipeNet> extends WorldSavedData { @@ -35,9 +41,16 @@ protected void setWorldAndInit(World world) { } } - public static String getDataID(final String baseID, final World world) { - if (world == null || world.isRemote) - throw new RuntimeException("WorldPipeNet should only be created on the server!"); + public static @NotNull String getDataID(@NotNull final String baseID, @NotNull final World world) { + // noinspection ConstantValue + if (world == null || world.isRemote) { + GTLog.logger.error("WorldPipeNet should only be created on the server!", new Throwable()); + // noinspection ConstantValue + if (world == null) { + return baseID; + } + } + int dimension = world.provider.getDimension(); return dimension == 0 ? baseID : baseID + '.' + dimension; } diff --git a/src/main/java/gregtech/api/pipenet/tile/TileEntityPipeBase.java b/src/main/java/gregtech/api/pipenet/tile/TileEntityPipeBase.java index b1ec074d9d6..84897a022e8 100644 --- a/src/main/java/gregtech/api/pipenet/tile/TileEntityPipeBase.java +++ b/src/main/java/gregtech/api/pipenet/tile/TileEntityPipeBase.java @@ -544,10 +544,12 @@ public boolean shouldRefresh(@NotNull World world, @NotNull BlockPos pos, IBlock @Override public void onChunkUnload() { super.onChunkUnload(); - WorldPipeNet worldPipeNet = getPipeBlock().getWorldPipeNet(getWorld()); - PipeNet net = worldPipeNet.getNetFromPos(pos); - if (net != null) { - net.onChunkUnload(); + if (!world.isRemote) { + WorldPipeNet worldPipeNet = getPipeBlock().getWorldPipeNet(getWorld()); + PipeNet net = worldPipeNet.getNetFromPos(pos); + if (net != null) { + net.onChunkUnload(); + } } }