Fix stabilized contraption moving bearing block

This commit is contained in:
Snownee 2021-01-31 19:24:44 +08:00
parent c77e7c28d7
commit 7436ceb209
7 changed files with 15 additions and 14 deletions

View File

@ -135,7 +135,7 @@ public abstract class Contraption {
public abstract boolean assemble(World world, BlockPos pos); 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(); protected abstract AllContraptionTypes getType();
@ -338,7 +338,7 @@ public abstract class Contraption {
private void moveBearing(BlockPos pos, List<BlockPos> frontier, Set<BlockPos> visited, BlockState state) { private void moveBearing(BlockPos pos, List<BlockPos> frontier, Set<BlockPos> visited, BlockState state) {
Direction facing = state.get(MechanicalBearingBlock.FACING); Direction facing = state.get(MechanicalBearingBlock.FACING);
if (!canAxisBeStabilized(facing.getAxis())) { if (!canBeStabilized(facing, pos.subtract(anchor))) {
BlockPos offset = pos.offset(facing); BlockPos offset = pos.offset(facing);
if (!visited.contains(offset)) if (!visited.contains(offset))
frontier.add(offset); frontier.add(offset);

View File

@ -5,7 +5,6 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.gen.feature.template.Template.BlockInfo; import net.minecraft.world.gen.feature.template.Template.BlockInfo;
@ -48,7 +47,7 @@ public abstract class TranslatingContraption extends Contraption {
} }
@Override @Override
protected boolean canAxisBeStabilized(Axis axis) { public boolean canBeStabilized(Direction facing, BlockPos localPos) {
return false; return false;
} }

View File

@ -9,7 +9,6 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.gen.feature.template.Template.BlockInfo; import net.minecraft.world.gen.feature.template.Template.BlockInfo;
@ -84,8 +83,10 @@ public class BearingContraption extends Contraption {
} }
@Override @Override
protected boolean canAxisBeStabilized(Axis axis) { public boolean canBeStabilized(Direction facing, BlockPos localPos) {
return axis == facing.getAxis(); if (facing.getOpposite() == this.facing && BlockPos.ZERO.equals(localPos))
return false;
return facing.getAxis() == this.facing.getAxis();
} }
} }

View File

@ -12,7 +12,6 @@ import com.simibubi.create.foundation.utility.NBTHelper;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -110,15 +109,17 @@ public class ClockworkContraption extends Contraption {
@Override @Override
public void readNBT(World world, CompoundNBT tag, boolean spawnData) { 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); handType = NBTHelper.readEnum(tag, "HandType", HandType.class);
offset = tag.getInt("offset"); offset = tag.getInt("offset");
super.readNBT(world, tag, spawnData); super.readNBT(world, tag, spawnData);
} }
@Override @Override
protected boolean canAxisBeStabilized(Axis axis) { public boolean canBeStabilized(Direction facing, BlockPos localPos) {
return axis == facing.getAxis(); if (BlockPos.ZERO.equals(localPos) || BlockPos.ZERO.equals(localPos.offset(facing)))
return false;
return facing.getAxis() == this.facing.getAxis();
} }
public static enum HandType { public static enum HandType {

View File

@ -45,7 +45,7 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour {
AbstractContraptionEntity entity = context.contraption.entity; AbstractContraptionEntity entity = context.contraption.entity;
if (entity instanceof ControlledContraptionEntity) { if (entity instanceof ControlledContraptionEntity) {
ControlledContraptionEntity controlledCE = (ControlledContraptionEntity) entity; ControlledContraptionEntity controlledCE = (ControlledContraptionEntity) entity;
if (controlledCE.getRotationAxis() == axis) if (context.contraption.canBeStabilized(facing, context.localPos))
offset = -controlledCE.getAngle(renderPartialTicks); offset = -controlledCE.getAngle(renderPartialTicks);
} else if (entity instanceof OrientedContraptionEntity) { } else if (entity instanceof OrientedContraptionEntity) {

View File

@ -55,7 +55,7 @@ public class StabilizedContraption extends Contraption {
} }
@Override @Override
protected boolean canAxisBeStabilized(Axis axis) { public boolean canBeStabilized(Direction facing, BlockPos localPos) {
return false; return false;
} }

View File

@ -149,7 +149,7 @@ public class MountedContraption extends Contraption {
} }
@Override @Override
protected boolean canAxisBeStabilized(Axis axis) { public boolean canBeStabilized(Direction facing, BlockPos localPos) {
return true; return true;
} }