Add proper fast block placing.

This commit is contained in:
LambdAurora
2020-02-17 22:52:59 +01:00
parent 07a296603a
commit 0eadc054b6
2 changed files with 36 additions and 15 deletions

View File

@@ -674,6 +674,32 @@ public class LambdaInput
} }
} }
public static Direction getMoveDirection(@Nullable BlockPos lastPos, @NotNull BlockPos newPos)
{
if (lastPos == null)
return null;
BlockPos vector = newPos.subtract(lastPos);
if (vector.getX() > 0)
return Direction.EAST;
else if (vector.getX() < 0)
return Direction.WEST;
else if (vector.getZ() > 0)
return Direction.SOUTH;
else if (vector.getZ() < 0)
return Direction.NORTH;
else if (vector.getY() > 0)
return Direction.UP;
else if (vector.getY() < 0)
return Direction.DOWN;
return null;
}
/**
* Returns a nullable block hit result if front placing is possible.
*
* @param client The client instance.
* @return A block hit result if front placing is possible.
*/
public static @Nullable BlockHitResult tryFrontPlace(@NotNull MinecraftClient client) public static @Nullable BlockHitResult tryFrontPlace(@NotNull MinecraftClient client)
{ {
if (!LambdaControlsFeature.FRONT_BLOCK_PLACING.isAvailable()) if (!LambdaControlsFeature.FRONT_BLOCK_PLACING.isAvailable())

View File

@@ -68,8 +68,6 @@ public abstract class MinecraftClientMixin implements FrontBlockPlaceResultAcces
private BlockPos lambdacontrols_lastTargetPos; private BlockPos lambdacontrols_lastTargetPos;
private Vec3d lambdacontrols_lastPos; private Vec3d lambdacontrols_lastPos;
private Direction lambdacontrols_lastTargetSide; private Direction lambdacontrols_lastTargetSide;
private Direction lambdacontrols_lockedSide;
private int lambdacontrols_lockedSideCooldown;
@Override @Override
public @Nullable BlockHitResult lambdacontrols_getFrontBlockPlaceResult() public @Nullable BlockHitResult lambdacontrols_getFrontBlockPlaceResult()
@@ -95,35 +93,32 @@ public abstract class MinecraftClientMixin implements FrontBlockPlaceResultAcces
this.lambdacontrols_lastPos = this.player.getPos(); this.lambdacontrols_lastPos = this.player.getPos();
int cooldown = this.itemUseCooldown; int cooldown = this.itemUseCooldown;
double distance = this.lambdacontrols_lastPos.distanceTo(this.player.getPos());
BlockHitResult hitResult; BlockHitResult hitResult;
if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.BLOCK && this.player.abilities.flying) { if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.BLOCK && this.player.abilities.flying) {
hitResult = (BlockHitResult) this.crosshairTarget; hitResult = (BlockHitResult) this.crosshairTarget;
BlockPos targetPos = hitResult.getBlockPos(); BlockPos targetPos = hitResult.getBlockPos();
Direction side = hitResult.getSide(); Direction side = hitResult.getSide();
// @TODO Find a very good way to add fast block placing without it being annoying. boolean sidewaysBlockPlacing = this.lambdacontrols_lastTargetPos == null || !targetPos.equals(this.lambdacontrols_lastTargetPos.offset(this.lambdacontrols_lastTargetSide));
if (cooldown > 1 && !targetPos.equals(this.lambdacontrols_lastTargetPos) boolean backwardsBlockPlacing = this.player.input.movementForward < 0.0f && (this.lambdacontrols_lastTargetPos == null || targetPos.equals(this.lambdacontrols_lastTargetPos.offset(this.lambdacontrols_lastTargetSide)));
&& distance >= 0.38) {
if (cooldown > 1
&& !targetPos.equals(this.lambdacontrols_lastTargetPos)
&& (sidewaysBlockPlacing || backwardsBlockPlacing)) {
this.itemUseCooldown = 1; this.itemUseCooldown = 1;
this.lambdacontrols_lockedSide = side;
this.lambdacontrols_lockedSideCooldown = 10;
} else {
if (this.lambdacontrols_lockedSideCooldown == 0)
this.lambdacontrols_lockedSide = null;
else if (this.lambdacontrols_lockedSideCooldown > 0)
this.lambdacontrols_lockedSideCooldown--;
} }
this.lambdacontrols_lastTargetPos = targetPos.toImmutable(); this.lambdacontrols_lastTargetPos = targetPos.toImmutable();
this.lambdacontrols_lastTargetSide = side; this.lambdacontrols_lastTargetSide = side;
} else if (this.player.isSprinting()) { }
// Removed front placing sprinting as way too cheaty.
/* else if (this.player.isSprinting()) {
hitResult = this.lambdacontrols_frontBlockPlaceResult; hitResult = this.lambdacontrols_frontBlockPlaceResult;
if (hitResult != null) { if (hitResult != null) {
if (cooldown > 0) if (cooldown > 0)
this.itemUseCooldown = 0; this.itemUseCooldown = 0;
} }
} } */
this.lambdacontrols_lastPos = this.player.getPos(); this.lambdacontrols_lastPos = this.player.getPos();
} }