Skip to main content
Version: GeckoLib5

The Item Class

To have GeckoLib armor, you first need to have an item class.

note

This tutorial is specifically for GeckoLib implementation. For information on general-modding armor features, seek a tutorial or community support.

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

First, we create the base item class and implement the base constructor:

public class ExampleArmorItem extends Item {
public ExampleArmorItem(ArmorMaterial material, ArmorType type, Properties properties) {
super(properties.humanoidArmor(material, type));
}
}

Then, we will implement the GeoItem interface and override the getAnimatableInstanceCache and registerControllers methods:

public class ExampleArmorItem extends Item implements GeoItem {
public ExampleArmorItem(ArmorMaterial material, ArmorType type, Properties properties) {
super(properties.humanoidArmor(material, type));
}

@Override
public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) {
// We can fill this in later
}

@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return null;
}
}

Next, let's instantiate an AnimatableInstanceCache in a final field at the top of our class, and return it in getAnimatableInstanceCache:

public class ExampleArmorItem extends Item implements GeoItem {
private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);

public ExampleArmorItem(ArmorMaterial material, ArmorType type, Properties properties) {
super(properties.humanoidArmor(material, type));
}

@Override
public void registerControllers(final AnimatableManager.ControllerRegistrar controllers) {
// We can fill this in later
}

@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.geoCache;
}
}

And you're done!

For information on adding animation controllers, see the Animation Controllers page.

info

You might have noticed that this setup is very similar to a GeckoLib item.
You'd be right! This is exactly the same setup as a GeckoLib item!

Extra Bits

I want to use triggered animations on this armor

Click to Expand

To prepare your armor item class for using triggered animations, you'll need to register the item as a synced animatable.
This is done in the constructor, like so:

public class ExampleArmorItem extends Item implements GeoItem {
private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);

public ExampleArmorItem(ArmorMaterial material, ArmorType type, Properties properties) {
super(properties.humanoidArmor(material, type));

GeoItem.registerSyncedAnimatable(this);
}

// ...
}

See the Triggered Animations section for more information on triggered animations and how to use them

Registering the item

Once you have created your item 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 entities.