Skip to content

How to register your resources

Timmypote edited this page May 29, 2017 · 2 revisions

We are going to see how to register your resources (models and animations) with the CraftStudio API


Main Class

@Mod.EventBusSubscriber
@Mod(name = "TestMod", modid = Mod_Test.MODID)
public class Mod_Test
{
    public static final String MODID = "testmod";

    @SidedProxy(clientSide = "path.to.ClientProxy", serverSide = "path.to.CommonProxy")
    private static CommonProxy proxy;

    @Instance(Mod_Test.MODID)
    private static Mod_Test    instance;

    public static Mod_Test getInstance() {
        return Mod_Test.instance;
    }

    @SubscribeEvent
    @SideOnly(Side.CLIENT)
    public static void registerModels(RegistryEvent.Register<CSReadedModel> e) {
        Mod_Test.proxy.registerModels();
    }

    @SubscribeEvent
    @SideOnly(Side.CLIENT)
    public static void registerAnims(RegistryEvent.Register<CSReadedAnim> e) {
        Mod_Test.proxy.registerAnims();
    }
}

As you may seen, we need to add two methods:

 @SubscribeEvent
 @SideOnly(Side.CLIENT) 
 public static void registerModels(RegistryEvent.Register<CSReadedModel> e) {}

 @SubscribeEvent
 @SideOnly(Side.CLIENT)
 public static void registerAnimations(RegistryEvent.Register<CSReadedAnim> e) {}

These methods are used to register your resources in order to use them in your project. The same way we register a block, an item or an entity in the registry of forge.

Be sure that these methods are statics to register resources in the API !

Now, we need to create two same methods (for the name) in your proxy classes


Proxys

public class CommonProxy
{
    public void registerModels() {}

    public void registerAnims() {}

    // Other methods...
}
public class ClientProxy extends CommonProxy
{
    CSRegistryHelper registry = new CSRegistryHelper(Mod_Test.MODID);
   
    @Override
    public void registerModels() {
        super.registerModels();
        registry.register(ResourceType.MODEL, RenderType.ENTITY, "your_model");
    }

    @Override
    public void registerAnims() {
        super.registerAnims();
        registry.register(ResourceType.ANIM, RenderType.ENTITY, "your_animation");
    }
}

In the ClientProxy, Start to instaciate the CSRegistryHelper class and define your mod id in the constructor

And call register method to register (thx captain' obvious) your resources in the API

registry.register(resourceTypeIn, renderTypeIn, resourceIn);

resourceTypeIn define if your resource is a model or an animation with ResourceType.MODEL or ResourceType.ANIM

renderTypeIn define if your resource is a block or an entity with RenderType.BLOCK or RenderType.ENTITY

resourceIn the name of your resource in your mod assets


Manage Assets

Your resources needs to be in a special assets folder to be properly readed by the API.

  • assets
    • your_modid
      • craftstudio
        • animations
          • blocks
            • your_animation.csjsmodelanim
          • entity
            • your_animation.csjsmodelanim
        • models
          • blocks
            • your_animation.csjsmodel
          • entity
            • your_animation.csjsmodel

Tips: How to export CraftStudio resources

Clone this wiki locally