From fa7324e1f566d39792d953061b5e3288b4005009 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Thu, 13 Feb 2020 16:47:45 -0900 Subject: [PATCH] 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