Registering Partial Models - Rabbitminers/Extended-Bogeys GitHub Wiki

What are partial models?

Partial models allow for multiple parts to be combined into one model while being able to be positioned and rotated individually. This is very useful for bogeys so the wheels can spin without having to spin the whole thing.

Registering bogey models

PartialModels must be initialized during FMLClientSetupEvent, Once ModelBakeEvent finishes, all PartialModels (with valid modelLocations) will have their bakedModel fields populated. Attempting to create a PartialModel after ModelRegistryEvent will cause an error. So partial models must be registered on startup and only client side.

First create an asResource method in your mods Entry Point class (the one annotated with @Mod) like so in order to register partial assets:

public static ResourceLocation asResource(String path) {
    return new ResourceLocation(MODID, path);
}

Next, create a class to define your partial models within like so:

public class BogeyPartials {
    // Note - these files must all be lower case

    public static final PartialModel
        EXAMPLE_WHEELS = block("example_style/wheels"),
        EXAMPLE_FRAME = block("example_style/frame"),
    ;

    private static PartialModel block(String path) {
        return new PartialModel(CustomBogeyStyleDemonstration.asResource("block/" + path));
    }

    public static void init() {
        // init static fields
    }
}

This will load two .json models from the resources/model/block/ directory, we reccomend you use .obj models instead of just .json for instructions on how to load those read Here

To register these partials on client initialisation call the init method like so:

@Mod(CustomBogeyStyleDemonstration.MODID)
public class CustomBogeyStyleDemonstration {
    public static final String MODID = "demo";
    
    public CustomBogeyStyleDemonstration() {
        IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
        DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
                () -> BogeyPartials::init);
        MinecraftForge.EVENT_BUS.register(this);
    }
    
    public static ResourceLocation asResource(String path) {
        return new ResourceLocation(MODID, path);
    }
}

This will call the init method in the BogeyPartials class causing the Partial Models to load for the client, they can henceforth be accessed through BogeyPartials.[ModelName], this will be very useful when rendering your bogeys