From 2c3a866494bdd238ac50cbffab753cb2b00e4754 Mon Sep 17 00:00:00 2001 From: Snownee Date: Tue, 26 Jan 2021 14:43:33 +0800 Subject: [PATCH] Fix contraption sticky block connectivity. Add support to PUSH_ONLY push reaction --- .../BlockMovementTraits.java | 6 ++++++ .../structureMovement/Contraption.java | 20 +++++++++++++++---- .../piston/PistonContraption.java | 3 +++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java index 93a4dac0d..ad25a1b97 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/BlockMovementTraits.java @@ -227,6 +227,12 @@ public class BlockMovementTraits { if (state.getBlock() instanceof SailBlock) return facing.getAxis() == state.get(SailBlock.FACING) .getAxis(); + if (AllBlocks.PISTON_EXTENSION_POLE.has(state)) + return facing.getAxis() != state.get(BlockStateProperties.FACING) + .getAxis(); + if (AllBlocks.MECHANICAL_PISTON_HEAD.has(state)) + return facing.getAxis() != state.get(BlockStateProperties.FACING) + .getAxis(); return isBrittle(state); } 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 bf4a6124f..bb4dadb7f 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 @@ -59,6 +59,7 @@ import net.minecraft.block.ChestBlock; import net.minecraft.block.DoorBlock; import net.minecraft.block.IWaterLoggable; import net.minecraft.block.PressurePlateBlock; +import net.minecraft.block.material.PushReaction; import net.minecraft.entity.Entity; import net.minecraft.fluid.Fluids; import net.minecraft.fluid.IFluidState; @@ -240,7 +241,7 @@ public abstract class Contraption { fluidStorage.forEach((pos, mfs) -> mfs.tick(entity, pos, world.isRemote)); } - protected boolean moveBlock(World world, BlockPos pos, Direction forcedDirection, List frontier, + protected boolean moveBlock(World world, BlockPos pos, @Nullable Direction forcedDirection, List frontier, Set visited) { visited.add(pos); frontier.remove(pos); @@ -296,14 +297,13 @@ public abstract class Contraption { Map superglue = SuperGlueHandler.gatherGlue(world, pos); // Slime blocks and super glue drag adjacent blocks if possible - boolean isStickyBlock = state.isStickyBlock(); for (Direction offset : Iterate.directions) { BlockPos offsetPos = pos.offset(offset); BlockState blockState = world.getBlockState(offsetPos); if (isAnchoringBlockAt(offsetPos)) continue; if (!movementAllowed(world, offsetPos)) { - if (offset == forcedDirection && isStickyBlock) + if (offset == forcedDirection) return false; continue; } @@ -313,8 +313,20 @@ public abstract class Contraption { boolean blockAttachedTowardsFace = BlockMovementTraits.isBlockAttachedTowards(world, offsetPos, blockState, offset.getOpposite()); boolean brittle = BlockMovementTraits.isBrittle(blockState); + boolean canStick = !brittle && state.canStickTo(blockState) && blockState.canStickTo(state); + if (canStick) { + if (state.getPushReaction() == PushReaction.PUSH_ONLY || blockState.getPushReaction() == PushReaction.PUSH_ONLY) { + canStick = false; + } + if (BlockMovementTraits.notSupportive(state, offset)) { + canStick = false; + } + if (BlockMovementTraits.notSupportive(blockState, offset.getOpposite())) { + canStick = false; + } + } - if (!wasVisited && ((isStickyBlock && !brittle) || blockAttachedTowardsFace || faceHasGlue)) + if (!wasVisited && (canStick || blockAttachedTowardsFace || faceHasGlue || (offset == forcedDirection && !BlockMovementTraits.notSupportive(state, forcedDirection)))) frontier.add(offsetPos); if (faceHasGlue) addGlue(superglue.get(offset)); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java index 2895fb9bd..1e101fd94 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/piston/PistonContraption.java @@ -8,6 +8,7 @@ import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.BlockState; import net.minecraft.block.CarpetBlock; +import net.minecraft.block.material.PushReaction; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.PistonType; @@ -164,6 +165,8 @@ public class PistonContraption extends TranslatingContraption { return true; if (!BlockMovementTraits.movementAllowed(world, currentPos)) return retracting; + if (retracting && state.getPushReaction() == PushReaction.PUSH_ONLY) + return true; frontier.add(currentPos); if (BlockMovementTraits.notSupportive(state, orientation)) return true;