Skip to content

Commit 1c45e41

Browse files
Fix horse/llama's armor/carpet not visible in 1.20.5->.3 (#765)
1 parent bc3d6b9 commit 1c45e41

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@
2828
import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.Protocol1_20_5To1_20_3;
2929
import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.storage.RegistryDataStorage;
3030
import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.storage.SecureChatStorage;
31+
import com.viaversion.viaversion.api.connection.UserConnection;
3132
import com.viaversion.viaversion.api.data.entity.DimensionData;
33+
import com.viaversion.viaversion.api.data.entity.EntityTracker;
3234
import com.viaversion.viaversion.api.minecraft.Particle;
3335
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
3436
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
3537
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
3638
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
3739
import com.viaversion.viaversion.api.minecraft.item.Item;
40+
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
3841
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
3942
import com.viaversion.viaversion.api.type.Types;
4043
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
4144
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
4245
import com.viaversion.viaversion.data.entity.DimensionDataImpl;
46+
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3;
4347
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5;
4448
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Attributes1_20_5;
4549
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5;
@@ -49,7 +53,9 @@
4953
import com.viaversion.viaversion.util.Key;
5054
import com.viaversion.viaversion.util.KeyMappings;
5155
import com.viaversion.viaversion.util.MathUtil;
56+
import java.util.ArrayList;
5257
import java.util.HashMap;
58+
import java.util.List;
5359
import java.util.Map;
5460

5561
public final class EntityPacketRewriter1_20_5 extends EntityRewriter<ClientboundPacket1_20_5, Protocol1_20_5To1_20_3> {
@@ -65,18 +71,24 @@ public void registerPackets() {
6571
registerRemoveEntities(ClientboundPackets1_20_5.REMOVE_ENTITIES);
6672

6773
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
6975
byte slot;
7076
do {
7177
slot = wrapper.read(Types.BYTE);
78+
final Item item = protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM));
79+
7280
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+
}
7589
}
7690

7791
wrapper.write(Types.BYTE, slot);
78-
79-
final Item item = protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM));
8092
wrapper.write(Types.ITEM1_20_2, item);
8193
} while (slot < 0);
8294
});
@@ -350,6 +362,22 @@ private void updateDimensionTypeData(final CompoundTag elementTag) {
350362
}
351363
}
352364

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+
353381
@Override
354382
protected void registerRewrites() {
355383
filter().mapDataType(typeId -> {

0 commit comments

Comments
 (0)