28
28
import com .viaversion .viabackwards .protocol .v1_20_5to1_20_3 .Protocol1_20_5To1_20_3 ;
29
29
import com .viaversion .viabackwards .protocol .v1_20_5to1_20_3 .storage .RegistryDataStorage ;
30
30
import com .viaversion .viabackwards .protocol .v1_20_5to1_20_3 .storage .SecureChatStorage ;
31
+ import com .viaversion .viaversion .api .connection .UserConnection ;
31
32
import com .viaversion .viaversion .api .data .entity .DimensionData ;
33
+ import com .viaversion .viaversion .api .data .entity .EntityTracker ;
32
34
import com .viaversion .viaversion .api .minecraft .Particle ;
33
35
import com .viaversion .viaversion .api .minecraft .RegistryEntry ;
34
36
import com .viaversion .viaversion .api .minecraft .entities .EntityType ;
35
37
import com .viaversion .viaversion .api .minecraft .entities .EntityTypes1_20_5 ;
36
38
import com .viaversion .viaversion .api .minecraft .entitydata .EntityData ;
37
39
import com .viaversion .viaversion .api .minecraft .item .Item ;
40
+ import com .viaversion .viaversion .api .protocol .packet .PacketWrapper ;
38
41
import com .viaversion .viaversion .api .protocol .remapper .PacketHandlers ;
39
42
import com .viaversion .viaversion .api .type .Types ;
40
43
import com .viaversion .viaversion .api .type .types .version .Types1_20_3 ;
41
44
import com .viaversion .viaversion .api .type .types .version .Types1_20_5 ;
42
45
import com .viaversion .viaversion .data .entity .DimensionDataImpl ;
46
+ import com .viaversion .viaversion .protocols .v1_20_2to1_20_3 .packet .ClientboundPackets1_20_3 ;
43
47
import com .viaversion .viaversion .protocols .v1_20_3to1_20_5 .Protocol1_20_3To1_20_5 ;
44
48
import com .viaversion .viaversion .protocols .v1_20_3to1_20_5 .data .Attributes1_20_5 ;
45
49
import com .viaversion .viaversion .protocols .v1_20_3to1_20_5 .packet .ClientboundConfigurationPackets1_20_5 ;
49
53
import com .viaversion .viaversion .util .Key ;
50
54
import com .viaversion .viaversion .util .KeyMappings ;
51
55
import com .viaversion .viaversion .util .MathUtil ;
56
+ import java .util .ArrayList ;
52
57
import java .util .HashMap ;
58
+ import java .util .List ;
53
59
import java .util .Map ;
54
60
55
61
public final class EntityPacketRewriter1_20_5 extends EntityRewriter <ClientboundPacket1_20_5 , Protocol1_20_5To1_20_3 > {
@@ -65,18 +71,24 @@ public void registerPackets() {
65
71
registerRemoveEntities (ClientboundPackets1_20_5 .REMOVE_ENTITIES );
66
72
67
73
protocol .registerClientbound (ClientboundPackets1_20_5 .SET_EQUIPMENT , wrapper -> {
68
- wrapper .passthrough (Types .VAR_INT ); // Entity id
74
+ final int entityId = wrapper .passthrough (Types .VAR_INT ); // Entity id
69
75
byte slot ;
70
76
do {
71
77
slot = wrapper .read (Types .BYTE );
78
+ final Item item = protocol .getItemRewriter ().handleItemToClient (wrapper .user (), wrapper .read (Types1_20_5 .ITEM ));
79
+
72
80
if (slot == 6 ) {
73
- //TODO Body to... something else?
74
- slot = 2 ;
81
+ final EntityTracker tracker = wrapper .user ().getEntityTracker (Protocol1_20_5To1_20_3 .class );
82
+ slot = 4 ; // Map body slot index to chest slot index for horses
83
+ final EntityType type = tracker .entityType (entityId );
84
+ if (type != null && type .isOrHasParent (EntityTypes1_20_5 .LLAMA )) {
85
+ // Cancel equipment and set correct entity data instead
86
+ wrapper .cancel ();
87
+ sendCarpetColorUpdate (wrapper .user (), entityId , item );
88
+ }
75
89
}
76
90
77
91
wrapper .write (Types .BYTE , slot );
78
-
79
- final Item item = protocol .getItemRewriter ().handleItemToClient (wrapper .user (), wrapper .read (Types1_20_5 .ITEM ));
80
92
wrapper .write (Types .ITEM1_20_2 , item );
81
93
} while (slot < 0 );
82
94
});
@@ -350,6 +362,22 @@ private void updateDimensionTypeData(final CompoundTag elementTag) {
350
362
}
351
363
}
352
364
365
+ private void sendCarpetColorUpdate (final UserConnection connection , final int entityId , final Item item ) {
366
+ final PacketWrapper setEntityData = PacketWrapper .create (ClientboundPackets1_20_3 .SET_ENTITY_DATA , connection );
367
+ setEntityData .write (Types .VAR_INT , entityId ); // Entity id
368
+ int color = -1 ;
369
+ if (item != null ) {
370
+ // Convert carpet item id to dyed color id
371
+ if (item .identifier () >= 445 && item .identifier () <= 460 ) {
372
+ color = item .identifier () - 445 ;
373
+ }
374
+ }
375
+ final List <EntityData > metadataList = new ArrayList <>();
376
+ metadataList .add (new EntityData (20 , Types1_20_3 .ENTITY_DATA_TYPES .varIntType , color ));
377
+ setEntityData .write (Types1_20_3 .ENTITY_DATA_LIST , metadataList );
378
+ setEntityData .send (Protocol1_20_5To1_20_3 .class );
379
+ }
380
+
353
381
@ Override
354
382
protected void registerRewrites () {
355
383
filter ().mapDataType (typeId -> {
0 commit comments