Skip to content

Commit a0d063d

Browse files
Handle data->pitch/yaw item frame rotation change in 1.17->1.16.4 (#848)
1 parent 24f994f commit a0d063d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/EntityPacketRewriter1_17.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.viaversion.viabackwards.protocol.v1_17to1_16_4.Protocol1_17To1_16_4;
2323
import com.viaversion.viaversion.api.minecraft.Particle;
2424
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
25+
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2;
2526
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_17;
2627
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
2728
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
@@ -50,6 +51,29 @@ protected void registerPackets() {
5051
registerTracker(ClientboundPackets1_17.ADD_PLAYER, EntityTypes1_17.PLAYER);
5152
registerSetEntityData(ClientboundPackets1_17.SET_ENTITY_DATA, Types1_17.ENTITY_DATA_LIST, Types1_16.ENTITY_DATA_LIST);
5253

54+
protocol.appendClientbound(ClientboundPackets1_17.ADD_ENTITY, wrapper -> {
55+
final int entityType = wrapper.get(Types.VAR_INT, 1);
56+
if (entityType != EntityTypes1_16_2.ITEM_FRAME.getId()) {
57+
return;
58+
}
59+
60+
// Older clients will ignore the data field and the server sets the item frame rotation by the yaw/pitch field inside the packet,
61+
// newer clients do the opposite and ignore yaw/pitch and use the data field from the packet.
62+
final int data = wrapper.get(Types.INT, 0);
63+
64+
float pitch = 0F;
65+
float yaw = 0F;
66+
switch (Math.abs(data % 6)) {
67+
case 0 /* down */ -> pitch = 90F;
68+
case 1 /* up */ -> pitch = -90F;
69+
case 2 /* north */ -> yaw = 180F;
70+
case 4 /* west */ -> yaw = 90F;
71+
case 5 /* east */ -> yaw = 270;
72+
}
73+
wrapper.set(Types.BYTE, 0, (byte) (pitch * 256F / 360F));
74+
wrapper.set(Types.BYTE, 1, (byte) (yaw * 256F / 360F));
75+
});
76+
5377
protocol.registerClientbound(ClientboundPackets1_17.REMOVE_ENTITY, ClientboundPackets1_16_2.REMOVE_ENTITIES, wrapper -> {
5478
int entityId = wrapper.read(Types.VAR_INT);
5579
tracker(wrapper.user()).removeEntity(entityId);

0 commit comments

Comments
 (0)