Skip to main content
Version: GeckoLib5

Creating the Renderer

Once you've made your replaced entity class, you can now create the renderer and register it.

Making the class

💻Additive Code Section
All code snippets in this section add onto the previous code snippets, using a step-by-step approach to build the complete code.
Green highlights show added or modified lines of code for each step.

To begin, let's create a renderer class that extends GeoReplacedEntityRenderer:

public class ExampleReplacedEntityRenderer extends GeoReplacedEntityRenderer {

}

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 ExampleReplacedEntityRenderer<R extends CreeperRenderState & GeoRenderState> extends GeoEntityRenderer<ExampleReplacedEntity, Creeper, R> {

}

And then we add in the constructor, passing in the GeoModel and GeoReplacedEntity instance:

public class ExampleReplacedEntityRenderer<R extends CreeperRenderState & GeoRenderState> extends GeoEntityRenderer<ExampleReplacedEntity, Creeper, R> {
public ExampleReplacedEntityRenderer(EntityRendererProvider.Context context) {
super(context, new ExampleReplacedEntityGeoModel(), new ExampleReplacedEntity();
}
}

That's it! Now you need to register it.

Extra Bits

GeckoLib strongly recommends that you additionally override createRenderState(T, E) and return a new instance of the target entity's normal RenderState class, as well as extractRenderState, adding the target entity's normal RenderState values.

For example, if you're replacing a Creeper:

@Override
public R createRenderState(ExampleReplacedEntity animatable, Creeper relatedObject) {
return (R)new CreeperRenderState();
}

@Override
public void extractRenderState(Creeper entity, R renderState, float partialTick) {
super.extractRenderState(entity, renderState, partialTick);

renderState.swelling = entity.getSwelling(partialTick);
renderState.isPowered = entity.isPowered();
}

You may also want to override other parts of the renderer to better match the target entity, if applicable.

warning

The above example is for replacing a Creeper. If you are replacing a different entity, you will need to check your target entity's normal renderer and use those values instead.

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.

The generic types

In the Making the class section, we added in the generic types that the renderer requires in step 3.

But what are these generic types?

  • R - This is the RenderState type. By default, GeckoLib uses vanilla's LivingEntityRenderState, combined with GeckoLib's GeoRenderState, but it is strongly recommended you use the RenderState your replaced entity uses (such as CreeperRenderState for Creepers).
    For more information on RenderStates, see the RenderStates page.
  • Creeper - This is the entity class of the entity you're replacing. Replace this with your target entity's class name.
  • ExampleReplacedEntity - This is your ReplacedGeoEntity! Replace this with your replaced entity's class name.