Skip to content

Commit ca69def

Browse files
authored
Fix missing entity data for pig and strider saddles in 1.21.5 -> 1.21.4 (#1182)
1 parent b268342 commit ca69def

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_5to1_21_4/rewriter/BlockItemPacketRewriter1_21_5.java

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ public void registerPackets() {
190190
final Item item = wrapper.read(itemType());
191191
if (equipmentSlot == SADDLE_EQUIPMENT_SLOT) {
192192
// Send saddle entity data for horses
193-
if (trackedEntity != null && trackedEntity.entityType().isOrHasParent(EntityTypes1_21_5.ABSTRACT_HORSE)) {
193+
if (trackedEntity != null && (
194+
trackedEntity.entityType().isOrHasParent(EntityTypes1_21_5.ABSTRACT_HORSE)
195+
|| trackedEntity.entityType().isOrHasParent(EntityTypes1_21_5.PIG)
196+
|| trackedEntity.entityType().isOrHasParent(EntityTypes1_21_5.STRIDER)
197+
)) {
194198
sendSaddledEntityData(wrapper.user(), trackedEntity, entityId, item.identifier() == 800);
195199
}
196200
} else {
@@ -285,30 +289,44 @@ private void convertClientAsset(final PacketWrapper wrapper) {
285289
}
286290

287291
private void sendSaddledEntityData(final UserConnection connection, final TrackedEntity trackedEntity, final int entityId, final boolean saddled) {
288-
byte data = 0;
289-
if (trackedEntity.hasData()) {
290-
final HorseDataStorage horseDataStorage = trackedEntity.data().get(HorseDataStorage.class);
291-
if (horseDataStorage != null) {
292-
if (horseDataStorage.saddled() == saddled) {
293-
return;
292+
EntityData entityData = null;
293+
294+
if (trackedEntity.entityType().isOrHasParent(EntityTypes1_21_5.ABSTRACT_HORSE)) {
295+
byte data = 0;
296+
if (trackedEntity.hasData()) {
297+
final HorseDataStorage horseDataStorage = trackedEntity.data().get(HorseDataStorage.class);
298+
if (horseDataStorage != null) {
299+
if (horseDataStorage.saddled() == saddled) {
300+
return;
301+
}
302+
303+
data = horseDataStorage.data();
294304
}
305+
}
306+
307+
trackedEntity.data().put(new HorseDataStorage(data, saddled));
295308

296-
data = horseDataStorage.data();
309+
if (saddled) {
310+
data = (byte) (data | SADDLED_FLAG);
297311
}
298-
}
299312

300-
trackedEntity.data().put(new HorseDataStorage(data, saddled));
313+
entityData = new EntityData(17, VersionedTypes.V1_21_4.entityDataTypes.byteType, data);
314+
315+
} else if (trackedEntity.entityType().isOrHasParent(EntityTypes1_21_5.PIG)) {
316+
entityData = new EntityData(17, VersionedTypes.V1_21_4.entityDataTypes.booleanType, saddled);
301317

302-
if (saddled) {
303-
data = (byte) (data | SADDLED_FLAG);
318+
} else if (trackedEntity.entityType().isOrHasParent(EntityTypes1_21_5.STRIDER)) {
319+
entityData = new EntityData(19, VersionedTypes.V1_21_4.entityDataTypes.booleanType, saddled);
304320
}
305321

306-
final PacketWrapper entityDataPacket = PacketWrapper.create(ClientboundPackets1_21_2.SET_ENTITY_DATA, connection);
307-
final List<EntityData> entityDataList = new ArrayList<>();
308-
entityDataList.add(new EntityData(17, VersionedTypes.V1_21_4.entityDataTypes.byteType, data));
309-
entityDataPacket.write(Types.VAR_INT, entityId);
310-
entityDataPacket.write(VersionedTypes.V1_21_4.entityDataList, entityDataList);
311-
entityDataPacket.send(Protocol1_21_5To1_21_4.class);
322+
if (entityData != null) {
323+
final PacketWrapper entityDataPacket = PacketWrapper.create(ClientboundPackets1_21_2.SET_ENTITY_DATA, connection);
324+
final List<EntityData> entityDataList = new ArrayList<>();
325+
entityDataList.add(entityData);
326+
entityDataPacket.write(Types.VAR_INT, entityId);
327+
entityDataPacket.write(VersionedTypes.V1_21_4.entityDataList, entityDataList);
328+
entityDataPacket.send(Protocol1_21_5To1_21_4.class);
329+
}
312330
}
313331

314332
private String heightmapType(final int id) {

0 commit comments

Comments
 (0)