Fix NPE while deployer on a contraption trying to disassemble self

This commit is contained in:
Snownee 2021-02-07 15:49:25 +08:00
parent b76782364d
commit 16991c2ce8
2 changed files with 18 additions and 3 deletions

View File

@ -58,6 +58,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
protected Contraption contraption; protected Contraption contraption;
protected boolean initialized; protected boolean initialized;
private boolean prevPosInvalid; private boolean prevPosInvalid;
private boolean ticking;
public AbstractContraptionEntity(EntityType<?> entityTypeIn, World worldIn) { public AbstractContraptionEntity(EntityType<?> entityTypeIn, World worldIn) {
super(entityTypeIn, worldIn); super(entityTypeIn, worldIn);
@ -245,6 +246,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
if (!world.isRemote) if (!world.isRemote)
contraption.stalled = false; contraption.stalled = false;
ticking = true;
for (MutablePair<BlockInfo, MovementContext> pair : contraption.getActors()) { for (MutablePair<BlockInfo, MovementContext> pair : contraption.getActors()) {
MovementContext context = pair.right; MovementContext context = pair.right;
BlockInfo blockInfo = pair.left; BlockInfo blockInfo = pair.left;
@ -264,13 +266,25 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
continue; continue;
if (newPosVisited && !context.stall) { if (newPosVisited && !context.stall) {
actor.visitNewPosition(context, gridPosition); actor.visitNewPosition(context, gridPosition);
if (!isAlive())
break;
context.firstMovement = false; context.firstMovement = false;
} }
if (!oldMotion.equals(context.motion)) if (!oldMotion.equals(context.motion)) {
actor.onSpeedChanged(context, oldMotion, context.motion); actor.onSpeedChanged(context, oldMotion, context.motion);
if (!isAlive())
break;
}
actor.tick(context); actor.tick(context);
if (!isAlive())
break;
contraption.stalled |= context.stall; contraption.stalled |= context.stall;
} }
if (!isAlive()) {
contraption.stop(world);
return;
}
ticking = false;
for (Entity entity : getPassengers()) { for (Entity entity : getPassengers()) {
if (!(entity instanceof OrientedContraptionEntity)) if (!(entity instanceof OrientedContraptionEntity))
@ -444,7 +458,8 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
@Override @Override
public void remove(boolean keepData) { public void remove(boolean keepData) {
if (!world.isRemote && !removed && contraption != null) { if (!world.isRemote && !removed && contraption != null) {
contraption.stop(world); if (!ticking)
contraption.stop(world);
} }
super.remove(keepData); super.remove(keepData);
} }

View File

@ -59,7 +59,7 @@ public final class NBTProcessors {
TileEntityType<?> type = tileEntity.getType(); TileEntityType<?> type = tileEntity.getType();
if (survival && survivalProcessors.containsKey(type)) if (survival && survivalProcessors.containsKey(type))
compound = survivalProcessors.get(type).apply(compound); compound = survivalProcessors.get(type).apply(compound);
if (processors.containsKey(type)) if (compound != null && processors.containsKey(type))
return processors.get(type).apply(compound); return processors.get(type).apply(compound);
if (tileEntity.onlyOpsCanSetNbt()) if (tileEntity.onlyOpsCanSetNbt())
return null; return null;