diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index 7834027f10a..1d5e3d46f3c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -555,12 +555,11 @@ protected boolean travel(VehicleContext ctx, float speed) { motion = motion.mul(movementMultiplier); } - Vector3d correctedMovement = vehicle.getSession().getCollisionManager().correctMovement( - motion.toDouble(), boundingBox, vehicle.isOnGround(), this.stepHeight, true, vehicle.canWalkOnLava() + Vector3d correctedMovement = vehicle.getSession().getWorldBorder().correctMovement(boundingBox, motion.toDouble()); + correctedMovement = vehicle.getSession().getCollisionManager().correctMovement( + correctedMovement, boundingBox, vehicle.isOnGround(), this.stepHeight, true, vehicle.canWalkOnLava() ); - correctedMovement = vehicle.getSession().getWorldBorder().correctMovement(boundingBox, correctedMovement); - boundingBox.translate(correctedMovement); ctx.loadSurroundingBlocks(); diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java index 397941b6fb3..0d16ae21143 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java @@ -205,46 +205,43 @@ public Vector3d correctMovement(BoundingBox boundingBox, Vector3d movement) { Vector3d bbMin = boundingBox.getMin(); Vector3d bbMax = boundingBox.getMax(); - // If outside border, don't adjust movement - if (bbMin.getX() + COLLISION_TOLERANCE < GenericMath.floor(minX) - || bbMin.getZ() + COLLISION_TOLERANCE < GenericMath.floor(minZ) - || bbMax.getX() - COLLISION_TOLERANCE > GenericMath.ceil(maxX) - || bbMax.getZ() - COLLISION_TOLERANCE > GenericMath.ceil(maxZ)) { + double correctedX; + if (movement.getX() < 0) { + correctedX = -limitMovement(-movement.getX(), bbMin.getX() - GenericMath.floor(minX)); + } else { + correctedX = limitMovement(movement.getX(), GenericMath.ceil(maxX) - bbMax.getX()); + } + + // Outside of border, don't adjust movement + if (Double.isNaN(correctedX)) { return movement; } - double diff; // Difference between edge of bounding box and world border - double correctedX = movement.getX(); - diff = GenericMath.floor(minX) - (bbMin.getX() + movement.getX()); - if (diff > 0) { - correctedX += diff; + double correctedZ; + if (movement.getZ() < 0) { + correctedZ = -limitMovement(-movement.getZ(), bbMin.getZ() - GenericMath.floor(minZ)); } else { - diff = (bbMax.getX() + movement.getX()) - GenericMath.ceil(maxX); - if (diff > 0) { - correctedX -= diff; - } + correctedZ = limitMovement(movement.getZ(), GenericMath.ceil(maxZ) - bbMax.getZ()); } - if (Math.abs(correctedX) < COLLISION_TOLERANCE) { - correctedX = 0; + if (Double.isNaN(correctedZ)) { + return movement; } - double correctedZ = movement.getZ(); - diff = GenericMath.floor(minZ) - (bbMin.getZ() + movement.getZ()); - if (diff > 0) { - correctedZ += diff; - } else { - diff = (bbMax.getZ() + movement.getZ()) - GenericMath.ceil(maxZ); - if (diff > 0) { - correctedZ -= diff; - } + return Vector3d.from(correctedX, movement.getY(), correctedZ); + } + + private double limitMovement(double movement, double limit) { + if (limit < 0) { + // Return NaN to indicate outside of border + return Double.NaN; } - if (Math.abs(correctedZ) < COLLISION_TOLERANCE) { - correctedZ = 0; + if (limit < COLLISION_TOLERANCE) { + return 0; } - return Vector3d.from(correctedX, movement.getY(), correctedZ); + return Math.min(movement, limit); } /**