Skip to content

Commit bfe1ee5

Browse files
committed
Unify AvatarEntity offset handling, address clanker reviews
1 parent 6ef76c7 commit bfe1ee5

6 files changed

Lines changed: 13 additions & 14 deletions

File tree

core/src/main/java/org/geysermc/geyser/entity/type/Entity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public class Entity implements GeyserEntity {
104104

105105
protected Vector3f position;
106106
protected Vector3f motion;
107-
protected float offset;
107+
private float offset;
108108

109109
/**
110110
* x = Yaw, y = Pitch, z = HeadYaw
@@ -701,6 +701,7 @@ public Vector3f bedrockRotation() {
701701
* Gets the Bedrock edition position with the offset applied
702702
*/
703703
public Vector3f bedrockPosition() {
704+
float offset = getOffset();
704705
if (offset == 0f) {
705706
return position;
706707
}

core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl
154154
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
155155
moveEntityPacket.setRuntimeEntityId(geyserId);
156156
moveEntityPacket.setRotation(Vector3f.from(0, 0, bedRotation));
157-
moveEntityPacket.setPosition(Vector3f.from(position.getX() + xOffset, position.getY() + offset, position.getZ() + zOffset));
157+
moveEntityPacket.setPosition(Vector3f.from(position.getX() + xOffset, position.getY() + getOffset(), position.getZ() + zOffset));
158158
moveEntityPacket.setOnGround(isOnGround);
159159
moveEntityPacket.setTeleported(false);
160160
session.sendUpstreamPacket(moveEntityPacket);

core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,12 @@ public void setDimensionsFromPose(Pose pose) {
349349
}
350350

351351
@Override
352-
public Vector3f bedrockPosition() {
353-
// Don't apply the full bedrock y offset when le player is sleeping
352+
public float getOffset() {
353+
// Don't apply the full bedrock y offset when the player is sleeping
354354
if (bedPosition != null && getFlag(EntityFlag.SLEEPING)) {
355-
return position.up(0.2f);
355+
return 0.2f;
356356
}
357-
return super.bedrockPosition();
357+
return super.getOffset();
358358
}
359359

360360
public @Nullable String getSkinId() {

core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void setYaw(float yaw) {
172172
public Vector3f bedrockPosition() {
173173
TeleportCache unconfirmedTeleport = session.getUnconfirmedTeleport();
174174
if (unconfirmedTeleport != null) {
175-
return unconfirmedTeleport.getAdjustedPosition().up(EntityDefinitions.PLAYER.offset());
175+
return unconfirmedTeleport.getAdjustedPosition().up(getOffset());
176176
}
177177
return super.bedrockPosition();
178178
}
@@ -232,13 +232,11 @@ public void updateOwnRotation(float yaw, float pitch, float headYaw) {
232232
* @param position the new position of the Bedrock player
233233
*/
234234
public void setPositionFromBedrockPos(Vector3f position) {
235-
// Special handling: position while sleeping
236-
if (bedPosition != null && getFlag(EntityFlag.SLEEPING)) {
237-
this.position = position.down(0.2f);
238-
} else if (this.vehicle != null) {
235+
if (this.vehicle != null) {
239236
this.position = position.down(this.vehicle.getOffset());
240237
} else {
241-
this.position = position.down(offset);
238+
// getOffset will also account for a reduced offset (0.2) when sleeping
239+
this.position = position.down(getOffset());
242240
}
243241

244242
// Player is "above" the void so they're not supposed to no clip.

core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public Vector3f adjustPositionForBedrock(Vector3f position) {
467467
// Checks for Bedrock collision differences and adjust the position sent to Bedrock if needed
468468
// For example: Java teleports to 72.875 on top of a chest, but Bedrock believes chests are 72.95 high... so we fall through instead
469469
// ...which leads the server to teleport again, et voila.
470-
BoundingBox playerBox = session.getCollisionManager().getPlayerBoundingBox().clone();
470+
BoundingBox playerBox = playerBoundingBox.clone();
471471
playerBox.setMiddleX(position.getX());
472472
playerBox.setMiddleY(position.getY() + (playerBox.getSizeY() / 2.0));
473473
playerBox.setMiddleZ(position.getZ());

core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac
135135
TeleportCache.TeleportType type = (deltaMovement.distanceSquared(Vector3f.ZERO) > 1.0E-8F) ?
136136
TeleportCache.TeleportType.KEEP_VELOCITY : TeleportCache.TeleportType.NORMAL;
137137

138-
// We need to set the unconfirmed teleport to ensure we use the proper Bedrock position in moveAbsolute (see SessionPlayerEntity#adjustPositionForBedrock)
138+
// Set the unconfirmed teleport to ensure we send the adjusted Bedrock position in moveAbsolute (see CollisionManager#adjustPositionForBedrock)
139139
session.setUnconfirmedTeleport(new TeleportCache(session, teleportDestination, deltaMovement, newPitch, newYaw, teleportId, type));
140140
entity.moveAbsolute(teleportDestination, newYaw, newPitch, false, true);
141141

0 commit comments

Comments
 (0)