Skip to content

Geckolib Armor (Geckolib3)

Tslat edited this page Mar 27, 2024 · 6 revisions

Pre-word

When making your armor model in Blockbench, ensure you have selected the Armor model type in the Geckolib Model Settings panel in the File menu. This is critical to ensure that Blockbench generates the correct project template and output files for you when finished.

Steps

Creating a GeckoLib armor requires the following steps:

  1. Creating your Blockbench Model
  2. Creating your Geo Model
  3. Creating your item display json
  4. Creating your Item class
  5. Creating and registering your renderer

Steps #1 and #2 will not be covered on this page, instead visit their respective links for info. This page will focus on steps #3, #4, and #5

Full Video Guides

The Item Class

Forge

Armor item classes are created the exact same way normal animatable item classes are. Because of this, you'll want to look at the Geckolib Items page for instructions on creating the class.

The only difference to normal items is that we should extend GeoArmorItem instead. This handles the rendering callback for you. If for some reason you're unable to extend GeoArmorItem, you will need to re-implement the functionality that GeoArmorItem contains.

Example Armor Item Class

public class ExampleArmorItem extends GeoArmorItem implements IAnimatable {
    protected static final AnimationBuilder IDLE_ANIM = new AnimationBuilder().addAnimation("misc.idle", true);

    private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
    
    public ExampleArmorItem(ArmorMaterial armorMaterial, EquipmentSlot slot, Properties properties) {
        super(armorMaterial, slot, properties);
    }
    
    private <T extends ExampleArmorItem> PlayState idleAnimController(final AnimationEvent<T> event) {
        event.getController().setAnimation(IDLE_ANIM);

        return PlayState.CONTINUE;
    }
    
    @Override
    public void registerControllers(AnimationData data) {
        data.addAnimationController(new AnimationController(this, "Idle Controller", 0, this::idleAnimController));
    }
    
    @Override
    public AnimationFactory getFactory() {
        return this.factory;
    }
}
Fabric

Armor item classes are created the exact same way normal animatable item classes are. Because of this, you'll want to look at the Geckolib Items page for instructions on creating the class.

Example Armor Item Class

public class ExampleArmorItem extends ArmorItem implements IAnimatable {
    protected static final AnimationBuilder IDLE_ANIM = new AnimationBuilder().addAnimation("misc.idle", true);

    private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
    
    public ExampleArmorItem(ArmorMaterial armorMaterial, EquipmentSlot slot, Properties properties) {
        super(armorMaterial, slot, properties);
    }
    
    private <T extends ExampleArmorItem> PlayState idleAnimController(final AnimationEvent<T> event) {
        event.getController().setAnimation(IDLE_ANIM);

        return PlayState.CONTINUE;
    }
    
    @Override
    public void registerControllers(AnimationData data) {
        data.addAnimationController(new AnimationController(this, "Idle Controller", 0, this::idleAnimController));
    }
    
    @Override
    public AnimationFactory getFactory() {
        return this.factory;
    }
}

The Renderer

Creating the Class

GeoArmorRenderers are probably the most involved renderer type for GeckoLib3. Unlike most normal renderers, we have to do some additional manual work in the constructor to make sure everything works properly.

By default, Geckolib armors operate on a humanoid model basis. This means that the expected format for an armour roughly resembles a humanoid in that it has two arms, two legs, two feet, a torso, and a head. We need to tell the renderer which of our 'bones' align with the humanoid representation of them, so that it can match them up for rendering.

We do this by assigning the name of the bone (found in our geo.json, or as the name of the bone group in Blockbench) to each respective part of the renderer. See below for example usage of this, with generic placeholder bone names.

Example Renderer Class

    public class ExampleArmorRenderer extends GeoArmorRenderer<ExampleArmorItem> {
    	public ExampleArmorRenderer() {
    		super(new ExampleArmorModel());
    
    		// These values are what each bone name is in blockbench. So if your head bone group is named "bone545", 
    		// you would do to do this.headBone = "bone545";
    		
    		// The default values are the ones that come with the default armor template in the GeckoLib Blockbench plugin.
    		this.headBone = "helmet";
    		this.bodyBone = "chestplate";
    		this.rightArmBone = "rightArm";
    		this.leftArmBone = "leftArm";
    		this.rightLegBone = "rightLeg";
    		this.leftLegBone = "leftLeg";
    		this.rightBootBone = "rightBoot";
    		this.leftBootBone = "leftBoot";
    	}
    }

Registering the Renderer

Forge

To register your Geckolib armor renderer, we need to call GeoArmorRenderer#registerArmorRenderer during FMLClientSetupEvent in your mod. To that, we pass the class of the armor item, and a supplier for the renderer.

Example Renderer Registration

    @SubscribeEvent
    public static void clientSetup(final FMLClientSetupEvent event) {
        GeoArmorRenderer.registerArmorRenderer(ExampleArmorItem.class, ExampleArmorRenderer::new);
    }
Fabric

To register your Geckolib armor renderer, we need to call GeoArmorRenderer#registerArmorRenderer inside onInitializeClient in your mod. To that, we pass the an instance of the renderer for the armor, as well as the item instances for each relevant armor piece.

Example Renderer Registration

    @Override
    public void onInitializeClient() {
        GeoArmorRenderer.registerArmorRenderer(new PotatoArmorRenderer(), 
					 MyItems.EXAMPLE_ARMOR_HELMET, MyItems.EXAMPLE_ARMOR_CHESTPLATE, MyItems.EXAMPLE_ARMOR_LEGGINGS, MyItems.EXAMPLE_ARMOR_BOOTS);
    }

Table of Contents

Geckolib 3
Geckolib 4

Hosted By: Cloudsmith

Package repository hosting is graciously provided by Cloudsmith.

Cloudsmith is the only fully hosted, cloud-native, universal package management solution that enables your organization to create, store and share packages in any format, to any place, with total confidence.

Clone this wiki locally