From d76d6377814da3b712d41b7c7630e23be08453c9 Mon Sep 17 00:00:00 2001 From: drcrazy Date: Fri, 26 Jul 2019 15:12:47 +0300 Subject: [PATCH] Fix solar panel loading NPE --- .../generator/SolarPanelBlockEntity.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/techreborn/blockentity/generator/SolarPanelBlockEntity.java b/src/main/java/techreborn/blockentity/generator/SolarPanelBlockEntity.java index 4411edbd6..9f96904db 100644 --- a/src/main/java/techreborn/blockentity/generator/SolarPanelBlockEntity.java +++ b/src/main/java/techreborn/blockentity/generator/SolarPanelBlockEntity.java @@ -57,8 +57,19 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I public boolean isSunOut() { return canSeeSky && !world.isRaining() && !world.isThundering() && world.isDaylight(); } + + private void updatePanel(){ + if (world == null) { + return; + } + Block panelBlock = world.getBlockState(pos).getBlock(); + if (panelBlock instanceof BlockSolarPanel) { + BlockSolarPanel solarPanelBlock = (BlockSolarPanel) panelBlock; + panel = solarPanelBlock.panelType; + } + } - // TilePowerAcceptor + // PowerAcceptorBlockEntity @Override public void tick() { super.tick(); @@ -150,20 +161,12 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I super.fromTag(tag); } - // TileMachineBase + // MachineBaseBlockEntity @Override public void onLoad() { super.onLoad(); updatePanel(); } - - private void updatePanel(){ - Block panelBlock = world.getBlockState(pos).getBlock(); - if (panelBlock instanceof BlockSolarPanel) { - BlockSolarPanel solarPanelBlock = (BlockSolarPanel) panelBlock; - panel = solarPanelBlock.panelType; - } - } // IToolDrop @Override