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/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java index 50d097db..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; @@ -42,11 +43,12 @@ 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; + 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,11 +82,22 @@ public class LivingEntity extends Entity { armorEquipmentPacket.setLeggings(leggings); armorEquipmentPacket.setBoots(boots); - MobEquipmentPacket mobEquipmentPacket = new MobEquipmentPacket(); - mobEquipmentPacket.setRuntimeEntityId(geyserId); - mobEquipmentPacket.setItem(hand); + 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/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/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