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

@ -58,7 +58,18 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
return canSeeSky && !world.isRaining() && !world.isThundering() && world.isDaylight(); return canSeeSky && !world.isRaining() && !world.isThundering() && world.isDaylight();
} }
// TilePowerAcceptor private void updatePanel(){
if (world == null) {
return;
}
Block panelBlock = world.getBlockState(pos).getBlock();
if (panelBlock instanceof BlockSolarPanel) {
BlockSolarPanel solarPanelBlock = (BlockSolarPanel) panelBlock;
panel = solarPanelBlock.panelType;
}
}
// PowerAcceptorBlockEntity
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
@ -150,21 +161,13 @@ 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
public ItemStack getToolDrop(final PlayerEntity playerIn) { public ItemStack getToolDrop(final PlayerEntity playerIn) {