From 9084c59003bfe930616ef8711cbc7e9cf69e9533 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Thu, 2 Dec 2021 19:56:12 -0500 Subject: [PATCH] Fix regressions in player movement handling --- .../java/org/geysermc/geyser/entity/EntityDefinition.java | 7 ++++++- .../main/java/org/geysermc/geyser/entity/type/Entity.java | 4 ++-- .../geysermc/geyser/entity/type/living/AgeableEntity.java | 5 ++--- .../geyser/entity/type/living/monster/PhantomEntity.java | 4 ++-- .../java/org/geysermc/geyser/session/GeyserSession.java | 5 ++--- .../bedrock/entity/player/BedrockMovePlayerTranslator.java | 4 +--- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java index 1149a67fd..f66a0c56b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java @@ -91,7 +91,7 @@ public record EntityDefinition(EntityFactory factory, Entit private String identifier; private float width; private float height; - private float offset; + private float offset = 0.00001f; private final List> translators; private Builder(EntityFactory factory) { @@ -118,6 +118,11 @@ public record EntityDefinition(EntityFactory factory, Entit return this; } + public Builder offset(float offset) { + this.offset = offset + 0.00001f; + return this; + } + /** * Resets the identifier as well */ diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 1828f63e1..479ec2e8c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -83,9 +83,9 @@ public class Entity { /* Metadata about this specific entity */ @Setter(AccessLevel.NONE) - protected float boundingBoxHeight; + private float boundingBoxHeight; @Setter(AccessLevel.NONE) - protected float boundingBoxWidth; + private float boundingBoxWidth; @Setter(AccessLevel.NONE) protected String nametag = ""; /* Metadata end */ diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java index b250f3e8e..b04247a7a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java @@ -45,9 +45,8 @@ public class AgeableEntity extends CreatureEntity { dirtyMetadata.put(EntityData.SCALE, isBaby ? getBabySize() : getAdultSize()); setFlag(EntityFlag.BABY, isBaby); - // TODO save this? - dirtyMetadata.put(EntityData.BOUNDING_BOX_HEIGHT, definition.height() * (isBaby ? getBabySize() : getAdultSize())); - dirtyMetadata.put(EntityData.BOUNDING_BOX_WIDTH, definition.width() * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxHeight(definition.height() * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxWidth(definition.width() * (isBaby ? getBabySize() : getAdultSize())); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java index 68f3e7d23..8d3ccc71f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java @@ -44,8 +44,8 @@ public class PhantomEntity extends FlyingEntity { float modelScale = 1f + 0.15f * size; float boundsScale = (1f + (0.2f * size) / definition.width()) / modelScale; - dirtyMetadata.put(EntityData.BOUNDING_BOX_WIDTH, boundsScale * definition.width()); - dirtyMetadata.put(EntityData.BOUNDING_BOX_HEIGHT, boundsScale * definition.height()); + setBoundingBoxWidth(boundsScale * definition.width()); + setBoundingBoxHeight(boundsScale * definition.height()); dirtyMetadata.put(EntityData.SCALE, modelScale); } } diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index e215017c0..0011381cf 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -58,7 +58,6 @@ import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.data.*; import com.nukkitx.protocol.bedrock.data.command.CommandPermission; -import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.v471.Bedrock_v471; @@ -1057,7 +1056,7 @@ public class GeyserSession implements GeyserConnection, CommandSender { private void setSneakingPose(boolean sneaking) { this.pose = sneaking ? Pose.SNEAKING : Pose.STANDING; - playerEntity.getDirtyMetadata().put(EntityData.BOUNDING_BOX_HEIGHT, sneaking ? 1.5f : playerEntity.getDefinition().height()); + playerEntity.setBoundingBoxHeight(sneaking ? 1.5f : playerEntity.getDefinition().height()); playerEntity.setFlag(EntityFlag.SNEAKING, sneaking); collisionManager.updatePlayerBoundingBox(); @@ -1065,7 +1064,7 @@ public class GeyserSession implements GeyserConnection, CommandSender { public void setSwimming(boolean swimming) { this.pose = swimming ? Pose.SWIMMING : Pose.STANDING; - playerEntity.getDirtyMetadata().put(EntityData.BOUNDING_BOX_HEIGHT, swimming ? 0.6f : playerEntity.getDefinition().height()); + playerEntity.setBoundingBoxHeight(swimming ? 0.6f : playerEntity.getDefinition().height()); playerEntity.setFlag(EntityFlag.SWIMMING, swimming); playerEntity.updateBedrockMetadata(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java index 76d7edc17..1555722d6 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java @@ -33,10 +33,10 @@ import com.nukkitx.math.vector.Vector3d; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; -import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; @@ -71,8 +71,6 @@ public class BedrockMovePlayerTranslator extends PacketTranslator