Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -319,7 +319,7 @@ protected void collided() {
waitingForSpeedChange = true;
return;
}
offset = getGridOffset(offset - getMovementSpeed());

resetContraptionToOffset();
tryDisassemble();
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +26,6 @@

public class MechanicalPistonBlockEntity extends LinearActuatorBlockEntity {

protected boolean hadCollisionWithOtherPiston;
protected int extensionLength;

public MechanicalPistonBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
Expand All @@ -52,26 +52,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;
Expand All @@ -87,7 +76,7 @@ public void assemble() throws AssemblyException {
level.addFreshEntity(movedContraption);

AllSoundEvents.CONTRAPTION_ASSEMBLE.playOnServer(level, worldPosition);

if (contraption.containsBlockBreakers())
award(AllAdvancements.CONTRAPTION_ACTORS);
}
Expand Down Expand Up @@ -122,7 +111,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down