From 2a44874458fba950e9156aad479f604a9a4ba19a Mon Sep 17 00:00:00 2001 From: rosiecube <53262103+rosiecube@users.noreply.github.com> Date: Thu, 10 Dec 2020 05:09:14 +0900 Subject: [PATCH] Fix Bedrock ItemEntity Y position bug (#1636) Setting motion while on the ground causes visual issues. Additionally, there is an offset difference in the movement of an item entity. --- .../geysermc/connector/entity/ItemEntity.java | 17 +++++++++++++++-- .../connector/entity/type/EntityType.java | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java index 41308a0de..4a69c834b 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/ItemEntity.java @@ -36,7 +36,20 @@ import org.geysermc.connector.network.translators.item.ItemTranslator; public class ItemEntity extends Entity { public ItemEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { - super(entityId, geyserId, entityType, position, motion, rotation); + super(entityId, geyserId, entityType, position.add(0d, entityType.getOffset(), 0d), motion, rotation); + } + + @Override + public void setMotion(Vector3f motion) { + if (isOnGround()) + motion = Vector3f.from(motion.getX(), 0, motion.getZ()); + + super.setMotion(motion); + } + + @Override + public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround, boolean teleported) { + super.moveAbsolute(session, position.add(0d, this.entityType.getOffset(), 0d), rotation, isOnGround, teleported); } @Override @@ -44,7 +57,7 @@ public class ItemEntity extends Entity { if (entityMetadata.getId() == 7) { AddItemEntityPacket itemPacket = new AddItemEntityPacket(); itemPacket.setRuntimeEntityId(geyserId); - itemPacket.setPosition(position); + itemPacket.setPosition(position.add(0d, this.entityType.getOffset(), 0d)); itemPacket.setMotion(motion); itemPacket.setUniqueEntityId(geyserId); itemPacket.setFromFishing(false); diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index a77d3504c..3e6b6c72d 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -100,7 +100,7 @@ public enum EntityType { ARMOR_STAND(ArmorStandEntity.class, 61, 1.975f, 0.5f), TRIPOD_CAMERA(Entity.class, 62, 0f), PLAYER(PlayerEntity.class, 63, 1.8f, 0.6f, 0.6f, 1.62f), - ITEM(ItemEntity.class, 64, 0.25f, 0.25f), + ITEM(ItemEntity.class, 64, 0.25f, 0.25f, 0.25f, 0.125f), PRIMED_TNT(TNTEntity.class, 65, 0.98f, 0.98f, 0.98f, 0f, "minecraft:tnt"), FALLING_BLOCK(FallingBlockEntity.class, 66, 0.98f, 0.98f), MOVING_BLOCK(Entity.class, 67, 0f),