From 7436ceb209ed53df82c366f96297b6a895c16e60 Mon Sep 17 00:00:00 2001 From: Snownee Date: Sun, 31 Jan 2021 19:24:44 +0800 Subject: [PATCH] Fix stabilized contraption moving bearing block --- .../components/structureMovement/Contraption.java | 4 ++-- .../structureMovement/TranslatingContraption.java | 3 +-- .../structureMovement/bearing/BearingContraption.java | 7 ++++--- .../structureMovement/bearing/ClockworkContraption.java | 9 +++++---- .../bearing/StabilizedBearingMovementBehaviour.java | 2 +- .../structureMovement/bearing/StabilizedContraption.java | 2 +- .../structureMovement/mounted/MountedContraption.java | 2 +- 7 files changed, 15 insertions(+), 14 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 bb4dadb7f..54bab2c8d 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 @@ -135,7 +135,7 @@ public abstract class Contraption { public abstract boolean assemble(World world, BlockPos pos); - protected abstract boolean canAxisBeStabilized(Axis axis); + public abstract boolean canBeStabilized(Direction facing, BlockPos localPos); protected abstract AllContraptionTypes getType(); @@ -338,7 +338,7 @@ public abstract class Contraption { private void moveBearing(BlockPos pos, List frontier, Set visited, BlockState state) { Direction facing = state.get(MechanicalBearingBlock.FACING); - if (!canAxisBeStabilized(facing.getAxis())) { + if (!canBeStabilized(facing, pos.subtract(anchor))) { BlockPos offset = pos.offset(facing); if (!visited.contains(offset)) frontier.add(offset); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/TranslatingContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/TranslatingContraption.java index 7e473df3b..9d889227b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/TranslatingContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/TranslatingContraption.java @@ -5,7 +5,6 @@ import java.util.HashSet; import java.util.Set; import net.minecraft.util.Direction; -import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template.BlockInfo; @@ -48,7 +47,7 @@ public abstract class TranslatingContraption extends Contraption { } @Override - protected boolean canAxisBeStabilized(Axis axis) { + public boolean canBeStabilized(Direction facing, BlockPos localPos) { return false; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java index 76db5bd8b..9559d8c90 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingContraption.java @@ -9,7 +9,6 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; -import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template.BlockInfo; @@ -84,8 +83,10 @@ public class BearingContraption extends Contraption { } @Override - protected boolean canAxisBeStabilized(Axis axis) { - return axis == facing.getAxis(); + public boolean canBeStabilized(Direction facing, BlockPos localPos) { + if (facing.getOpposite() == this.facing && BlockPos.ZERO.equals(localPos)) + return false; + return facing.getAxis() == this.facing.getAxis(); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java index 31b7709f3..ee625cc63 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/ClockworkContraption.java @@ -12,7 +12,6 @@ import com.simibubi.create.foundation.utility.NBTHelper; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; -import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -110,15 +109,17 @@ public class ClockworkContraption extends Contraption { @Override public void readNBT(World world, CompoundNBT tag, boolean spawnData) { - facing = Direction.byIndex(tag.getInt("Facing")); + facing = Direction.byIndex(tag.getInt("facing")); handType = NBTHelper.readEnum(tag, "HandType", HandType.class); offset = tag.getInt("offset"); super.readNBT(world, tag, spawnData); } @Override - protected boolean canAxisBeStabilized(Axis axis) { - return axis == facing.getAxis(); + public boolean canBeStabilized(Direction facing, BlockPos localPos) { + if (BlockPos.ZERO.equals(localPos) || BlockPos.ZERO.equals(localPos.offset(facing))) + return false; + return facing.getAxis() == this.facing.getAxis(); } public static enum HandType { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index 35df5d517..3bec0cedf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -45,7 +45,7 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour { AbstractContraptionEntity entity = context.contraption.entity; if (entity instanceof ControlledContraptionEntity) { ControlledContraptionEntity controlledCE = (ControlledContraptionEntity) entity; - if (controlledCE.getRotationAxis() == axis) + if (context.contraption.canBeStabilized(facing, context.localPos)) offset = -controlledCE.getAngle(renderPartialTicks); } else if (entity instanceof OrientedContraptionEntity) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java index f54d09beb..a6b3ec837 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedContraption.java @@ -55,7 +55,7 @@ public class StabilizedContraption extends Contraption { } @Override - protected boolean canAxisBeStabilized(Axis axis) { + public boolean canBeStabilized(Direction facing, BlockPos localPos) { return false; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java index 3d6a28dd8..8846e24b0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MountedContraption.java @@ -149,7 +149,7 @@ public class MountedContraption extends Contraption { } @Override - protected boolean canAxisBeStabilized(Axis axis) { + public boolean canBeStabilized(Direction facing, BlockPos localPos) { return true; }