Skip to content

Commit

Permalink
only access worldpipenet on server (#2310)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 committed Dec 18, 2023
1 parent e54bb80 commit 0bd5234
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/main/java/gregtech/api/pipenet/WorldPipeNet.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<NodeDataType, T extends PipeNet<NodeDataType>> extends WorldSavedData {

Expand All @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/gregtech/api/pipenet/tile/TileEntityPipeBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down

0 comments on commit 0bd5234

Please sign in to comment.