Skip to content

Commit

Permalink
Fix cable unload of already unloaded chunks.
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jul 21, 2024
1 parent e8ca4b2 commit 2379b88
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/owmii/powah/block/cable/CableNet.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.slf4j.LoggerFactory;

public class CableNet {
private static final Logger LOG = LoggerFactory.getLogger(CableNet.class);

// Level -> ChunkPos -> BlockPos -> Tile
private static final Map<Level, Long2ObjectMap<Long2ObjectMap<CableTile>>> loadedCables = new WeakHashMap<>();

Expand All @@ -39,12 +37,19 @@ static void addCable(CableTile cable) {
}

static void removeCable(CableTile cable) {
// No need to repeat this if the cable isn't part of a net anyway
if (cable.net == null) {
return;
}

var levelMap = loadedCables.get(cable.getLevel());
if (levelMap == null) {
return; // The full-chunk cleanup already took care of the entire level
}
var chunkPos = ChunkPos.asLong(cable.getBlockPos());
var chunkMap = levelMap.get(chunkPos);
if (chunkMap == null) {
LOG.error("Ignoring to unload cable @ {} since chunk is already gone.", cable.getBlockPos());
return;
return; // The full-chunk cleanup already took care of the entire chunk
}
if (chunkMap.remove(cable.getBlockPos().asLong()) != cable) {
throw new RuntimeException("Removed wrong cable from position %s".formatted(cable.getBlockPos()));
Expand Down

0 comments on commit 2379b88

Please sign in to comment.