mirror of
https://github.com/Minestom/Minestom.git
synced 2024-06-26 06:24:54 +02:00
Reduce position packets when velocity is applied
This commit is contained in:
parent
88ec8ddffa
commit
e5903c23a3
|
@ -537,9 +537,6 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
refreshPosition(finalVelocityPosition, true);
|
refreshPosition(finalVelocityPosition, true);
|
||||||
if (!isSocketClient) {
|
|
||||||
synchronizePosition(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update velocity
|
// Update velocity
|
||||||
if (hasVelocity || !newVelocity.isZero()) {
|
if (hasVelocity || !newVelocity.isZero()) {
|
||||||
|
@ -1124,6 +1121,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||||
public void refreshPosition(@NotNull final Pos position, boolean ignoreView) {
|
public void refreshPosition(@NotNull final Pos position, boolean ignoreView) {
|
||||||
final var previousPosition = this.position;
|
final var previousPosition = this.position;
|
||||||
this.position = ignoreView ? previousPosition.withCoord(position) : position;
|
this.position = ignoreView ? previousPosition.withCoord(position) : position;
|
||||||
|
if (position.equals(lastSyncedPosition)) return;
|
||||||
if (!position.samePoint(previousPosition)) {
|
if (!position.samePoint(previousPosition)) {
|
||||||
refreshCoordinate(position);
|
refreshCoordinate(position);
|
||||||
}
|
}
|
||||||
|
@ -1133,9 +1131,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||||
final double distanceZ = Math.abs(position.z() - lastSyncedPosition.z());
|
final double distanceZ = Math.abs(position.z() - lastSyncedPosition.z());
|
||||||
final boolean positionChange = (distanceX + distanceY + distanceZ) > 0;
|
final boolean positionChange = (distanceX + distanceY + distanceZ) > 0;
|
||||||
if (distanceX > 8 || distanceY > 8 || distanceZ > 8) {
|
if (distanceX > 8 || distanceY > 8 || distanceZ > 8) {
|
||||||
synchronizePosition(true);
|
sendPacketToViewers(new EntityTeleportPacket(getEntityId(), position, isOnGround()));
|
||||||
// #synchronizePosition sets sync fields, it's safe to return
|
|
||||||
return;
|
|
||||||
} else if (positionChange && viewChange) {
|
} else if (positionChange && viewChange) {
|
||||||
sendPacketToViewers(EntityPositionAndRotationPacket.getPacket(getEntityId(), position,
|
sendPacketToViewers(EntityPositionAndRotationPacket.getPacket(getEntityId(), position,
|
||||||
lastSyncedPosition, isOnGround()));
|
lastSyncedPosition, isOnGround()));
|
||||||
|
@ -1147,6 +1143,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||||
sendPacketToViewers(new EntityHeadLookPacket(getEntityId(), position.yaw()));
|
sendPacketToViewers(new EntityHeadLookPacket(getEntityId(), position.yaw()));
|
||||||
sendPacketToViewers(new EntityRotationPacket(getEntityId(), position.yaw(), position.pitch(), onGround));
|
sendPacketToViewers(new EntityRotationPacket(getEntityId(), position.yaw(), position.pitch(), onGround));
|
||||||
}
|
}
|
||||||
|
this.lastAbsoluteSynchronizationTime = System.currentTimeMillis();
|
||||||
this.lastSyncedPosition = position;
|
this.lastSyncedPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user