From c2c8e2da2d0d6b21386b59a8563cc4564c05fcf8 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 25 Jun 2020 21:47:11 -0400 Subject: [PATCH] Update ServerEntityEquipmentPacket --- .../data/game/entity/metadata/Equipment.java | 13 +++++++++ .../entity/ServerEntityEquipmentPacket.java | 28 +++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/Equipment.java diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/Equipment.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/Equipment.java new file mode 100644 index 00000000..1afc9a6d --- /dev/null +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/Equipment.java @@ -0,0 +1,13 @@ +package com.github.steveice10.mc.protocol.data.game.entity.metadata; + +import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NonNull; + +@Data +@AllArgsConstructor +public class Equipment { + private @NonNull EquipmentSlot slot; + private @NonNull ItemStack item; +} diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java index f33179f7..110f359a 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java @@ -2,6 +2,7 @@ package com.github.steveice10.mc.protocol.packet.ingame.server.entity; import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.Equipment; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; @@ -14,6 +15,8 @@ import lombok.NonNull; import lombok.Setter; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; @Data @Setter(AccessLevel.NONE) @@ -21,21 +24,34 @@ import java.io.IOException; @AllArgsConstructor public class ServerEntityEquipmentPacket implements Packet { private int entityId; - private @NonNull EquipmentSlot slot; - private @NonNull ItemStack item; + private @NonNull Equipment[] equipment; @Override public void read(NetInput in) throws IOException { this.entityId = in.readVarInt(); - this.slot = MagicValues.key(EquipmentSlot.class, in.readVarInt()); - this.item = ItemStack.read(in); + boolean hasNextEntry = true; + List list = new ArrayList<>(); + while (hasNextEntry) { + int rawSlot = in.readVarInt(); + EquipmentSlot slot = MagicValues.key(EquipmentSlot.class, ((byte) rawSlot) & 127); + ItemStack item = ItemStack.read(in); + list.add(new Equipment(slot, item)); + hasNextEntry = (rawSlot & 128) == 128; + } + this.equipment = list.toArray(new Equipment[list.size()]); } @Override public void write(NetOutput out) throws IOException { out.writeVarInt(this.entityId); - out.writeVarInt(MagicValues.value(Integer.class, this.slot)); - ItemStack.write(out, this.item); + for (int i = 0; i < this.equipment.length; i++) { + int rawSlot = MagicValues.value(Integer.class, this.equipment); + if (i != equipment.length - 1) { + rawSlot = rawSlot | 128; + } + out.writeVarInt(rawSlot); + ItemStack.write(out, this.equipment[i].getItem()); + } } @Override