Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ default CooldownUtils.CooldownType showCooldown() {
@Comment("Whether Bedrock players are blocked from performing their scaffolding-style bridging.")
boolean disableBedrockScaffolding();

@Comment("""
On Bedrock, analog input (joystick) allow player to move tiny bit to a certain direction unlike java where your speed
isn't customizable, so this options if enable will allow the bedrock player to move like that in a vehicle (eg: horse).
If not the Bedrock player will control vehicle like Java Edition, turning this on might flag anticheat!
""")
@DefaultBoolean(true)
boolean vehicleAnalogInput();

@Comment("""
Bedrock prevents building and displaying blocks above Y127 in the Nether.
This config option works around that by changing the Nether dimension ID to the End ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import lombok.Getter;
import lombok.Setter;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.TrigMath;
import org.cloudburstmc.math.vector.Vector2f;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.math.vector.Vector3i;
Expand Down Expand Up @@ -447,10 +448,24 @@ public void resetAir() {
}

public void setVehicleInput(Vector2f vehicleInput) {
this.vehicleInput = Vector2f.from(
MathUtils.clamp(vehicleInput.getX(), -1.0f, 1.0f),
MathUtils.clamp(vehicleInput.getY(), -1.0f, 1.0f)
vehicleInput = Vector2f.from(
MathUtils.clamp(vehicleInput.getX(), -1.0f, 1.0f),
MathUtils.clamp(vehicleInput.getY(), -1.0f, 1.0f)
);

if (vehicleInput.lengthSquared() < 1e-16) { // If it's too small, don't register it as an input, since the math will assume that they're moving forward
this.vehicleInput = Vector2f.ZERO;
} else {
if (this.vehicle instanceof BoatEntity || !session.getGeyser().config().gameplay().vehicleAnalogInput()) {
// This need to be clamped to an angle dividable by 45 so that the player move in a general direction and not like analog direction.
final double yaw = Math.round((Math.toDegrees(Math.atan2(vehicleInput.getY(), vehicleInput.getX())) - 90.0) / 45f) * 45f;
// We have to pass this to MathUtils#closeToZero since it's could be 1.0e-16 for example even though it's supposed to be zero.
double x = MathUtils.closeToZero(-Math.sin(yaw * TrigMath.DEG_TO_RAD)), z = MathUtils.closeToZero(Math.cos(yaw * TrigMath.DEG_TO_RAD));
this.vehicleInput = Vector2f.from(Math.signum(x), Math.signum(z)); // Math#signum clamp these values back to -1/1 if needed.
} else {
this.vehicleInput = vehicleInput;
}
}
}

public void setVehicleJumpStrength(int vehicleJumpStrength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ private void controlBoat() {
float acceleration = 0.0F;

final Vector2f input = vehicle.getSession().getPlayerEntity().getVehicleInput();
boolean up = input.getY() > 0.35;
boolean down = input.getY() < -0.35;
boolean left = input.getX() > 0.35;
boolean right = input.getX() < -0.35;
boolean up = input.getY() > 0;
boolean down = input.getY() < 0;
boolean left = input.getX() > 0;
boolean right = input.getX() < 0;

if (left) this.deltaRotation--;
if (right) this.deltaRotation++;
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/geysermc/geyser/util/MathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static Vector3f xYRot(Vector3f velocity, float pitch, float yaw) {
return Vector3f.from(d1, e, i1);
}

public static double closeToZero(double value) {
return Math.abs(value) < 1.0e-7 ? 0 : value;
}

/**
* Wrap the given float degrees to be between -180.0 and 180.0.
*
Expand Down