Obsidian API Tutorial #3a – Entity Shadow Size and Scale – v0.2.1+

<< PreviousAll tutorialsNext >>

Let's customise the entities

As a further extension to creating entities, we can customise their shadow size and scale. This is only available for the Obsidian API v0.2.1 and beyond.

Prerequisites

You’ll need at least one entity already set up.

Shadow size

This is a really quick fix, it should have been in from the start… In your entity render class, you can now call the super constructor with a shadow size argument. Previously you would have had 

public RenderSaiga(ModelSaiga saiga)
{
    super(saiga);
}

but now the line super(saiga); can become

super(saiga, 0.8F);

where the second parameter is the shadow size. 

Model scale

You can now tweak the size of your model via the API. This is more of a temporary fix until properly model scaling is done when importing Tabula models, but it is still a useful alternative. To change the model scale, you need to change code in the ClientProxy. Previously, the line where you create the model renderer would look something like this:

RenderSaiga saigaRenderer = new RenderSaiga(FileLoader.loadModelFromResources("saiga", saigaModel, saigaTexture, ModelSaiga.class));

To change the model scale, we need to have direct access to the model object. We can then call setModelScale(float scale) on the model object to change the scale:

ModelSaiga modelSaiga = FileLoader.loadModelFromResources("saiga", saigaModel, saigaTexture, ModelSaiga.class);
modelSaiga.setModelScale(0.8F);
RenderSaiga saigaRenderer = new RenderSaiga(modelSaiga);

That will reduce the size of the model to 80% of what it was.

Easy right?

Hopefully that was easy to do! Just a little add on if you needed it!

<< PreviousAll tutorialsNext >>

Edited files

RenderSaiga

public class RenderSaiga extends RenderAnimated {

    public RenderSaiga(ModelSaiga saiga) {
        super(saiga, 0.8F);
    }
}

ClientProxy

public class ClientProxy extends CommonProxy {

    private ResourceLocation saigaModel = new ResourceLocation("mod_api_tutorial:models/Saiga.obm");
    private ResourceLocation saigaTexture = new ResourceLocation("mod_api_tutorial:models/Saiga.png");

    public void registerRendering() {
        ModelSaiga modelSaiga = FileLoader.loadModelFromResources("saiga", saigaModel, saigaTexture, ModelSaiga.class);
        modelSaiga.setModelScale(0.8F);
        RenderSaiga saigaRenderer = new RenderSaiga(modelSaiga);
        RenderingRegistry.registerEntityRenderingHandler(EntitySaiga.class, saigaRenderer);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *