From 077f54a506b1cfc0c48d190bc23c6bebed2f049d Mon Sep 17 00:00:00 2001 From: direwolf20 <39863894+Direwolf20-MC@users.noreply.github.com> Date: Sun, 18 Aug 2024 17:07:59 -0400 Subject: [PATCH] Resolve MORE crashes with Hyperbox --- .../common/blockentities/LaserNodeBE.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/direwolf20/laserio/common/blockentities/LaserNodeBE.java b/src/main/java/com/direwolf20/laserio/common/blockentities/LaserNodeBE.java index e9dcb7c0..10a46ccd 100644 --- a/src/main/java/com/direwolf20/laserio/common/blockentities/LaserNodeBE.java +++ b/src/main/java/com/direwolf20/laserio/common/blockentities/LaserNodeBE.java @@ -160,8 +160,11 @@ public List getInserterNodes() { /** This is called by nodes when a connection is added/removed - the other node does the discovery and then tells this one about it **/ public void setOtherNodesInNetwork(Set otherNodesInNetwork) { this.otherNodesInNetwork.clear(); + if (level == null) return; for (GlobalPos pos : otherNodesInNetwork) { - this.otherNodesInNetwork.add(new GlobalPos(MiscTools.getLevel(level.getServer(), pos).dimension(), getRelativePos(pos.pos()))); + Level targetLevel = MiscTools.getLevel(level.getServer(), pos); + if (targetLevel == null) continue; + this.otherNodesInNetwork.add(new GlobalPos(targetLevel.dimension(), getRelativePos(pos.pos()))); } refreshAllInvNodes(); //Seeing as the otherNodes list just got updated, we should refresh the InventoryNode content caches } @@ -354,8 +357,11 @@ public void populateThisRedstoneNetwork(boolean notifyOthers) { public void refreshRedstoneNetwork() { //System.out.println("Updating Redstone Network at: " + getBlockPos() + ", Gametime: " + level.getGameTime()); redstoneNetwork.clear(); + if (level == null) return; for (GlobalPos pos : otherNodesInNetwork) { - LaserNodeBE laserNodeBE = getNodeAt(new GlobalPos(MiscTools.getLevel(level.getServer(), pos).dimension(), getWorldPos(pos.pos()))); + Level targetLevel = MiscTools.getLevel(level.getServer(), pos); + if (targetLevel == null) continue; + LaserNodeBE laserNodeBE = getNodeAt(new GlobalPos(targetLevel.dimension(), getWorldPos(pos.pos()))); if (laserNodeBE == null) continue; for (Map.Entry entry : laserNodeBE.myRedstoneIn.byte2ByteEntrySet()) { updateRedstoneNetwork(entry.getKey(), entry.getValue()); @@ -390,8 +396,11 @@ public void refreshCardsRedstone() { //if (inserterUpdated || extractorUpdated) markDirtyClient(); if (inserterUpdated) { + if (level == null) return; for (GlobalPos pos : otherNodesInNetwork) { - LaserNodeBE node = getNodeAt(new GlobalPos(MiscTools.getLevel(level.getServer(), pos).dimension(), getWorldPos(pos.pos()))); + Level targetLevel = MiscTools.getLevel(level.getServer(), pos); + if (targetLevel == null) continue; + LaserNodeBE node = getNodeAt(new GlobalPos(targetLevel.dimension(), getWorldPos(pos.pos()))); if (node == null) continue; node.checkInvNode(new GlobalPos(this.level.dimension(), this.getBlockPos()), true); } @@ -1992,8 +2001,11 @@ public void updateThisNode() { /** When this node changes, tell other nodes to refresh their cache of it **/ public void notifyOtherNodesOfChange() { + if (level == null) return; for (GlobalPos pos : otherNodesInNetwork) { - LaserNodeBE node = getNodeAt(new GlobalPos(MiscTools.getLevel(level.getServer(), pos).dimension(), getWorldPos(pos.pos()))); + Level targetLevel = MiscTools.getLevel(level.getServer(), pos); + if (targetLevel == null) continue; + LaserNodeBE node = getNodeAt(new GlobalPos(targetLevel.dimension(), getWorldPos(pos.pos()))); if (node == null) continue; node.checkInvNode(new GlobalPos(this.level.dimension(), this.getBlockPos()), true); //node.refreshRedstoneNetwork(); @@ -2012,8 +2024,11 @@ public void refreshAllInvNodes() { channelOnlyCache.clear(); this.stockerDestinationCache.clear(); this.redstoneNetwork.clear(); + if (level == null) return; for (GlobalPos pos : otherNodesInNetwork) { - checkInvNode(new GlobalPos(MiscTools.getLevel(level.getServer(), pos).dimension(), getWorldPos(pos.pos())), false); + Level targetLevel = MiscTools.getLevel(level.getServer(), pos); + if (targetLevel == null) continue; + checkInvNode(new GlobalPos(targetLevel.dimension(), getWorldPos(pos.pos())), false); } //refreshRedstoneNetwork(); redstoneRefreshed = false;