Skip to main content
Version: GeckoLib5

Applying the Renderer

Once you've made your item class and its associated renderer, you need to apply it to your item.

Adjusting Your Item Class​

To apply the GeoItemRenderer to your item, you'll need to add in a small section to your item 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.

First, we override createGeoRenderer in our item class:

public class ExampleItem extends Item implements GeoItem {

// ...

@Override
public void createGeoRenderer(Consumer<GeoRenderProvider> consumer) {

}
}

Then we provide the Consumer with a new GeoRenderProvider instance:

public class ExampleItem extends Item implements GeoItem {

// ...

@Override
public void createGeoRenderer(Consumer<GeoRenderProvider> consumer) {
consumer.accept(new GeoRenderProvider() {

});
}
}

Next, we create a cached supplier of your renderer, so that you're not creating a new one every render pass:

public class ExampleItem extends Item implements GeoItem {

// ...

@Override
public void createGeoRenderer(Consumer<GeoRenderProvider> consumer) {
consumer.accept(new GeoRenderProvider() {
private final Supplier<GeoItemRenderer<ExampleItem>> renderer = Suppliers.memoize(() -> new GeoItemRenderer<>(ExampleItem.this));


});
}
}

And finally, we override getGeoItemRenderer and return our renderer:

public class ExampleItem extends Item implements GeoItem {

// ...

@Override
public void createGeoRenderer(Consumer<GeoRenderProvider> consumer) {
consumer.accept(new GeoRenderProvider() {
private final Supplier<GeoItemRenderer<ExampleItem>> renderer = Suppliers.memoize(() -> new GeoItemRenderer<>(ExampleItem.this));

@Override
public @Nullable GeoItemRenderer<ExampleItem> getGeoItemRenderer() {
return this.renderer.get();
}
});
}
}

Split Sources​

If you have client-server split sources, you'll need to do a few additional steps to make your renderer work, since your IDE won't be able to find the renderer class while working in your item.

Item 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.

First, we'll need to put a MutableObject in your item class so it can hold the GeoRenderProvider:

public class ExampleItem extends Item implements GeoItem {
private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);
public final MutableObject<Object> geoRenderProvider = new MutableObject<>();

public ExampleItem(Properties properties) {
super(properties);
}

// ...
}

Then, we'll need to provide that to the GeoRenderProvider consumer, instead of directly passing it:

public class ExampleItem extends Item implements GeoItem {
private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);
public final MutableObject<Object> geoRenderProvider = new MutableObject<>();

// ...

@Override
public void createGeoRenderer(Consumer<GeoRenderProvider> consumer) {
consumer.accept(this.geoRenderProvider.getValue());
}
// ...
}
warning

Make sure you remove the GeoRenderProvider reference from createGeoRenderer:

public class ExampleItem extends Item implements GeoItem {
private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);
public final MutableObject<Object> geoRenderProvider = new MutableObject<>();

// ...

@Override
public void createGeoRenderer(Consumer consumer) {
consumer.accept(this.geoRenderProvider.getValue());
}
// ...
}

Client Setup Class​

Lastly, in your mod's client setup, you'll need to set the geoRenderProvider in your item's instance. See the Adjusting Your Item Class section to see how to build the GeoRenderProvider instance.

@SubscribeEvent
public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) {
ItemRegistry.EXAMPLE_ITEM.geoRenderProvider.setValue(new GeoRenderProvider() {
private final Supplier<GeoItemRenderer<ExampleItem>> renderer = Suppliers.memoize(() -> new GeoItemRenderer<>(ItemRegistry.EXAMPLE_ITEM.get()));

@Override
public @Nullable GeoItemRenderer<ExampleItem> getGeoItemRenderer() {
return this.renderer.get();
}
});
}