Class PhysicsUtils
java.lang.Object
net.minestom.server.collision.PhysicsUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic PhysicsResultsimulateMovement(Pos entityPosition, Vec entityVelocityPerTick, BoundingBox entityBoundingBox, WorldBorder worldBorder, Block.Getter blockGetter, Aerodynamics aerodynamics, boolean entityNoGravity, boolean entityHasPhysics, boolean entityOnGround, boolean entityFlying, @Nullable PhysicsResult previousPhysicsResult) Simulate the entity's movement physicsstatic VecupdateVelocity(Pos entityPosition, Vec currentVelocity, Block.Getter blockGetter, Aerodynamics aerodynamics, boolean positionChanged, boolean entityFlying, boolean entityOnGround, boolean entityNoGravity) Calculates an updated velocity for an entity
-
Method Details
-
simulateMovement
public static PhysicsResult simulateMovement(Pos entityPosition, Vec entityVelocityPerTick, BoundingBox entityBoundingBox, WorldBorder worldBorder, Block.Getter blockGetter, Aerodynamics aerodynamics, boolean entityNoGravity, boolean entityHasPhysics, boolean entityOnGround, boolean entityFlying, @Nullable @Nullable PhysicsResult previousPhysicsResult) Simulate the entity's movement physicsThis is done by first attempting to move the entity forward with the current velocity passed in. Then adjusting the velocity by applying air resistance and friction.
- Parameters:
entityPosition- the current entity positionentityVelocityPerTick- the current entity velocity in blocks/tickentityBoundingBox- the current entity bounding boxworldBorder- the world border to test bounds againstblockGetter- the block getter to test block collisions againstaerodynamics- the current entity aerodynamicsentityNoGravity- whether the entity has gravityentityHasPhysics- whether the entity has physicsentityOnGround- whether the entity is on the groundentityFlying- whether the entity is flyingpreviousPhysicsResult- the physics result from the previous simulation or null- Returns:
- a
PhysicsResultcontaining the resulting physics state of this simulation
-
updateVelocity
public static Vec updateVelocity(Pos entityPosition, Vec currentVelocity, Block.Getter blockGetter, Aerodynamics aerodynamics, boolean positionChanged, boolean entityFlying, boolean entityOnGround, boolean entityNoGravity) Calculates an updated velocity for an entityIf the position has not changed then the x and z values will not be touched, and only gravity will be accounted for if the entity is not flying. Otherwise, the velocity will be adjusted by applying air resistance, gravity, and friction (only if the entity is on the ground).
- Parameters:
entityPosition- the current entity positioncurrentVelocity- the current entity velocity in blocks/tickblockGetter- the block getter to test block collisions againstaerodynamics- the current entity aerodynamicspositionChanged- whether the position changed for the entityentityFlying- whether the entity is flyingentityOnGround- whether the entity is on the groundentityNoGravity- whether the entity has gravity- Returns:
- the updated velocity or
Vec.ZEROif the entity is flying
-