Skip to content

Tabula model loader

iLexiconn edited this page Mar 26, 2016 · 1 revision

Tabula model loader

What is it?

The Tabula Model Loader allows you to load Tabula models into your mod, similar to how you would load a texture. Using this, there is no need to export your models to .java files from Tabula.

Loading a model

Firstly, you will need to load a TabulaModelContainer, a basic container of a Tabula JSON-file. This can be done by calling:

TabulaModelContainer container = TabulaModelHandler.INSTANCE.loadTabulaModel("assets/<modid>/<pathtoyourmodel>");

Be warned, this method can throw an IOException if LLibrary can't load the model, so be sure to handle that exception. Now that you have a TabulaModelContainer, you can create a TabulaModel object. The TabulaModel object is what you will use for rendering your model. It is pretty much the same thing as an exported .java file from Tabula.

You can create a TabulaModel object like this:

ModelBase model = new TabulaModel(container);

As said previously, this is the same as an exported .java file, so you could either use java model.render(...); with it, or if you are inheriting RenderLiving in your Render class, you can pass it in as a parameter to the super constructor similarly to this:

public RenderClass(RenderManager renderManager) throws IOException {
    super(renderManager, new TabulaModel(TabulaModelHandler.INSTANCE.loadTabulaModel("assets/<modid>/<pathtoyourmodel>")));
}

Attaching an Animator to your model

Because you don't have your own class that extends ModelBase that you can edit, you can't override the setRotationAngles method to animate your model. Luckily, LLibrary's got you covered. When creating a TabulaModel, you can optionally pass in an ITabulaModelAnimator object. Firstly, you'll want to create a class that implements ITabulaModelAnimator, here is an example:

public class ExampleModelAnimator implements ITabulaModelAnimator<TestEntity> {
    @Override
    void setRotationAngles(TabulaModel model, TestEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float rotationYaw, float rotationPitch, float scale) {
        // Animation code goes here
    }
}

Then when creating your TabulaModel object...

new TabulaModel(container, new ExampleModelAnimator());

Now, to animate your model you'll need an instance of each model box, or ModelRenderer. You can access these by calling:

AdvancedModelRenderer testBox = model.getCube("Test Box");

Note that the parameter to getCube() is the name given in Tabula, so it can have spaces and other characters. Also note that the AdvancedModelRenderer is a special ModelRenderer made by LLibrary that allows for advanced animations and the TabulaModel is an instance of AdvancedModelBase, which the AdvancedModelRenderer is dependent on. There is currently no wiki page about it, but there will be soon!

Clone this wiki locally