Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
package org.geysermc.mcprotocollib.protocol.data.game.entity;

public enum EquipmentSlot {
MAIN_HAND,
OFF_HAND,
BOOTS,
LEGGINGS,
CHESTPLATE,
HELMET,
BODY,
SADDLE;
MAIN_HAND(0),
OFF_HAND(5),
BOOTS(1),
LEGGINGS(2),
CHESTPLATE(3),
HELMET(4),
BODY(6),
SADDLE(7);

private final int networkId;

EquipmentSlot(int networkId) {
this.networkId = networkId;
}

public int networkId() {
return networkId;
}

private static final EquipmentSlot[] VALUES = values();
private static final EquipmentSlot[] BY_NETWORK_ID = new EquipmentSlot[VALUES.length];

static {
for (EquipmentSlot slot : VALUES) {
BY_NETWORK_ID[slot.networkId] = slot;
}
}

public static EquipmentSlot fromEnumOrdinal(int id) {
return VALUES[id];
}

public static EquipmentSlot fromId(int networkId) {
return switch (networkId) {
case 0 -> MAIN_HAND;
case 1 -> BOOTS;
case 2 -> LEGGINGS;
case 3 -> CHESTPLATE;
case 4 -> HELMET;
case 5 -> OFF_HAND;
case 6 -> BODY;
case 7 -> SADDLE;
default -> throw new IllegalStateException("Unexpected equipment slot id: " + networkId);
};
if (networkId < 0 || networkId >= BY_NETWORK_ID.length) {
// ByIdMap.OutOfBoundsStrategy.ZERO
return BY_NETWORK_ID[0];
}

return BY_NETWORK_ID[networkId];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static Equippable readEquippable(ByteBuf buf) {
}

public static void writeEquippable(ByteBuf buf, Equippable equippable) {
MinecraftTypes.writeVarInt(buf, equippable.slot().ordinal());
MinecraftTypes.writeVarInt(buf, equippable.slot().networkId());
MinecraftTypes.writeSound(buf, equippable.equipSound());
MinecraftTypes.writeNullable(buf, equippable.model(), MinecraftTypes::writeResourceLocation);
MinecraftTypes.writeNullable(buf, equippable.cameraOverlay(), MinecraftTypes::writeResourceLocation);
Expand Down