Skip to content

Setup instructions

DarkPred edited this page Oct 8, 2024 · 1 revision

Adding the dependency

Add the following repo:
https://dl.cloudsmith.io/public/darkpred-mods/more-hitboxes/maven/
and artifact: com.github.darkpred.morehitboxes:morehitboxes-${loader}-${minecraft_version}:${more_hitboxes_version}
to your build.gradle. Available loaders are fabric, forge and common(for multi loader setups)

Setting up the hitboxes

To set up the hitboxes for a mob you first need to implement the correct interface and create the HitboxData.

public class Example extends Mob implements MultiPartEntity<Example> {
    private final EntityHitboxData<Prehistoric> hitboxData = EntityHitboxDataFactory.create(this);

    @Override
    public EntityHitboxData<Prehistoric> getEntityHitboxData() {
        return hitboxData;
    }
}

To add the hitboxes, create a json file at data/{modId}/hitboxes/{entityTypeKey}.json. Here a hitbox can be created by defining the width, height and local position(bottom center). Using the Blockbench plugin can help with this process.

{
    "elements": [
        {
            "name": "body",
            "pos": [0, 0, 0],
            "width": 17.6,
            "height": 20.8
        },
        {
            "name": "head",
            "pos": [0, 13.4, 15.8],
            "width": 11.2,
            "height": 8
        }
    ]
}

GeckoLib support

To attach the hitboxes to GeckoLib animations implement the GeckoLib interface instead.

public class GeckoLibExample extends Mob implements GeckoLibMultiPartEntity<Example> {
    private final EntityHitboxData<Prehistoric> hitboxData = EntityHitboxDataFactory.create(this);

    @Override
    public EntityHitboxData<Prehistoric> getEntityHitboxData() {
        return hitboxData;
    }
}

To have the animation override the static position, first add an (ideally) empty bone to the model and reference its name in the json file.

{
    "elements": [
        {
            "name": "body",
            "pos": [0, 0, 0],
            "width": 17.6,
            "height": 20.8,
            "ref": "body_hitbox"
        },
        {
            "name": "head",
            "pos": [0, 13.4, 15.8],
            "width": 11.2,
            "height": 8,
            "ref": "head_hitbox"
        }
    ]
}

For GeckoLib 3 you will also have to replicate the following code in your entity renderer:

@Override
public void render(GeoModel model, T animatable, float partialTick, RenderType type, PoseStack poseStack, MultiBufferSource bufferSource, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
    super.render(model, animatable, partialTick, type, poseStack, bufferSource, buffer, packedLight, packedOverlay, red, green, blue, alpha);
    if (this instanceof MultiPartGeoEntityRenderer renderer) {
        renderer.updateTickForEntity(animatable);
    }
}

Additional info

More information can be found in the javadoc.

Clone this wiki locally