Creating & Registering the Renderer
Once you've made your entity class and registered your EntityType, you can now create the renderer and register it.
Making the class
- Simple
- Advanced
Simple Renderer Class
By default, GeckoLib does not require a custom renderer class, and you can instead just pass a new instance of
GeoEntityRenderer when registering your renderer.
If you do not require any custom handling of your entity's rendering, this is the recommended approach.
E.G.
- Fabric
- Forge
- NeoForge
// Registering the renderer
context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY);
// Registering the renderer
context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY.get());
// Registering the renderer
context -> new GeoEntityRenderer<>(context, EntityRegistry.EXAMPLE_ENTITY.get());
Advanced Renderer Class
This option is for creating a standalone renderer class that can override methods for additional handling.
Green highlights show added or modified lines of code for each step.
To begin, let's create a renderer class that extends GeoEntityRenderer:
public class ExampleEntityRenderer extends GeoEntityRenderer {
}
Then, we'll need to add in the generic types that the renderer requires:
For more information on this, see The generic types section.
public class ExampleEntityRenderer<R extends EntityRenderState & GeoRenderState> extends GeoEntityRenderer<ExampleEntity, R> {
}
And then we add in the constructor, passing in the EntityType to automatically create the GeoModel:
public class ExampleEntityRenderer<R extends EntityRenderState & GeoRenderState> extends GeoEntityRenderer<ExampleEntity, R> {
public ExampleEntityRenderer(EntityRendererProvider.Context context, EntityType<ExampleEntity> entityType) {
super(context, entityType);
}
}
That's it! Now you need to register it.
The generic types
In step 2, we added in the generic types that the renderer requires.
But what are these generic types?
R- This is theRenderStatetype. By default, GeckoLib uses vanilla'sLivingEntityRenderState, combined with GeckoLib'sGeoRenderState. For more information on RenderStates, see the RenderStates page.ExampleEntity- This is your entity! Replace this with your entity's class name.
Registering the renderer
Once you have created your renderer class, you then need to register it. This differs depending on the modloader you are using.
Select your loader below for a link to that loader's documentation for registering entity renderers.
- Fabric
- Forge
- NeoForge
None exists :(
See the NeoForge tab for similar instructions
The asset files
If you followed the above instructions, GeckoLib will be looking for your asset files (.geo.json, .animation.json, .png)
in the /entity/ subdirectory, named the same as your entity's registered id.
For example, if your EntityType was registered as example_entity, your files should be:
- Model:
resources/assets/<mod_id>/geckolib/models/entity/example_entity.geo.json- Animations:
resources/assets/<mod_id>/geckolib/animations/entity/example_entity.animation.json- Texture:
resources/assets/<mod_id>/textures/entity/example_entity.png
Where <mod_id> is the id of your mod.
See the Placing the Files page for more information on where to place these files.