mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-18 21:32:56 +01:00
fix: projectile entities positions becoming desynced from the client
This commit is contained in:
parent
fe8a230abb
commit
5bf4b4445a
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user