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