java.lang.Object
net.minestom.server.collision.CollisionUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Pos
applyWorldBorder
(WorldBorder worldBorder, Pos currentPosition, Pos newPosition) Applies world border collision.static PhysicsResult
blocklessCollision
(Pos entityPosition, Vec entityVelocity) Simulate the entity's collision physics as if the world had no blocksstatic Entity
canPlaceBlockAt
(Instance instance, Point blockPos, Block b) static Collection
<EntityCollisionResult> checkEntityCollisions
(Entity entity, Vec velocity, double extendRadius, Function<Entity, Boolean> entityFilter, @Nullable PhysicsResult physicsResult) Checks for entity collisionsstatic Collection
<EntityCollisionResult> checkEntityCollisions
(Instance instance, BoundingBox boundingBox, Point pos, Vec velocity, double extendRadius, Function<Entity, Boolean> entityFilter, @Nullable PhysicsResult physicsResult) Checks for entity collisionsstatic PhysicsResult
handlePhysics
(Entity entity, Vec entityVelocity) static PhysicsResult
handlePhysics
(Entity entity, Vec entityVelocity, @Nullable PhysicsResult lastPhysicsResult) Moves an entity with physics applied (ie checking against blocks)static PhysicsResult
handlePhysics
(Entity entity, Vec entityVelocity, @Nullable PhysicsResult lastPhysicsResult, boolean singleCollision) Moves an entity with physics applied (ie checking against blocks)static PhysicsResult
handlePhysics
(Block.Getter blockGetter, BoundingBox boundingBox, Pos position, Vec velocity, @Nullable PhysicsResult lastPhysicsResult, boolean singleCollision) Moves bounding box with physics applied (ie checking against blocks)static PhysicsResult
handlePhysics
(Instance instance, @Nullable Chunk chunk, BoundingBox boundingBox, Pos position, Vec velocity, @Nullable PhysicsResult lastPhysicsResult, boolean singleCollision) Moves bounding box with physics applied (ie checking against blocks)static boolean
isLineOfSightReachingShape
(Instance instance, @Nullable Chunk chunk, Point start, Point end, Shape shape) Checks whether shape is reachable by the given line of sight (ie there are no blocks colliding with it).static Shape
parseBlockShape
(Map<Object, Object> internCache, String collision, String occlusion, boolean occludes, byte lightEmission)
-
Constructor Details
-
CollisionUtils
public CollisionUtils()
-
-
Method Details
-
handlePhysics
public static PhysicsResult handlePhysics(Entity entity, Vec entityVelocity, @Nullable @Nullable PhysicsResult lastPhysicsResult, boolean singleCollision) Moves an entity with physics applied (ie checking against blocks)Works by getting all the full blocks that an entity could interact with. All bounding boxes inside the full blocks are checked for collisions with the entity.
- Parameters:
entity
- the entity to moveentityVelocity
- the velocity of the entitylastPhysicsResult
- the last physics result, can be nullsingleCollision
- if the entity should only collide with one block- Returns:
- the result of physics simulation
-
checkEntityCollisions
public static Collection<EntityCollisionResult> checkEntityCollisions(Instance instance, BoundingBox boundingBox, Point pos, Vec velocity, double extendRadius, Function<Entity, Boolean> entityFilter, @Nullable @Nullable PhysicsResult physicsResult) Checks for entity collisions- Parameters:
velocity
- the velocity of the entityextendRadius
- the largest entity bounding box we can collide with Measured from bottom center to top corner This is used to extend the search radius for entities we collide with For players this is (0.3^2 + 0.3^2 + 1.8^2) ^ (1/3) ~= 1.51
-
checkEntityCollisions
public static Collection<EntityCollisionResult> checkEntityCollisions(Entity entity, Vec velocity, double extendRadius, Function<Entity, Boolean> entityFilter, @Nullable @Nullable PhysicsResult physicsResult) Checks for entity collisions- Parameters:
entity
- the entity to check collisions forvelocity
- the velocity of the entityextendRadius
- the largest entity bounding box we can collide withentityFilter
- the entity filterphysicsResult
- optional physics result- Returns:
- the entity collision results
-
handlePhysics
public static PhysicsResult handlePhysics(Entity entity, Vec entityVelocity, @Nullable @Nullable PhysicsResult lastPhysicsResult) Moves an entity with physics applied (ie checking against blocks)Works by getting all the full blocks that an entity could interact with. All bounding boxes inside the full blocks are checked for collisions with the entity.
- Parameters:
entity
- the entity to moveentityVelocity
- the velocity of the entitylastPhysicsResult
- the last physics result, can be null- Returns:
- the result of physics simulation
-
handlePhysics
public static PhysicsResult handlePhysics(Instance instance, @Nullable @Nullable Chunk chunk, BoundingBox boundingBox, Pos position, Vec velocity, @Nullable @Nullable PhysicsResult lastPhysicsResult, boolean singleCollision) Moves bounding box with physics applied (ie checking against blocks)Works by getting all the full blocks that a bounding box could interact with. All bounding boxes inside the full blocks are checked for collisions with the given bounding box.
- Parameters:
boundingBox
- the bounding box to move- Returns:
- the result of physics simulation
-
handlePhysics
@Internal public static PhysicsResult handlePhysics(Block.Getter blockGetter, BoundingBox boundingBox, Pos position, Vec velocity, @Nullable @Nullable PhysicsResult lastPhysicsResult, boolean singleCollision) Moves bounding box with physics applied (ie checking against blocks)Works by getting all the full blocks that a bounding box could interact with. All bounding boxes inside the full blocks are checked for collisions with the given bounding box.
- Parameters:
blockGetter
- the block getter to check collisions against, ensure block access is synchronized- Returns:
- the result of physics simulation
-
isLineOfSightReachingShape
public static boolean isLineOfSightReachingShape(Instance instance, @Nullable @Nullable Chunk chunk, Point start, Point end, Shape shape) Checks whether shape is reachable by the given line of sight (ie there are no blocks colliding with it).- Parameters:
instance
- the instance.chunk
- optional chunk reference for speedup purposes.start
- start of the line of sight.end
- end of the line of sight.shape
- shape to check.- Returns:
- true is shape is reachable by the given line of sight; false otherwise.
-
handlePhysics
-
canPlaceBlockAt
-
applyWorldBorder
Applies world border collision.- Parameters:
worldBorder
- the world bordercurrentPosition
- the current positionnewPosition
- the future target position- Returns:
- the position with the world border collision applied (can be
newPosition
if not changed)
-
parseBlockShape
-
blocklessCollision
Simulate the entity's collision physics as if the world had no blocks- Parameters:
entityPosition
- the position of the entityentityVelocity
- the velocity of the entity- Returns:
- the result of physics simulation
-