4040import com .viaversion .viaversion .api .type .Types ;
4141import com .viaversion .viaversion .api .type .types .version .Types1_18 ;
4242import 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 ;
4345import com .viaversion .viaversion .protocols .v1_17_1to1_18 .packet .ClientboundPackets1_18 ;
4446import com .viaversion .viaversion .protocols .v1_18_2to1_19 .packet .ClientboundPackets1_19 ;
4547import com .viaversion .viaversion .util .Key ;
4648import com .viaversion .viaversion .util .TagUtil ;
4749
4850public 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 {
0 commit comments