Skip to content

Commit 2360ea2

Browse files
committed
Fix 1.19->1.18 painting offsets
Fixes #964
1 parent 44819ea commit 2360ea2

2 files changed

Lines changed: 66 additions & 15 deletions

File tree

common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/EntityPacketRewriter1_19.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@
4040
import com.viaversion.viaversion.api.type.Types;
4141
import com.viaversion.viaversion.api.type.types.version.Types1_18;
4242
import com.viaversion.viaversion.api.type.types.version.Types1_19;
43+
import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet;
44+
import com.viaversion.viaversion.libs.fastutil.ints.IntSet;
4345
import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPackets1_18;
4446
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19;
4547
import com.viaversion.viaversion.util.Key;
4648
import com.viaversion.viaversion.util.TagUtil;
4749

4850
public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPackets1_19, Protocol1_19To1_18_2> {
4951

52+
private static final IntSet WIDE_PAINTINGS = IntOpenHashSet.of(
53+
7, 8, 9, 10, 11,
54+
14, 15, 16, 17, 18, 19, 20,
55+
21, 22, 23, 24, 25
56+
);
57+
5058
public EntityPacketRewriter1_19(final Protocol1_19To1_18_2 protocol) {
5159
super(protocol);
5260
}
@@ -89,7 +97,10 @@ public void register() {
8997
// The entity has been tracked, now we wait for the entity data packet
9098
final int entityId = wrapper.get(Types.VAR_INT, 0);
9199
final StoredEntityData entityData = tracker(wrapper.user()).entityData(entityId);
92-
final BlockPosition position = new BlockPosition(wrapper.get(Types.DOUBLE, 0).intValue(), wrapper.get(Types.DOUBLE, 1).intValue(), wrapper.get(Types.DOUBLE, 2).intValue());
100+
final int x = wrapper.get(Types.DOUBLE, 0).intValue();
101+
final int y = wrapper.get(Types.DOUBLE, 1).intValue();
102+
final int z = wrapper.get(Types.DOUBLE, 2).intValue();
103+
final BlockPosition position = new BlockPosition(x, y, z);
93104
entityData.put(new StoredPainting(entityId, wrapper.get(Types.UUID, 0), position, data));
94105
return;
95106
}
@@ -102,6 +113,31 @@ public void register() {
102113
}
103114
});
104115

116+
protocol.registerClientbound(ClientboundPackets1_19.TELEPORT_ENTITY, wrapper -> {
117+
final int entityId = wrapper.passthrough(Types.VAR_INT);
118+
if (tracker(wrapper.user()).entityType(entityId) != EntityTypes1_19.PAINTING) {
119+
return;
120+
}
121+
122+
final double x = wrapper.read(Types.DOUBLE);
123+
final double y = wrapper.read(Types.DOUBLE);
124+
final double z = wrapper.read(Types.DOUBLE);
125+
126+
final StoredEntityData entityData = tracker(wrapper.user()).entityDataIfPresent(entityId);
127+
final StoredPainting storedPainting = entityData != null ? entityData.get(StoredPainting.class) : null;
128+
// Presumably there is a more correct way of fixing this? Only north and east looking paintings with a width of >1 seem to be extra special
129+
if (storedPainting != null && (storedPainting.direction() == 2 || storedPainting.direction() == 3)
130+
&& WIDE_PAINTINGS.contains(storedPainting.type())) {
131+
wrapper.write(Types.DOUBLE, storedPainting.direction() == 2 ? x : x + 1);
132+
wrapper.write(Types.DOUBLE, y + 1);
133+
wrapper.write(Types.DOUBLE, storedPainting.direction() == 3 ? z : z + 1);
134+
} else {
135+
wrapper.write(Types.DOUBLE, x + 1);
136+
wrapper.write(Types.DOUBLE, y + 1);
137+
wrapper.write(Types.DOUBLE, z + 1);
138+
}
139+
});
140+
105141
protocol.registerClientbound(ClientboundPackets1_19.UPDATE_MOB_EFFECT, new PacketHandlers() {
106142
@Override
107143
public void register() {
@@ -327,12 +363,15 @@ protected void registerRewrites() {
327363
event.cancel();
328364

329365
final StoredEntityData entityData = tracker(event.user()).entityDataIfPresent(event.entityId());
330-
final StoredPainting storedPainting = entityData.remove(StoredPainting.class);
366+
final StoredPainting storedPainting = entityData != null ? entityData.get(StoredPainting.class) : null;
331367
if (storedPainting != null) {
368+
final int type = data.value();
369+
storedPainting.setType(type);
370+
332371
final PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_18.ADD_PAINTING, event.user());
333372
packet.write(Types.VAR_INT, storedPainting.entityId());
334373
packet.write(Types.UUID, storedPainting.uuid());
335-
packet.write(Types.VAR_INT, data.value());
374+
packet.write(Types.VAR_INT, type);
336375
packet.write(Types.BLOCK_POSITION1_14, storedPainting.position());
337376
packet.write(Types.BYTE, storedPainting.direction());
338377
try {

common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/storage/StoredPainting.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,32 @@
2222
import java.util.UUID;
2323

2424
public final class StoredPainting implements StorableObject {
25-
2625
private final int entityId;
2726
private final UUID uuid;
2827
private final BlockPosition position;
2928
private final byte direction;
29+
private int type;
3030

31-
public StoredPainting(final int entityId, final UUID uuid, final BlockPosition position, final int direction3d) {
31+
public StoredPainting(int entityId, UUID uuid, BlockPosition position, byte direction) {
3232
this.entityId = entityId;
3333
this.uuid = uuid;
3434
this.position = position;
35-
this.direction = to2dDirection(direction3d);
35+
this.direction = direction;
36+
}
37+
38+
public StoredPainting(final int entityId, final UUID uuid, final BlockPosition position, final int direction) {
39+
this(entityId, uuid, position, to2dDirection(direction));
40+
}
41+
42+
private static byte to2dDirection(int direction) {
43+
return switch (direction) {
44+
case 0, 1 -> -1; // No worky
45+
case 2 -> 2;
46+
case 3 -> 0;
47+
case 4 -> 1;
48+
case 5 -> 3;
49+
default -> throw new IllegalArgumentException("Invalid direction: " + direction);
50+
};
3651
}
3752

3853
public int entityId() {
@@ -51,14 +66,11 @@ public byte direction() {
5166
return direction;
5267
}
5368

54-
private byte to2dDirection(int direction) {
55-
return switch (direction) {
56-
case 0, 1 -> -1; // No worky
57-
case 2 -> 2;
58-
case 3 -> 0;
59-
case 4 -> 1;
60-
case 5 -> 3;
61-
default -> throw new IllegalArgumentException("Invalid direction: " + direction);
62-
};
69+
public int type() {
70+
return type;
71+
}
72+
73+
public void setType(final int type) {
74+
this.type = type;
6375
}
6476
}

0 commit comments

Comments
 (0)