1
0
forked from Clones/Controlify

✏️ Improve reach-around

This commit is contained in:
isXander
2023-06-15 18:35:00 +01:00
parent dc78eb61a2
commit 320c9d3d83
2 changed files with 15 additions and 13 deletions

View File

@ -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())

View File

@ -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) {