Fix solar panel loading NPE

This commit is contained in:
drcrazy 2019-07-26 15:12:47 +03:00
parent f28462a9e6
commit d76d637781

View file

@ -57,8 +57,19 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
public boolean isSunOut() { public boolean isSunOut() {
return canSeeSky && !world.isRaining() && !world.isThundering() && world.isDaylight(); 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 @Override
public void tick() { public void tick() {
super.tick(); super.tick();
@ -150,20 +161,12 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
super.fromTag(tag); super.fromTag(tag);
} }
// TileMachineBase // MachineBaseBlockEntity
@Override @Override
public void onLoad() { public void onLoad() {
super.onLoad(); super.onLoad();
updatePanel(); updatePanel();
} }
private void updatePanel(){
Block panelBlock = world.getBlockState(pos).getBlock();
if (panelBlock instanceof BlockSolarPanel) {
BlockSolarPanel solarPanelBlock = (BlockSolarPanel) panelBlock;
panel = solarPanelBlock.panelType;
}
}
// IToolDrop // IToolDrop
@Override @Override