mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-27 14:13:24 +02:00
Limit the number of velocity packet used for entities
This commit is contained in:
parent
9775262c6a
commit
e0c8e94bc1
@ -489,7 +489,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
||||
// Gravity force
|
||||
final double gravityY = !noGravity ? Math.min(
|
||||
gravityDragPerTick + (gravityAcceleration * (double) gravityTickCount),
|
||||
gravityTerminalVelocity) : 0f;
|
||||
gravityTerminalVelocity) : 0;
|
||||
|
||||
final Vector deltaPos = new Vector(
|
||||
getVelocity().getX() / tps,
|
||||
@ -515,7 +515,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
||||
|
||||
|
||||
// Update velocity
|
||||
{
|
||||
if (hasVelocity() || !newVelocityOut.isZero()) {
|
||||
this.velocity.copy(newVelocityOut);
|
||||
this.velocity.multiply(tps);
|
||||
|
||||
@ -544,6 +544,10 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
||||
|
||||
this.velocity.setX(velocity.getX() * drag);
|
||||
this.velocity.setZ(velocity.getZ() * drag);
|
||||
|
||||
if (velocity.equals(new Vector())) {
|
||||
this.velocity.zero();
|
||||
}
|
||||
}
|
||||
|
||||
// Synchronization and packets...
|
||||
@ -809,9 +813,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
||||
* @return true if velocity is not set to 0
|
||||
*/
|
||||
public boolean hasVelocity() {
|
||||
return velocity.getX() != 0 ||
|
||||
velocity.getY() != 0 ||
|
||||
velocity.getZ() != 0;
|
||||
return !velocity.isZero();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,6 +296,12 @@ public class Vector implements PublicCloneable<Vector> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isZero() {
|
||||
return getX() == 0 &&
|
||||
getY() == 0 &&
|
||||
getZ() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if a vector is normalized
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user