From 16991c2ce816d7ad4e11a411a6bf440093dc4d55 Mon Sep 17 00:00:00 2001 From: Snownee Date: Sun, 7 Feb 2021 15:49:25 +0800 Subject: [PATCH] Fix NPE while deployer on a contraption trying to disassemble self --- .../AbstractContraptionEntity.java | 19 +++++++++++++++++-- .../foundation/utility/NBTProcessors.java | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java index c863f4372..4d3a67406 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/AbstractContraptionEntity.java @@ -58,6 +58,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit protected Contraption contraption; protected boolean initialized; private boolean prevPosInvalid; + private boolean ticking; public AbstractContraptionEntity(EntityType entityTypeIn, World worldIn) { super(entityTypeIn, worldIn); @@ -245,6 +246,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit if (!world.isRemote) contraption.stalled = false; + ticking = true; for (MutablePair pair : contraption.getActors()) { MovementContext context = pair.right; BlockInfo blockInfo = pair.left; @@ -264,13 +266,25 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit continue; if (newPosVisited && !context.stall) { actor.visitNewPosition(context, gridPosition); + if (!isAlive()) + break; context.firstMovement = false; } - if (!oldMotion.equals(context.motion)) + if (!oldMotion.equals(context.motion)) { actor.onSpeedChanged(context, oldMotion, context.motion); + if (!isAlive()) + break; + } actor.tick(context); + if (!isAlive()) + break; contraption.stalled |= context.stall; } + if (!isAlive()) { + contraption.stop(world); + return; + } + ticking = false; for (Entity entity : getPassengers()) { if (!(entity instanceof OrientedContraptionEntity)) @@ -444,7 +458,8 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit @Override public void remove(boolean keepData) { if (!world.isRemote && !removed && contraption != null) { - contraption.stop(world); + if (!ticking) + contraption.stop(world); } super.remove(keepData); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java index 1524913fb..4cbf86483 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java @@ -59,7 +59,7 @@ public final class NBTProcessors { TileEntityType type = tileEntity.getType(); if (survival && survivalProcessors.containsKey(type)) compound = survivalProcessors.get(type).apply(compound); - if (processors.containsKey(type)) + if (compound != null && processors.containsKey(type)) return processors.get(type).apply(compound); if (tileEntity.onlyOpsCanSetNbt()) return null;