Fabric API

Fabric API

108M Downloads

Add tree types support to Object Builders API

kanpov opened this issue ยท 5 comments

commented

Hello Fabric Team!

In the process of creating my new tutorial on the Fabric Wiki about trees, I discovered that Fabric API currently lacks the functionality to create TrunkPlacerTypes, FoliagePlacerTypes, TreeDecoratorTypes, BlockStateProviderTypes and additionally IntProviderTypes without possible conflicts due to using the minecraft namespace.

These things are required for creating your own TrunkPlacers, FoliagePlacers, TreeDecorators, BlockStateProviders and IntProviders.
Unfortunately, the constructors are protected, and you have to use access wideners (highly not recommended) or mixin invokers.

Here's an example which I used in my tutorial for TrunkPlacerTypes:

@Mixin(TrunkPlacerType.class)
public interface TrunkPlacerTypeInvoker {
    @Invoker
    static <TTrunkPlacer extends TrunkPlacer> TrunkPlacerType<TTrunkPlacer> invokeRegister(String id, Codec<TTrunkPlacer> codec) {
        throw new AssertionError();
    }
}
public static final TrunkPlacerType<RichTrunkPlacer> RICH_TRUNK_PLACER = TrunkPlacerTypeInvoker.invokeRegister("rich_trunk_placer", RichTrunkPlacer.CODEC);

It would be great if we had an API to do this to reduce the usage of mixins in mods.
I could make a PR implementing this, though I haven't had any experience in creating and documenting APIs yet.

Thanks for your attention!

commented

I think this has been addressed by the transitive access widener module by now.

commented

There is no need to use an access widener, you can just create a new class that extends it? I havent done a huge amount with trees but TechReborn's rubber tree is done easily without any mixins.

commented

I'll update my tutorial with your method. Thanks!

commented

Unfortunately, that solution didn't work since the constructor has private access, not protected, so it's impossible to inherit from the class.

commented

Also the TechReborn tree extends from Decorator, not TreeDecorator