From 761b43999763436b1243a40f889a6c73e228a778 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Dec 2022 16:04:49 +0100 Subject: [PATCH] Catch crash for block state desync. #3424 Could be in some other places as well but let's see what this does. --- .../apiimpl/network/node/NetworkNode.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/NetworkNode.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/NetworkNode.java index 5de1057ff..53f1e43af 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/NetworkNode.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/network/node/NetworkNode.java @@ -18,13 +18,18 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraftforge.items.IItemHandler; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.UUID; public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor { + private static final Logger LOGGER = LogManager.getLogger(); + private static final String NBT_OWNER = "Owner"; private static final String NBT_VERSION = "Version"; private static final int CURRENT_VERSION = 1; @@ -256,8 +261,15 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor { if (direction == null) { BlockState state = level.getBlockState(pos); - if (state.getBlock() instanceof BaseBlock) { - direction = state.getValue(((BaseBlock) state.getBlock()).getDirection().getProperty()); + if (state.getBlock() instanceof BaseBlock baseBlock) { + DirectionProperty property = baseBlock.getDirection().getProperty(); + + if (state.hasProperty(property)) { + direction = state.getValue(property); + } else { + LOGGER.warn("Node @ {} has no direction! Consider recreating the block", pos); + return Direction.NORTH; + } } }