Class BlockCollisionProvider
- All Implemented Interfaces:
BoxBlockIterator.BoxIterationConsumer
A collider is cast into the world from a given start position along a vector. Potential block collisions, trigger events and damages are reported to caller
using a IBlockCollisionConsumer instance. A block with filler blocks is only processed once per call. For each trigger exactly one of the trigger
event callbacks is executed. Current active triggers are passed and updated using a provided IBlockTracker instance.
Collision contacts are not sorted by distance and are delivered in order as returned by BoxBlockIterator.
Collision processing can be terminated when a final collision is detected using any of the methods in IBlockCollisionConsumer returning
a IBlockCollisionConsumer.Result.
Notes: - For solid and empty blocks the damage, trigger and collision boxes are the block bounding boxes. - For fluid blocks trigger boxes are defined by the block bounding boxes. Damage and collisions are computed using the unit box with height vertical fill level. - Submerged fluid is processed as fluid block but no trigger block processing is performed. - A single block can cause collisions with multiple materials (e.g. submerged blocks) - A single block can report damage twice for the block and the submerge fluid - Collision with empty collision material is not reported when the empty space is part of a solid or fluid block (complexity of computing the empty sub-boxes)
- Since:
- 2020-06-25
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(long x, long y, long z) Called by the algorithm to report a block that is being hit by the AABB on the given direction.voidcast(World world, Box collider, org.joml.Vector3d pos, org.joml.Vector3d v, IBlockCollisionConsumer collisionConsumer, IBlockTracker activeTriggers, double collisionStop) Cast a box collider and report block collisions, triggers and damage.booleannext()Called when the current iteration step is done and the next block to hit is further away.voidsetReportOverlaps(boolean reportOverlaps) Enable or disable reporting of overlapping blocks.voidsetRequestedCollisionMaterials(int requestedCollisionMaterials)
-
Constructor Details
-
BlockCollisionProvider
public BlockCollisionProvider()
-
-
Method Details
-
setRequestedCollisionMaterials
public void setRequestedCollisionMaterials(int requestedCollisionMaterials) -
setReportOverlaps
public void setReportOverlaps(boolean reportOverlaps) Enable or disable reporting of overlapping blocks.Normally overlapping blocks are ignored. But for moving out of solid blocks or searching for jump landing positions they need to be reported.
- Parameters:
reportOverlaps- True to report overlapping blocks else ignore them.
-
next
public boolean next()Description copied from interface:BoxBlockIterator.BoxIterationConsumerCalled when the current iteration step is done and the next block to hit is further away.- Specified by:
nextin interfaceBoxBlockIterator.BoxIterationConsumer- Returns:
- TRUE if iteration should continue
-
accept
public boolean accept(long x, long y, long z) Description copied from interface:BoxBlockIterator.BoxIterationConsumerCalled by the algorithm to report a block that is being hit by the AABB on the given direction.- Specified by:
acceptin interfaceBoxBlockIterator.BoxIterationConsumer- Parameters:
x- X-Coordinate of blocky- Y-Coordinate of blockz- Z-Coordinate of block- Returns:
- TRUE if iteration should continue
-
cast
public void cast(@Nonnull World world, @Nonnull Box collider, @Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d v, @Nonnull IBlockCollisionConsumer collisionConsumer, @Nonnull IBlockTracker activeTriggers, double collisionStop) Cast a box collider and report block collisions, triggers and damage.- Parameters:
world- Worldcollider- Box used as colliderpos- Start position for boxv- Vector along the box is castcollisionConsumer- Instance to receive collision, trigger and damage eventsactiveTriggers-IBlockTrackerstoring currently active trigger blockcollisionStop- Relative distance factor tovto stop processing (between 0 and 1)
-