Download MECHA - Multiple Entity Collision Hitboxes API — Minecraft Mods — MetaMods
MECHA - Multiple Entity Collision Hitboxes API

MECHA - Multiple Entity Collision Hitboxes API

Active

Downloads

7

Last update

1 year ago

Versions

1.19.4 — 1.21.1
Client and server
Fabric
Game mechanics
Libraries
Utils

MECHA - Multiple Entity Collision Hitboxes API

This API provides developers with the ability to equip custom entities with multiple collision areas instead of the standard single one.

Getting Started

To connect the library, add the Modrinth repository to your build.gradle file and specify the appropriate mod version:

repositories {
    maven { url 'https://api.modrinth.com/maven' }
}

dependencies {
    modImplementation "maven.modrinth:mecha-api:VERSION_GOES_HERE"
}

Usage

In your custom entity class, implement the MultiCollidable interface and override the getColliders method to add additional collision areas.

Implementation Example

The following example code adds two collision areas to an entity, each the size of a slab:

public CustomEntity extends Entity implements MultiCollidable {
    public List<VoxelShape> getColliders() {
        List<VoxelShape> colliders = new ArrayList<>();
        BlockPos pos = this.blockPos();
        double x = pos.getX();
        double y = pos.getY();
        double z = pos.getZ();
        colliders.add(VoxelShapes.cuboid(x, y, z, x+1, y+0.5, z+1));
        colliders.add(VoxelShapes.cuboid(x, y+0.5, z, x+1, y+1, z+1));
        return colliders;
    }
}

Starting from version 0.1.2, a special entity type DynamicBoundingBoxEntity is available, which automatically adjusts its boundaries according to the list returned by the getColliders() method:

public CustomEntity extends DynamicBoundingBoxEntity {
    // The boundaries of this entity will dynamically change
    // to match the collision areas returned by this function
    @Override
    public List<VoxelShape> getColliders() { ... }
}
Project members
byteManiak

byteManiak

Developer

Created: 6 May 2024

ID: 14648