Update ServerEntityEquipmentPacket

This commit is contained in:
DoctorMacc 2020-06-25 21:47:11 -04:00
parent c614376c0c
commit c2c8e2da2d
2 changed files with 35 additions and 6 deletions

View file

@ -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;
}

View file

@ -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<Equipment> 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