Events

Collision Events

There are two types of collisions events: BLOCK_COLLISION and ELEMENT_COLLISION You can register callbacks for them like so:

// Element V Terrain
ElementCollisionEvents.BLOCK_COLLISION.register((element, terrain, impulse) -> {
    if (element instanceof MyCustomPhysicsEntity) {
        if (terrain.getBlockState().getBlock().equals(Blocks.BRICKS)) {
            System.out.println("Collided with bricks!!");
        }
    }
});

// Element V Element
ElementCollisionEvents.ELEMENT_COLLISION.register((element1, element2, impulse) -> {
    if (element1 instanceof MyCustomPhysicsEntity && element2 instanceof MyCustomPhysicsEntity) {
        System.out.println("Element collision!!");
    }
});

Physics Space Events

There are four available physics space events: INIT, STEP, ELEMENT_ADDED, and ELEMENT_REMOVED. You can register callbacks for them like so:

PhysicsSpaceEvents.INIT.register(space -> {
    System.out.println("Initializing physics space!");
});

PhysicsSpaceEvents.STEP.register(space -> {
    System.out.println("Stepping physics space!");
});

PhysicsSpaceEvents.ELEMENT_ADDED.register((space, rigidBody) -> {
    System.out.println("Added a rigid body!");
});

PhysicsSpaceEvents.ELEMENT_REMOVED.register((space, rigidBody) -> {
    System.out.println("Removed a rigid body!");
});

Last updated