From ca4877430ececbd7e00754569658fce69a9d6ebe Mon Sep 17 00:00:00 2001 From: Snownee <1850986885@qq.com> Date: Thu, 14 May 2020 18:22:21 +0800 Subject: [PATCH 1/3] Fix deployers getting stuck in water or bedrock as contraption --- .../deployer/DeployerFakePlayer.java | 1 + .../components/deployer/DeployerHandler.java | 35 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java index fa8e15b89..f5f71dc1a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java @@ -66,6 +66,7 @@ public class DeployerFakePlayer extends FakePlayer { return new StringTextComponent(Lang.translate("block.deployer.damage_source_name")); } + @Override @OnlyIn(Dist.CLIENT) public float getEyeHeight(Pose poseIn) { return 0; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerHandler.java b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerHandler.java index 303c79761..3b24f953e 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerHandler.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerHandler.java @@ -1,6 +1,7 @@ package com.simibubi.create.modules.contraptions.components.deployer; import static net.minecraftforge.eventbus.api.Event.Result.DENY; +import static net.minecraftforge.eventbus.api.Event.Result.DEFAULT; import java.util.ArrayList; import java.util.List; @@ -47,7 +48,7 @@ import net.minecraft.world.server.ServerWorld; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock; import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock; -import net.minecraftforge.eventbus.api.Event.Result; +import net.minecraftforge.eventbus.api.Event; public class DeployerHandler { @@ -164,18 +165,18 @@ public class DeployerHandler { // Left click if (mode == Mode.PUNCH) { - LeftClickBlock event = ForgeHooks.onLeftClickBlock(player, clickedPos, face); - if (event.isCanceled()) - return; if (!world.isBlockModifiable(player, clickedPos)) return; - if (world.extinguishFire(player, clickedPos, face)) - return; - if (clickedState.isAir(world, clickedPos)) { + if (clickedState.getRenderShape(world, clickedPos).isEmpty()) { player.blockBreakingProgress = null; return; } - if (event.getUseBlock() != Result.DENY) + LeftClickBlock event = ForgeHooks.onLeftClickBlock(player, clickedPos, face); + if (event.isCanceled()) + return; + if (world.extinguishFire(player, clickedPos, face)) + return; + if (event.getUseBlock() != DENY) clickedState.onBlockClicked(world, clickedPos, player); if (stack.isEmpty()) return; @@ -193,6 +194,10 @@ public class DeployerHandler { player.blockBreakingProgress = null; return; } + if (progress <= 0) { + player.blockBreakingProgress = null; + return; + } if ((int) (before * 10) != (int) (progress * 10)) world.sendBlockBreakProgress(player.getEntityId(), clickedPos, (int) (progress * 10)); @@ -202,10 +207,16 @@ public class DeployerHandler { // Right click ItemUseContext itemusecontext = new ItemUseContext(player, hand, result); - RightClickBlock event = ForgeHooks.onRightClickBlock(player, hand, clickedPos, face); + Event.Result useBlock = DENY; + Event.Result useItem = DEFAULT; + if (!clickedState.getRenderShape(world, clickedPos).isEmpty()) { + RightClickBlock event = ForgeHooks.onRightClickBlock(player, hand, clickedPos, face); + useBlock = event.getUseBlock(); + useItem = event.getUseItem(); + } // Item has custom active use - if (event.getUseItem() != DENY) { + if (useItem != DENY) { ActionResultType actionresult = stack.onItemUseFirst(itemusecontext); if (actionresult != ActionResultType.PASS) return; @@ -216,11 +227,11 @@ public class DeployerHandler { !(player.isSneaking() && holdingSomething) || (stack.doesSneakBypassUse(world, clickedPos, player)); // Use on block - if (event.getUseBlock() != DENY && flag1 && clickedState.onBlockActivated(world, player, hand, result)) + if (useBlock != DENY && flag1 && clickedState.onBlockActivated(world, player, hand, result)) return; if (stack.isEmpty()) return; - if (event.getUseItem() == DENY) + if (useItem == DENY) return; if (item instanceof BlockItem && !clickedState.isReplaceable(new BlockItemUseContext(itemusecontext))) return; 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 2/3] 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 3/3] 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() {