Class CollisionModule

All Implemented Interfaces:
CommandOwner

public class CollisionModule extends JavaPlugin
The Collision Module, which provides collision detection and response functionality for entities and blocks
  • Field Details

  • Constructor Details

    • CollisionModule

      public CollisionModule(@Nonnull JavaPluginInit init)
      Default Constructor for a CollisionModule instance.
      Parameters:
      init - The plugin initialization step for this plugin
  • Method Details

    • get

      public static CollisionModule get()
      Returns:
      the singleton instance of the CollisionModule plugin.
    • getConfig

      @Nonnull public CollisionModuleConfig getConfig()
      Returns:
      the configuration for the CollisionModule plugin.
    • getTangibleEntitySpatialResourceType

      public ResourceType<EntityStore, SpatialResource<Ref<EntityStore>, EntityStore>> getTangibleEntitySpatialResourceType()
      Returns:
      the resource type for the SpatialResource that contains all tangible entities for collision detection.
    • findCollisions

      public static boolean findCollisions(@Nonnull Box collider, @Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d v, @Nonnull CollisionResult result, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to find collisions for a moving box collider in the world.
      Parameters:
      collider - The box collider.
      pos - The position of the collider.
      v - The movement vector of the collider.
      result - The collision result to store the results in.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      true if the movement distance is considered far, false if it is considered short.
    • findCollisions

      public static boolean findCollisions(@Nonnull Box collider, @Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d v, boolean stopOnCollisionFound, @Nonnull CollisionResult result, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to find collisions for a moving box collider in the world.
      Parameters:
      collider - The box collider.
      pos - The position of the collider.
      v - The movement vector of the collider.
      stopOnCollisionFound - Whether to stop searching for collisions after the first one is found.
      result - The collision result to store the results in.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      true if the movement distance is considered far, false if it is considered short.
    • findBlockCollisionsIterative

      public static void findBlockCollisionsIterative(@Nonnull World world, @Nonnull Box collider, @Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d v, boolean stopOnCollisionFound, @Nonnull CollisionResult result)
      Called to find block collisions for a moving box collider in the world using an iterative approach.
      Parameters:
      world - The world to check for collisions in.
      collider - The box collider.
      pos - The position of the collider.
      v - The movement vector of the collider.
      stopOnCollisionFound - Whether to stop searching for collisions after the first one is found.
      result - The collision result to store the results in.
    • findCharacterCollisions

      public static void findCharacterCollisions(@Nonnull Box collider, @Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d v, @Nonnull CollisionResult result, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to find character collisions for a moving box collider in the world.
      Parameters:
      collider - The moving collider box.
      pos - The position of the collider.
      v - The movement vector of the collider.
      result - The collision result to store the results in.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
    • findBlockCollisionsShortDistance

      public static void findBlockCollisionsShortDistance(@Nonnull World world, @Nonnull Box collider, @Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d v, @Nonnull CollisionResult result)
      Called to find block collisions for a moving box collider in the world using a short distance approach.
      Parameters:
      world - The world to check for collisions in.
      collider - The box collider.
      pos - The position of the collider.
      v - The movement vector of the collider.
      result - The collision result to store the results in.
    • findIntersections

      public void findIntersections(@Nonnull World world, @Nonnull Box collider, @Nonnull org.joml.Vector3d pos, @Nonnull CollisionResult result, boolean triggerBlocks, boolean intersections)
      Called to find intersections for a box collider in the world.
      Parameters:
      world - The associated world.
      collider - The box collider.
      pos - The position of the collider.
      result - The collision result to store the results in.
      triggerBlocks - Whether to report trigger block intersections.
      intersections - Whether to report normal block intersections.
    • validatePosition

      public int validatePosition(@Nonnull World world, @Nonnull Box collider, @Nonnull org.joml.Vector3dc pos, @Nonnull CollisionResult result)
      Called to validate a position for a box collider in the world.
      Parameters:
      world - The associated world.
      collider - The box collider.
      pos - The position of the collider.
      result - The collision result to store the results in.
      Returns:
      the validation code.
    • validatePosition

      public <T> int validatePosition(@Nonnull World world, @Nonnull Box collider, @Nonnull org.joml.Vector3dc pos, int invalidBlockMaterials, @Nullable T t, @Nonnull CollisionFilter<BoxBlockIntersectionEvaluator, T> predicate, @Nonnull CollisionResult result)
      Called to validate a position for a box collider in the world.
      Type Parameters:
      T - The type of the extra data passed to the predicate.
      Parameters:
      world - The associated world.
      collider - The box collider.
      pos - The position of the collider.
      invalidBlockMaterials - The invalid block materials bitmask.
      t - The extra data passed to the predicate.
      predicate - The collision filter predicate.
      result - The collision result to store the results in.
      Returns:
      the validation code.
    • isBelowMovementThreshold

      public static boolean isBelowMovementThreshold(@Nonnull org.joml.Vector3d v)
      Check if a movement vector is below the movement threshold.
      Parameters:
      v - The movement vector.
      Returns:
      true if the movement vector is below the threshold, false otherwise.