Skip to content

Commit ace97c5

Browse files
committed
Better method
1 parent 52eb07d commit ace97c5

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

common/src/main/java/com/viaversion/viarewind/protocol/v1_9to1_8/rewriter/EntityPacketRewriter1_9.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,19 @@ public void register() {
454454
}
455455
});
456456

457+
// Passthrough except while a potion spawn is held - then folded into it
458+
protocol.registerClientbound(ClientboundPackets1_9.SET_ENTITY_MOTION, wrapper -> {
459+
final int entityId = wrapper.passthrough(Types.VAR_INT);
460+
final EntityTracker1_9 tracker = tracker(wrapper.user());
461+
final EntityTracker1_9.PotionSpawn pending = tracker.getPendingPotionSpawns().get(entityId);
462+
if (pending == null) {
463+
return;
464+
}
465+
tracker.getPendingPotionSpawns().put(entityId,
466+
pending.withVelocity(wrapper.read(Types.SHORT), wrapper.read(Types.SHORT), wrapper.read(Types.SHORT)));
467+
wrapper.cancel();
468+
});
469+
457470
protocol.registerClientbound(ClientboundPackets1_9.TELEPORT_ENTITY, new PacketHandlers() {
458471
@Override
459472
public void register() {
@@ -468,6 +481,14 @@ public void register() {
468481
final int entityId = wrapper.get(Types.VAR_INT, 0);
469482

470483
final EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
484+
final EntityTracker1_9.PotionSpawn pending = tracker.getPendingPotionSpawns().get(entityId);
485+
if (pending != null) {
486+
tracker.getPendingPotionSpawns().put(entityId, pending.withPosition(
487+
wrapper.get(Types.INT, 0), wrapper.get(Types.INT, 1), wrapper.get(Types.INT, 2),
488+
wrapper.get(Types.BYTE, 1), wrapper.get(Types.BYTE, 0)));
489+
wrapper.cancel();
490+
return;
491+
}
471492
if (tracker.entityType(entityId) == EntityTypes1_9.EntityType.BOAT) {
472493
byte yaw = wrapper.get(Types.BYTE, 0);
473494
yaw -= 64;

common/src/main/java/com/viaversion/viarewind/protocol/v1_9to1_8/storage/EntityTracker1_9.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,16 @@ public Int2ObjectMap<PotionSpawn> getPendingPotionSpawns() {
9696
return pendingPotionSpawns;
9797
}
9898

99-
/** Spawn packet values of a thrown potion, held until its item entity data supplies the 1.8 object data. */
99+
/** Spawn packet values of a thrown potion, held until its item entity data supplies the 1.8 object data.
100+
* Motion/teleports arriving while held are folded in - the released spawn carries the latest state. */
100101
public record PotionSpawn(int x, int y, int z, byte pitch, byte yaw, short velocityX, short velocityY, short velocityZ) {
102+
103+
public PotionSpawn withPosition(int x, int y, int z, byte pitch, byte yaw) {
104+
return new PotionSpawn(x, y, z, pitch, yaw, velocityX, velocityY, velocityZ);
105+
}
106+
107+
public PotionSpawn withVelocity(short velocityX, short velocityY, short velocityZ) {
108+
return new PotionSpawn(x, y, z, pitch, yaw, velocityX, velocityY, velocityZ);
109+
}
101110
}
102111
}

0 commit comments

Comments
 (0)