Creating the Renderer
Once you've made your replaced entity class, you can now create the renderer and register it.
Making the class
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.
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.
- Fabric
- Forge
- NeoForge
None exists :(
See the NeoForge tab for similar instructions
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 theRenderStatetype. By default, GeckoLib uses vanilla'sLivingEntityRenderState, combined with GeckoLib'sGeoRenderState, but it is strongly recommended you use theRenderStateyour replaced entity uses (such asCreeperRenderStatefor 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 yourReplacedGeoEntity! Replace this with your replaced entity's class name.