From 276a8d6485b698d059e2244e39cbefa08e2a489a Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Thu, 13 Feb 2020 00:14:17 -0900 Subject: [PATCH 1/4] Fix hotbar slot changing when the player's hand is updated The default value is 0. -1 seems to leave the selected hotbar slot unchanged. --- .../main/java/org/geysermc/connector/entity/LivingEntity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java index 50d097db..9f0a33d1 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -83,6 +83,7 @@ public class LivingEntity extends Entity { MobEquipmentPacket mobEquipmentPacket = new MobEquipmentPacket(); mobEquipmentPacket.setRuntimeEntityId(geyserId); mobEquipmentPacket.setItem(hand); + mobEquipmentPacket.setHotbarSlot(-1); session.getUpstream().sendPacket(armorEquipmentPacket); session.getUpstream().sendPacket(mobEquipmentPacket); From b18b83fd9aa0b183d26d9c14b6bfc3cbc061b5d8 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Thu, 13 Feb 2020 13:35:07 -0900 Subject: [PATCH 2/4] Fix armor not showing if partially armored --- .../org/geysermc/connector/entity/LivingEntity.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java index 9f0a33d1..2b8b8feb 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -42,11 +42,11 @@ import org.geysermc.connector.network.session.GeyserSession; @Setter public class LivingEntity extends Entity { - protected ItemData helmet; - protected ItemData chestplate; - protected ItemData leggings; - protected ItemData boots; - protected ItemData hand = ItemData.of(0, (short) 0, 0); + protected ItemData helmet = ItemData.AIR; + protected ItemData chestplate = ItemData.AIR; + protected ItemData leggings = ItemData.AIR; + protected ItemData boots = ItemData.AIR; + protected ItemData hand = ItemData.AIR; public LivingEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { super(entityId, geyserId, entityType, position, motion, rotation); From fa7324e1f566d39792d953061b5e3288b4005009 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Thu, 13 Feb 2020 16:47:45 -0900 Subject: [PATCH 3/4] Add support for offhand --- .../connector/entity/LivingEntity.java | 22 ++++++++++++++----- .../entity/JavaEntityEquipmentTranslator.java | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java index 2b8b8feb..bbe72f99 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -27,6 +27,7 @@ package org.geysermc.connector.entity; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.ContainerId; import com.nukkitx.protocol.bedrock.data.EntityData; import com.nukkitx.protocol.bedrock.data.ItemData; import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket; @@ -47,6 +48,7 @@ public class LivingEntity extends Entity { protected ItemData leggings = ItemData.AIR; protected ItemData boots = ItemData.AIR; protected ItemData hand = ItemData.AIR; + protected ItemData offHand = ItemData.AIR; public LivingEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { super(entityId, geyserId, entityType, position, motion, rotation); @@ -80,12 +82,22 @@ public class LivingEntity extends Entity { armorEquipmentPacket.setLeggings(leggings); armorEquipmentPacket.setBoots(boots); - MobEquipmentPacket mobEquipmentPacket = new MobEquipmentPacket(); - mobEquipmentPacket.setRuntimeEntityId(geyserId); - mobEquipmentPacket.setItem(hand); - mobEquipmentPacket.setHotbarSlot(-1); + MobEquipmentPacket handPacket = new MobEquipmentPacket(); + handPacket.setRuntimeEntityId(geyserId); + handPacket.setItem(hand); + handPacket.setHotbarSlot(-1); + handPacket.setInventorySlot(0); + handPacket.setContainerId(ContainerId.INVENTORY); + + MobEquipmentPacket offHandPacket = new MobEquipmentPacket(); + offHandPacket.setRuntimeEntityId(geyserId); + offHandPacket.setItem(offHand); + offHandPacket.setHotbarSlot(-1); + offHandPacket.setInventorySlot(0); + offHandPacket.setContainerId(ContainerId.OFFHAND); session.getUpstream().sendPacket(armorEquipmentPacket); - session.getUpstream().sendPacket(mobEquipmentPacket); + session.getUpstream().sendPacket(handPacket); + session.getUpstream().sendPacket(offHandPacket); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java index 1262664d..5efe8e4e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityEquipmentTranslator.java @@ -70,7 +70,7 @@ public class JavaEntityEquipmentTranslator extends PacketTranslator Date: Thu, 13 Feb 2020 17:04:22 -0900 Subject: [PATCH 4/4] Fix new player entity data getting lost while loading skin --- .../java/org/geysermc/connector/entity/Entity.java | 11 ++++++++++- .../org/geysermc/connector/entity/PlayerEntity.java | 5 ++++- .../connector/network/session/cache/EntityCache.java | 6 +++++- .../java/entity/JavaEntityMetadataTranslator.java | 8 ++------ .../java/entity/JavaEntityPropertiesTranslator.java | 2 +- .../java/entity/spawn/JavaSpawnPlayerTranslator.java | 1 + 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 47b39874..057a0663 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -154,6 +154,8 @@ public class Entity { } public void updateBedrockAttributes(GeyserSession session) { + if (!valid) return; + List attributes = new ArrayList<>(); for (Map.Entry entry : this.attributes.entrySet()) { if (!entry.getValue().getType().isBedrockAttribute()) @@ -191,7 +193,8 @@ public class Entity { metadata.put(EntityData.NAMETAG, MessageUtils.getBedrockMessage(name)); break; case 3: // is custom name visible - metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0)); + if (!this.is(PlayerEntity.class)) + metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0)); break; case 4: // silent metadata.getFlags().setFlag(EntityFlag.SILENT, (boolean) entityMetadata.getValue()); @@ -201,6 +204,12 @@ public class Entity { break; } + updateBedrockMetadata(session); + } + + public void updateBedrockMetadata(GeyserSession session) { + if (!valid) return; + SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); entityDataPacket.setRuntimeEntityId(geyserId); entityDataPacket.getMetadata().putAll(metadata); diff --git a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java index 67dc0894..20583002 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java @@ -81,10 +81,13 @@ public class PlayerEntity extends LivingEntity { addPlayerPacket.setCustomFlags(0); addPlayerPacket.setDeviceId(""); addPlayerPacket.setPlatformChatId(""); - addPlayerPacket.getMetadata().putAll(getMetadata()); + addPlayerPacket.getMetadata().putAll(metadata); valid = true; session.getUpstream().sendPacket(addPlayerPacket); + + updateEquipment(session); + updateBedrockAttributes(session); } public void sendPlayer(GeyserSession session) { diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java index cba6b7b6..2834cb90 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java @@ -56,9 +56,13 @@ public class EntityCache { public void spawnEntity(Entity entity) { entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY()); + cacheEntity(entity); + entity.spawnEntity(session); + } + + public void cacheEntity(Entity entity) { entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId()); entities.put(entity.getGeyserId(), entity); - entity.spawnEntity(session); } public boolean removeEntity(Entity entity, boolean force) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java index 0a55120d..d8d28fb7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java @@ -41,12 +41,8 @@ public class JavaEntityMetadataTranslator extends PacketTranslator