From 3f41c5e8f80cb962606b137e76ff57807760d887 Mon Sep 17 00:00:00 2001 From: Teteros <5067989+Teteros@users.noreply.github.com> Date: Tue, 4 Nov 2025 20:39:04 +0000 Subject: [PATCH] Add null guards to BlockUtil reflections to prevent NullPointerExceptions (#103) Co-authored-by: Teteros Co-authored-by: Martin Robertz --- src/main/java/forestry/core/utils/BlockUtil.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/forestry/core/utils/BlockUtil.java b/src/main/java/forestry/core/utils/BlockUtil.java index 499906020..48e5be626 100644 --- a/src/main/java/forestry/core/utils/BlockUtil.java +++ b/src/main/java/forestry/core/utils/BlockUtil.java @@ -235,7 +235,7 @@ public abstract class BlockUtil { private static Class GTBlockMachines_Class; private static Block GTBlockMachines; private static final boolean bw = Loader.isModLoaded("bartworks"); - private static final boolean gt = Loader.isModLoaded("gregtech"); + private static final boolean gt = Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi"); static { if (bw) try { @@ -268,11 +268,13 @@ public abstract class BlockUtil { } while (stillInside.test(tile)); block = world.getBlock(x, y - depth, z); - if (bw && BW_MetaGenerated_WerkstoffBlocksClass.isInstance(block)) { + if (bw && BW_MetaGenerated_WerkstoffBlocksClass != null + && BWBlocks != null + && BW_MetaGenerated_WerkstoffBlocksClass.isInstance(block)) { return new ItemStack(BWBlocks, 1, block.getDamageValue(world, x, y - depth, z)); } - if (gt && GTBlockMachines_Class.isInstance(block)) { + if (gt && GTBlockMachines_Class != null && GTBlockMachines != null && GTBlockMachines_Class.isInstance(block)) { return new ItemStack(GTBlockMachines, 1, block.getDamageValue(world, x, y - depth, z)); }