Bad Acting

- Fixed crash when loading contraptions with missing blocks which had provided movement behaviours
This commit is contained in:
simibubi 2022-12-11 21:31:11 +01:00
parent c420048a88
commit d6e8ac73df

View file

@ -744,10 +744,12 @@ public abstract class Contraption {
ListTag actorsNBT = new ListTag();
for (MutablePair<StructureBlockInfo, MovementContext> actor : getActors()) {
MovementBehaviour behaviour = AllMovementBehaviours.getBehaviour(actor.left.state);
if (behaviour == null)
continue;
CompoundTag compound = new CompoundTag();
compound.put("Pos", NbtUtils.writeBlockPos(actor.left.pos));
AllMovementBehaviours.getBehaviour(actor.left.state)
.writeExtraData(actor.right);
behaviour.writeExtraData(actor.right);
actor.right.writeToNBT(compound);
actorsNBT.add(compound);
}
@ -1120,8 +1122,9 @@ public abstract class Contraption {
public void startMoving(Level world) {
for (MutablePair<StructureBlockInfo, MovementContext> pair : actors) {
MovementContext context = new MovementContext(world, pair.left, this);
AllMovementBehaviours.getBehaviour(pair.left.state)
.startMoving(context);
MovementBehaviour behaviour = AllMovementBehaviours.getBehaviour(pair.left.state);
if (behaviour != null)
behaviour.startMoving(context);
pair.setRight(context);
}
}
@ -1137,8 +1140,12 @@ public abstract class Contraption {
}
public void forEachActor(Level world, BiConsumer<MovementBehaviour, MovementContext> callBack) {
for (MutablePair<StructureBlockInfo, MovementContext> pair : actors)
callBack.accept(AllMovementBehaviours.getBehaviour(pair.getLeft().state), pair.getRight());
for (MutablePair<StructureBlockInfo, MovementContext> pair : actors) {
MovementBehaviour behaviour = AllMovementBehaviours.getBehaviour(pair.getLeft().state);
if (behaviour == null)
continue;
callBack.accept(behaviour, pair.getRight());
}
}
protected boolean shouldUpdateAfterMovement(StructureBlockInfo info) {