diff --git a/src/main/java/com/simibubi/create/content/contraptions/ContraptionCollider.java b/src/main/java/com/simibubi/create/content/contraptions/ContraptionCollider.java index df752567d6..667911a543 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/ContraptionCollider.java +++ b/src/main/java/com/simibubi/create/content/contraptions/ContraptionCollider.java @@ -14,7 +14,6 @@ import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.tuple.MutablePair; -import com.simibubi.create.AllBlocks; import com.simibubi.create.AllPackets; import com.simibubi.create.api.behaviour.interaction.MovingInteractionBehaviour; import com.simibubi.create.api.behaviour.movement.MovementBehaviour; @@ -701,7 +700,6 @@ public static boolean collideBlocks(AbstractContraptionEntity contraptionEntity) TranslatingContraption contraption = (TranslatingContraption) contraptionEntity.getContraption(); AABB bounds = contraptionEntity.getBoundingBox(); Vec3 position = contraptionEntity.position(); - BlockPos gridPos = BlockPos.containing(position); if (contraption == null) return false; @@ -713,8 +711,13 @@ public static boolean collideBlocks(AbstractContraptionEntity contraptionEntity) Direction movementDirection = Direction.getNearest(motion.x, motion.y, motion.z); // Blocks in the world - if (movementDirection.getAxisDirection() == AxisDirection.POSITIVE) - gridPos = gridPos.relative(movementDirection); + if (movementDirection.getAxisDirection() == AxisDirection.POSITIVE) { + Axis ax = movementDirection.getAxis(); + position = position.with(ax, Math.ceil(position.get(ax))); + } + + BlockPos gridPos = BlockPos.containing(position); + if (isCollidingWithWorld(world, contraption, gridPos, movementDirection)) return true; @@ -766,29 +769,32 @@ public static boolean isCollidingWithWorld(Level world, TranslatingContraption c boolean emptyCollider = collidedState.getCollisionShape(world, pos) .isEmpty(); + if (emptyCollider) continue; + if (collidedState.getBlock() instanceof CocoaBlock) continue; MovementBehaviour movementBehaviour = MovementBehaviour.REGISTRY.get(blockInfo.state()); if (movementBehaviour != null) { if (movementBehaviour instanceof BlockBreakingMovementBehaviour behaviour) { - if (!behaviour.canBreak(world, colliderPos, collidedState) && !emptyCollider) + if (!behaviour.canBreak(world, colliderPos, collidedState)) return true; continue; } if (movementBehaviour instanceof HarvesterMovementBehaviour harvesterMovementBehaviour) { if (!harvesterMovementBehaviour.isValidCrop(world, colliderPos, collidedState) - && !harvesterMovementBehaviour.isValidOther(world, colliderPos, collidedState) - && !emptyCollider) + && !harvesterMovementBehaviour.isValidOther(world, colliderPos, collidedState)) return true; continue; } } - if (AllBlocks.PULLEY_MAGNET.has(collidedState) && pos.equals(BlockPos.ZERO) - && movementDirection == Direction.UP) - continue; - if (!collidedState.canBeReplaced() && !emptyCollider) { + // This case exists for the mechanical piston, because it intersects with its own contraption + if (contraption.entity instanceof ControlledContraptionEntity cce) { + if (cce.controllerPos.equals(colliderPos)) continue; + } + + if (!collidedState.canBeReplaced()) { return true; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/gantry/GantryContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/gantry/GantryContraptionEntity.java index 72fcd45194..b0cf83a91f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/gantry/GantryContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/gantry/GantryContraptionEntity.java @@ -69,16 +69,19 @@ protected void tickContraption() { tickActors(); Vec3 movementVec = getDeltaMovement(); - if (ContraptionCollider.collideBlocks(this)) { - if (!level().isClientSide) - disassemble(); - return; - } - if (!isStalled() && tickCount > 2) { if (sequencedOffsetLimit >= 0) movementVec = VecHelper.clampComponentWise(movementVec, (float) sequencedOffsetLimit); + move(movementVec.x, movementVec.y, movementVec.z); + if (ContraptionCollider.collideBlocks(this)) { + move(-movementVec.x, -movementVec.y, -movementVec.z); + + if (!level().isClientSide) + disassemble(); + return; + } + if (sequencedOffsetLimit > 0) sequencedOffsetLimit = Math.max(0, sequencedOffsetLimit - movementVec.length()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/piston/LinearActuatorBlockEntity.java b/src/main/java/com/simibubi/create/content/contraptions/piston/LinearActuatorBlockEntity.java index 22dd3b27cf..6ce494e8b4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/piston/LinearActuatorBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/piston/LinearActuatorBlockEntity.java @@ -289,7 +289,7 @@ protected void tryDisassemble() { return; } int initial = getInitialOffset(); - if ((int) (offset + .5f) != initial && getMovementMode() == MovementMode.MOVE_PLACE_RETURNED) { + if (getMovementMode() == MovementMode.MOVE_PLACE_RETURNED && getGridOffset(offset) != initial) { waitingForSpeedChange = true; return; } @@ -319,7 +319,7 @@ protected void collided() { waitingForSpeedChange = true; return; } - offset = getGridOffset(offset - getMovementSpeed()); + resetContraptionToOffset(); tryDisassemble(); } @@ -336,7 +336,7 @@ protected void resetContraptionToOffset() { } public float getMovementSpeed() { - float movementSpeed = Mth.clamp(convertToLinear(getSpeed()), -.49f, .49f) + clientOffsetDiff / 2f; + float movementSpeed = Mth.clamp(convertToLinear(getSpeed()), -1, 1) + clientOffsetDiff / 2f; if (level.isClientSide) movementSpeed *= ServerSpeedProvider.get(); if (sequencedOffsetLimit >= 0) diff --git a/src/main/java/com/simibubi/create/content/contraptions/piston/MechanicalPistonBlockEntity.java b/src/main/java/com/simibubi/create/content/contraptions/piston/MechanicalPistonBlockEntity.java index 28ab0331fa..2e9adcf717 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/piston/MechanicalPistonBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/piston/MechanicalPistonBlockEntity.java @@ -15,6 +15,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; +import net.minecraft.core.HolderLookup; import net.minecraft.core.Direction.AxisDirection; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.Mth; @@ -50,26 +51,15 @@ public void assemble() throws AssemblyException { Direction direction = getBlockState().getValue(BlockStateProperties.FACING); - // Collect Construct + // Assemble contraption first (getMovementSpeed may already exist) PistonContraption contraption = new PistonContraption(direction, getMovementSpeed() < 0); if (!contraption.assemble(level, worldPosition)) return; - Direction positive = Direction.get(AxisDirection.POSITIVE, direction.getAxis()); - Direction movementDirection = - getSpeed() > 0 ^ direction.getAxis() != Axis.Z ? positive : positive.getOpposite(); - - BlockPos anchor = contraption.anchor.relative(direction, contraption.initialExtensionProgress); - if (ContraptionCollider.isCollidingWithWorld(level, contraption, anchor.relative(movementDirection), - movementDirection)) - return; - - // Check if not at limit already extensionLength = contraption.extensionLength; - float resultingOffset = contraption.initialExtensionProgress + Math.signum(getMovementSpeed()) * .5f; - if (resultingOffset <= 0 || resultingOffset >= extensionLength) { - return; - } + + // If piston cannot move, do not assemble + if (getMovementSpeed() == 0) return; // Run running = true; @@ -120,7 +110,7 @@ protected void collided() { @Override public float getMovementSpeed() { - float movementSpeed = Mth.clamp(convertToLinear(getSpeed()), -.49f, .49f); + float movementSpeed = Mth.clamp(convertToLinear(getSpeed()), -1, 1); if (level.isClientSide) movementSpeed *= ServerSpeedProvider.get(); Direction pistonDirection = getBlockState().getValue(BlockStateProperties.FACING); diff --git a/src/main/java/com/simibubi/create/content/kinetics/gantry/GantryShaftBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/gantry/GantryShaftBlockEntity.java index 25e7619336..c5345f8de3 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/gantry/GantryShaftBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/gantry/GantryShaftBlockEntity.java @@ -104,7 +104,7 @@ public float getPinionMovementSpeed() { BlockState blockState = getBlockState(); if (!AllBlocks.GANTRY_SHAFT.has(blockState)) return 0; - return Mth.clamp(convertToLinear(-getSpeed()), -.49f, .49f); + return Mth.clamp(convertToLinear(-getSpeed()), -1, 1); } @Override