Skip to content
Fx Morin edited this page Jul 16, 2024 · 7 revisions

MoreCulling has an API to allow mods to take full advantage of the extra performance.

Using JitPack + Gradle

Including the API in your project using Jitpack

  1. Head over to: https://jitpack.io/#fxmorin/MoreCulling
  2. Pick the version you want and select Get it
  3. Include the API using the link provided by JitPack. Should something look like this: modApi 'com.github.fxmorin:MoreCulling:LATEST'
  4. Reload Gradle and that's it, the API can now be used in your mod. Now you can follow the API Docs to use the API correctly

Use a Mixin Config Plugin to fix conflicts. MoreCulling uses conditional-mixin to simplify this task.

Using Custom block culling

Sounds like you want to continue using MoreCulling while also being able to use its culling API to boost the performance of your modded blocks. Well your in the right place, here you will find examples on how to use MoreCulling's API to perform custom culling on your blocks.
The main interface used for block culling is MoreBlockCulling found here it contains the base API for all block related culling methods.
These methods have JavaDoc explaining what they do, so instead I will mostly be showing examples.

Prevent culling against another block

This example shows how to use the cantCullAgainst() method to prevent a block from culling against other blocks. So this block wouldn't be able to cull against a block with the tag SPECIAL_MODE set to true and SpecialUtils.cullSpecialBlocks() returning false.

@Override
public boolean cantCullAgainst(BlockState state) {
    return state.has(SPECIAL_MODE) && state.get(SPECIAL_MODE) && !SpecialUtils.cullSpecialBlocks();
}

Custom face drawing

The MoreBlockCulling interface provides the method customShouldDrawFace(). This method has 3 possible return values: empty, true, or false. When empty (default), this method does nothing and lets MoreCulling run its own face culling. Although you are able to conditionally change this value to force your own results. Although this method is only used if usesCustomShouldDrawFace() return true.
Example from CullLessLeaves

@Override
public boolean usesCustomShouldDrawFace(BlockState state) {
    return CullLessLeaves.getConfig().enabled;
}

@Override
public Optional<Boolean> customShouldDrawFace(BlockView view, BlockState thisState, BlockState sideState, BlockPos thisPos, BlockPos sidePos, Direction side) {
    if (CullLessLeaves.shouldCullSide(view, thisPos, side)) {
        return Optional.of(false);
    }
    return Optional.empty();
}

Disable culling on your modded blocks

You can disable MoreCulling's custom culling on your modded blocks though MoreCulling's API. It is first recommended that you find the cause of any culling bugs before, and attempt to do the culling correctly instead of just disabling it. Easy instructions on how to fix your modded block culling
If you still want to disable culling on your block make your block implements MoreBlockCulling and add the following method:

@Override
public boolean shouldAttemptToCull(BlockState state) {
    return false;
}

This will prevent all of MoreCulling's custom culling from working on your block. Not Recommended

Fixing culling issues on modded blocks

Some modded blocks may not be culling correctly, so I will walk you through fixing that.

Opaque

If your block is Opaque, this means its a solid full block. Vanilla automatically tries culling against these blocks so MoreCulling does too.
To set your block as not Opaque, you can follow this fabric doc

Culling Shape

All blocks in Minecraft have a Culling Shape, its a VoxelShape you get from calling getCullingShape() on a block. By default this culling shape uses the outline shape, and by default the outline shape is a full cube. You need to make sure that your blocks culling shape matches the model correctly. If your outline shape does not match your model, make sure to set the culling shape manually to do this. Here's an example on how to set the culling shape:

private static final VoxelShape CULL_SHAPE = VoxelShapes.union( // each number is just the position in pixels
        Block.createCuboidShape(0.0, 2.0, 2.0, 16.0, 14.0, 14.0),
        Block.createCuboidShape(2.0, 0.0, 2.0, 14.0, 16.0, 14.0),
        Block.createCuboidShape(2.0, 2.0, 0.0, 14.0, 14.0, 16.0)
); // Example of a Chorus Flower cull shape

@Override
public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
    return CULL_SHAPE;
}

Leaves

Some leaves may look weird in your mod. Make sure that all your leaves extend vanilla's LeavesBlock if they should look and render the same. This allows MoreCulling to provide proper culling for them using its various leave culling techniques.
Another possible issue with leaves can be due to your custom leaves not being inside the minecraft:leaves tag key, make sure they are.

Doors

Much like leaves, make sure your doors are within the minecraft:doors tag key list, this will prevent them from being culled.