From 8d4e6895bcb844aea889fd235baec6d55ee337ae Mon Sep 17 00:00:00 2001 From: Snownee <1850986885@qq.com> Date: Thu, 14 May 2020 21:42:52 +0800 Subject: [PATCH 1/2] Fix bell duplicating --- .../contraptions/BlockMovementTraits.java | 15 +++++++++++++++ .../contraptions/StructureTransform.java | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java index 55d86719c..dce0411c2 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java @@ -26,6 +26,7 @@ import com.simibubi.create.modules.logistics.block.transposer.TransposerBlock; import net.minecraft.block.AbstractPressurePlateBlock; import net.minecraft.block.AbstractRailBlock; +import net.minecraft.block.BellBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -33,6 +34,7 @@ import net.minecraft.block.CarpetBlock; import net.minecraft.block.DoorBlock; import net.minecraft.block.FenceGateBlock; import net.minecraft.block.FlowerPotBlock; +import net.minecraft.block.HorizontalBlock; import net.minecraft.block.HorizontalFaceBlock; import net.minecraft.block.LadderBlock; import net.minecraft.block.RedstoneDiodeBlock; @@ -42,6 +44,7 @@ import net.minecraft.block.TorchBlock; import net.minecraft.block.WallTorchBlock; import net.minecraft.block.material.PushReaction; import net.minecraft.state.properties.AttachFace; +import net.minecraft.state.properties.BellAttachment; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; @@ -145,6 +148,8 @@ public class BlockMovementTraits { return true; if (block instanceof CarpetBlock) return true; + if (block instanceof BellBlock) + return true; return false; } @@ -198,6 +203,16 @@ public class BlockMovementTraits { return direction == state.get(NozzleBlock.FACING).getOpposite(); if (block instanceof EngineBlock) return direction == state.get(EngineBlock.HORIZONTAL_FACING).getOpposite(); + if (block instanceof BellBlock) { + BellAttachment attachment = state.get(BlockStateProperties.BELL_ATTACHMENT); + if (attachment == BellAttachment.FLOOR) { + return direction == Direction.DOWN; + } + if (attachment == BellAttachment.CEILING) { + return direction == Direction.UP; + } + return direction == state.get(HorizontalBlock.HORIZONTAL_FACING); + } return false; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/StructureTransform.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/StructureTransform.java index 1b3109e36..fe2e7b15d 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/StructureTransform.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/StructureTransform.java @@ -12,6 +12,7 @@ import com.simibubi.create.modules.contraptions.components.contraptions.chassis. import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope; +import net.minecraft.block.BellBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.HorizontalFaceBlock; @@ -19,6 +20,8 @@ import net.minecraft.block.SlabBlock; import net.minecraft.block.StairsBlock; import net.minecraft.state.BooleanProperty; import net.minecraft.state.properties.AttachFace; +import net.minecraft.state.properties.BellAttachment; +import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.Half; import net.minecraft.state.properties.SlabType; import net.minecraft.util.Direction; @@ -78,11 +81,18 @@ public class StructureTransform { * horizontal axes */ public BlockState apply(BlockState state) { - if (rotationAxis == Axis.Y) - return state.rotate(rotation); - Block block = state.getBlock(); + if (rotationAxis == Axis.Y) { + if (block instanceof BellBlock) { + if (state.get(BlockStateProperties.BELL_ATTACHMENT) == BellAttachment.DOUBLE_WALL) { + state = state.with(BlockStateProperties.BELL_ATTACHMENT, BellAttachment.SINGLE_WALL); + } + return state.with(HorizontalFaceBlock.HORIZONTAL_FACING, rotation.rotate(state.get(HorizontalFaceBlock.HORIZONTAL_FACING))); + } + return state.rotate(rotation); + } + if (block instanceof AbstractChassisBlock) return rotateChassis(state); From 463bf0b641a28607e0daa182fcda43a3897cbeae Mon Sep 17 00:00:00 2001 From: Snownee <1850986885@qq.com> Date: Thu, 14 May 2020 23:00:43 +0800 Subject: [PATCH 2/2] Fix super glue behavior. Fix super glue can stay between two unmovable blocks --- .../contraptions/glue/SuperGlueEntity.java | 17 +++++++++++------ .../contraptions/glue/SuperGlueRenderer.java | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueEntity.java index 775e74b0c..c4b58507d 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueEntity.java @@ -8,6 +8,7 @@ import com.simibubi.create.AllEntities; import com.simibubi.create.AllItems; import com.simibubi.create.AllPackets; import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.modules.contraptions.components.contraptions.BlockMovementTraits; import com.simibubi.create.modules.schematics.ISpecialEntityItemRequirement; import com.simibubi.create.modules.schematics.ItemRequirement; import com.simibubi.create.modules.schematics.ItemRequirement.ItemUseType; @@ -157,11 +158,20 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat BlockPos pos2 = hangingPosition.offset(getFacingDirection().getOpposite()); if (!world.isAreaLoaded(pos, 0) || !world.isAreaLoaded(pos2, 0)) return true; - if (world.isAirBlock(pos) && world.isAirBlock(pos2)) + if (!isValidFace(world, pos2, getFacingDirection()) && !isValidFace(world, pos, getFacingDirection().getOpposite())) return false; return world.getEntitiesInAABBexcluding(this, getBoundingBox(), e -> e instanceof SuperGlueEntity).isEmpty(); } + public static boolean isValidFace(World world, BlockPos pos, Direction direction) { + if (!BlockMovementTraits.movementNecessary(world, pos)) + return false; + if (BlockMovementTraits.notSupportive(world.getBlockState(pos), direction)) { + return false; + } + return true; + } + @Override public boolean canBeCollidedWith() { return true; @@ -236,11 +246,6 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat return Math.max(light, light2); } - @Override - public void applyEntityCollision(Entity entityIn) { - super.applyEntityCollision(entityIn); - } - @Override public boolean processInitialInteract(PlayerEntity player, Hand hand) { DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueRenderer.java index 2e595f9d0..5765ebcc6 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/glue/SuperGlueRenderer.java @@ -83,7 +83,7 @@ public class SuperGlueRenderer extends EntityRenderer { return false; BlockPos pos = entity.hangingPosition; BlockPos pos2 = pos.offset(entity.getFacingDirection().getOpposite()); - return entity.world.isAirBlock(pos) != entity.world.isAirBlock(pos2); + return !SuperGlueEntity.isValidFace(entity.world, pos2, entity.getFacingDirection()) || !SuperGlueEntity.isValidFace(entity.world, pos, entity.getFacingDirection().getOpposite()); } private void initQuads() {