From 320c9d3d8350a3463a64221e1e25387848db0ad1 Mon Sep 17 00:00:00 2001 From: isXander Date: Thu, 15 Jun 2023 18:35:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Improve=20reach-around?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ingame/ControllerPlayerMovement.java | 11 +++++------ .../reacharound/ReachAroundHandler.java | 17 ++++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/isxander/controlify/ingame/ControllerPlayerMovement.java b/src/main/java/dev/isxander/controlify/ingame/ControllerPlayerMovement.java index 823afef..3fd8c6d 100644 --- a/src/main/java/dev/isxander/controlify/ingame/ControllerPlayerMovement.java +++ b/src/main/java/dev/isxander/controlify/ingame/ControllerPlayerMovement.java @@ -34,11 +34,10 @@ public class ControllerPlayerMovement extends Input { this.forwardImpulse = bindings.WALK_FORWARD.state() - bindings.WALK_BACKWARD.state(); this.leftImpulse = bindings.WALK_LEFT.state() - bindings.WALK_RIGHT.state(); - // .1 to prevent using boat turning absolute hell with left/right left/right - this.up = bindings.WALK_FORWARD.state() > 0.1; - this.down = bindings.WALK_BACKWARD.state() > 0.1; - this.left = bindings.WALK_LEFT.state() > 0.1; - this.right = bindings.WALK_RIGHT.state() > 0.1; + this.up = bindings.WALK_FORWARD.state() > 0; + this.down = bindings.WALK_BACKWARD.state() > 0; + this.left = bindings.WALK_LEFT.state() > 0; + this.right = bindings.WALK_RIGHT.state() > 0; if (Controlify.instance().config().globalSettings().keyboardMovement) { this.forwardImpulse = Math.signum(this.forwardImpulse); @@ -56,7 +55,7 @@ public class ControllerPlayerMovement extends Input { if (!bindings.JUMP.held()) this.jumping = false; - if (player.getAbilities().flying || (player.isInWater() && !player.onGround()) || !controller.config().toggleSneak) { + if (player.getAbilities().flying || (player.isInWater() && !player.onGround()) || player.getVehicle() != null || !controller.config().toggleSneak) { if (bindings.SNEAK.justPressed()) this.shiftKeyDown = true; if (!bindings.SNEAK.held()) diff --git a/src/main/java/dev/isxander/controlify/reacharound/ReachAroundHandler.java b/src/main/java/dev/isxander/controlify/reacharound/ReachAroundHandler.java index 9dd1228..ef545b1 100644 --- a/src/main/java/dev/isxander/controlify/reacharound/ReachAroundHandler.java +++ b/src/main/java/dev/isxander/controlify/reacharound/ReachAroundHandler.java @@ -18,16 +18,19 @@ public class ReachAroundHandler { if (!canReachAround(entity)) return hitResult; - // LivingEntity#playBlockFallSound - this is the location where the game determines the footstep noise - // maybe experiment on different values rather than 0.2f from other areas in the game? - int x = Mth.floor(entity.getX()); - int y = Mth.floor(entity.getY() - 0.2F); - int z = Mth.floor(entity.getZ()); - var floorPos = new BlockPos(x, y, z); + // New method in 1.20 describing the position of the block + // that the player is supported on. + // This differentiates from the feet minus 1 as a block on the edge of the hitbox + // may still support the player. + var supportingBlockPos = entity.getOnPos(); + + // player can be on ground but not directly over a block + if (entity.level().getBlockState(supportingBlockPos).isAir()) + return hitResult; // this allows all interaction with blocks, such as opening containers, ringing bells, etc. // this is consistent with bedrock edition behaviour, tested - return new BlockHitResult(floorPos.getCenter(), entity.getDirection(), floorPos, false); + return new BlockHitResult(supportingBlockPos.getCenter(), entity.getDirection(), supportingBlockPos, false); } private static boolean canReachAround(Entity cameraEntity) {