From d6e8ac73df0b11137785ce1498b0d91dbb5148fb Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sun, 11 Dec 2022 21:31:11 +0100 Subject: [PATCH] Bad Acting - Fixed crash when loading contraptions with missing blocks which had provided movement behaviours --- .../structureMovement/Contraption.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index 19f88448c..1133742ea 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -744,10 +744,12 @@ public abstract class Contraption { ListTag actorsNBT = new ListTag(); for (MutablePair 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 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 callBack) { - for (MutablePair pair : actors) - callBack.accept(AllMovementBehaviours.getBehaviour(pair.getLeft().state), pair.getRight()); + for (MutablePair pair : actors) { + MovementBehaviour behaviour = AllMovementBehaviours.getBehaviour(pair.getLeft().state); + if (behaviour == null) + continue; + callBack.accept(behaviour, pair.getRight()); + } } protected boolean shouldUpdateAfterMovement(StructureBlockInfo info) {