File tree Expand file tree Collapse file tree
protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package org .geysermc .mcprotocollib .protocol .data .game .entity ;
22
33public enum EquipmentSlot {
4- MAIN_HAND ,
5- OFF_HAND ,
6- BOOTS ,
7- LEGGINGS ,
8- CHESTPLATE ,
9- HELMET ,
10- BODY ,
11- SADDLE ;
4+ MAIN_HAND (0 ),
5+ OFF_HAND (5 ),
6+ BOOTS (1 ),
7+ LEGGINGS (2 ),
8+ CHESTPLATE (3 ),
9+ HELMET (4 ),
10+ BODY (6 ),
11+ SADDLE (7 );
12+
13+ private final int networkId ;
14+
15+ EquipmentSlot (int networkId ) {
16+ this .networkId = networkId ;
17+ }
18+
19+ public int networkId () {
20+ return networkId ;
21+ }
1222
1323 private static final EquipmentSlot [] VALUES = values ();
24+ private static final EquipmentSlot [] BY_NETWORK_ID = new EquipmentSlot [VALUES .length ];
25+
26+ static {
27+ for (EquipmentSlot slot : VALUES ) {
28+ BY_NETWORK_ID [slot .networkId ] = slot ;
29+ }
30+ }
1431
1532 public static EquipmentSlot fromEnumOrdinal (int id ) {
1633 return VALUES [id ];
1734 }
1835
1936 public static EquipmentSlot fromId (int networkId ) {
20- return switch (networkId ) {
21- case 0 -> MAIN_HAND ;
22- case 1 -> BOOTS ;
23- case 2 -> LEGGINGS ;
24- case 3 -> CHESTPLATE ;
25- case 4 -> HELMET ;
26- case 5 -> OFF_HAND ;
27- case 6 -> BODY ;
28- case 7 -> SADDLE ;
29- default -> throw new IllegalStateException ("Unexpected equipment slot id: " + networkId );
30- };
37+ if (networkId < 0 || networkId >= BY_NETWORK_ID .length ) {
38+ // ByIdMap.OutOfBoundsStrategy.ZERO
39+ return BY_NETWORK_ID [0 ];
40+ }
41+
42+ return BY_NETWORK_ID [networkId ];
3143 }
3244}
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ public static Equippable readEquippable(ByteBuf buf) {
243243 }
244244
245245 public static void writeEquippable (ByteBuf buf , Equippable equippable ) {
246- MinecraftTypes .writeVarInt (buf , equippable .slot ().ordinal ());
246+ MinecraftTypes .writeVarInt (buf , equippable .slot ().networkId ());
247247 MinecraftTypes .writeSound (buf , equippable .equipSound ());
248248 MinecraftTypes .writeNullable (buf , equippable .model (), MinecraftTypes ::writeResourceLocation );
249249 MinecraftTypes .writeNullable (buf , equippable .cameraOverlay (), MinecraftTypes ::writeResourceLocation );
You can’t perform that action at this time.
0 commit comments