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] 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;