Obsidian API Tutorial #2 – Resources – All versions

<< PreviousAll tutorialsNext >>

Let's get resourceful

So we’ve got The API ready, the next step is to import the resources that we’ve made using the animator. The video for this tutorial can be found here.

Prerequisites

You need to have setup the API as per the previous tutorial, as well as having a fully fleshed main mod class as per the tutorial source.

So what resources do we need?

There are two types of resources that the API makes use of – models and animations. Model files have .obm extensions (Obsidian Model) and animation files have .oba extensions (Obsidian Animation). Both are created by the animator: Obsidian Model files are created from the Tabula models, and you save Obsidian Animation files when you animate. You’ll need at least one model and animation file to complete these tutorials, so if you haven’t already, get animating!

Adding resources to the mod assets

I’m hoping you’re familiar with adding assets to Minecraft mods, if not go investigate. I like having two separate folders, one for animations and one for models. Create new folders if you wish and then drop the relevant files in there. Check the source project structure if you’re unsure where to put them.

Once the files are copied into the workspace, we need to extract the texture file from the Obsidian Model file. This is because you can’t extract the file via code once the mod is packed into a jar (it just gets messy). The Obsidian Model files are actually just zip files with a different extension, so you can open them with WinRAR (other archiving tools are available). There will be a texture.png file inside – extract it to the same assets folder your model is in, and rename it to match the model file, e.g. Saiga.obm and Saiga.png.

Registering animations

To reference our Obsidian Animation resources, we can use ResourceLocations, just like getting textures. I like defining mine as private variables at the top of the class where I need them:

private ResourceLocation saigaWalk = new ResourceLocation("mod_api_tutorial:animations/Walk.oba");

Animations are registered in the CommonProxy using the AnimationRegistry, which is part of the API. For good code structure, I like having all my animation processing in a single method and calling that from the proxy’s init method. All we’re going to do in this tutorial is initialise the AnimationRegistry:

public void registerAnimations() {
    AnimationRegistry.init();
}

We’ll make use of our new animation resources later, there are some other things we need to do first. The full CommonProxy class will be at the end of this tutorial.

Registering the texture and model 

The texture and model resources only need to be used on the client side, so we’ll register them in the ClientProxy. Add the required ResourceLocations to the top of the class as in the CommonProxy, and that’ll do for now.

Keeping it short and sweet

That’s everything for this tutorial, it’s a tad on the short side but it’s better than having a super long tutorial combining this one and the next. We’ll look at actually using our resources next time.

<< PreviousAll tutorialsNext >>

Edited files

CommonProxy

public class CommonProxy {

    private ResourceLocation saigaWalk = new ResourceLocation("mod_api_tutorial:animations/Walk.oba");
    private ResourceLocation saigaIdle = new ResourceLocation("mod_api_tutorial:animations/SaigaIdle.oba");
   
    public void init()
    {  
        ModEntities.registerEntities();
        registerRendering();
        registerAnimations();
    }

    public void registerRendering() {}
   
    public void registerAnimations() {
        AnimationRegistry.init();
    }  
}

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()
    {
        RenderSaiga saigaRenderer = new RenderSaiga(new ModelSaiga());
        RenderingRegistry.registerEntityRenderingHandler(EntitySaiga.class, saigaRenderer);
    }
}

Leave a Reply

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