fix: projectile entities positions becoming desynced from the client

This commit is contained in:
DeidaraMC 2024-04-30 20:32:39 -04:00 committed by iam
parent fe8a230abb
commit 5bf4b4445a
2 changed files with 3 additions and 6 deletions

View File

@ -580,6 +580,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
// Scheduled synchronization
if (vehicle == null && ticks >= nextSynchronizationTick) {
synchronizePosition();
sendPacketToViewers(getVelocityPacket());
}
// End of tick scheduled tasks
this.scheduler.processTickEnd();
@ -602,11 +603,9 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
velocity = physicsResult.newVelocity().mul(ServerFlag.SERVER_TICKS_PER_SECOND);
onGround = physicsResult.isOnGround();
boolean shouldSendVelocity = !entityIsPlayer && hasVelocity();
if (!PlayerUtils.isSocketClient(this)) {
refreshPosition(physicsResult.newPosition(), true, !SYNCHRONIZE_ONLY_ENTITIES.contains(entityType));
if (shouldSendVelocity) sendPacketToViewers(getVelocityPacket());
}
}

View File

@ -166,8 +166,6 @@ public class EntityVelocityIntegrationTest {
@Test
public void countVelocityPackets(Env env) {
final int VELOCITY_UPDATE_INTERVAL = 1;
var instance = env.createFlatInstance();
var viewerConnection = env.createConnection();
viewerConnection.connect(instance, new Pos(1, 40, 1)).join();
@ -177,11 +175,11 @@ public class EntityVelocityIntegrationTest {
env.tick(); // Tick because the entity is in the air, they'll send velocity from gravity
AtomicInteger i = new AtomicInteger();
BooleanSupplier tickLoopCondition = () -> i.getAndIncrement() < Math.max(VELOCITY_UPDATE_INTERVAL, 1);
BooleanSupplier tickLoopCondition = () -> i.getAndIncrement() < Math.max(entity.getSynchronizationTicks() - 1, 19);
var tracker = viewerConnection.trackIncoming(EntityVelocityPacket.class);
env.tickWhile(tickLoopCondition, null);
tracker.assertEmpty(); // Verify no updates are sent while the entity is not moving
tracker.assertEmpty(); // Verify no updates are sent while the entity is not being synchronized
entity.setVelocity(new Vec(0, 5, 0));
tracker = viewerConnection.trackIncoming(EntityVelocityPacket.class);