Skip to content

Geo Models (Geckolib4)

Tslat edited this page Jun 12, 2023 · 6 revisions

In GeckoLib, models are the glue that puts together your models, animations, and textures. A standard model class is very simple and can be reused.

To create a model class, extend AnimatedGeoModel and implement all the required methods.

The class should look like this:

Forge
public class JackInTheBoxModel extends GeoModel<JackInTheBoxItem> {
	private static final ResourceLocation modelPath = new ResourceLocation(GeckoLib.MOD_ID, "geo/jack.geo.json");
	private static final ResourceLocation texturePath = new ResourceLocation(GeckoLib.MOD_ID, "textures/item/jack.png");
	private static final ResourceLocation animationsPath = new ResourceLocation(GeckoLib.MOD_ID, "animations/jackinthebox.animation.json");

	@Override
	public ResourceLocation getModelResource(JackInTheBoxItem animatable) {
		return modelPath;
	}

	@Override
	public ResourceLocation getTextureResource(JackInTheBoxItem animatable) {
		return texturePath;
	}

	@Override
	public ResourceLocation getAnimationResource(JackInTheBoxItem animatable) {
		return animationsPath;
	}
}
Fabric/Quilt
public class JackInTheBoxModel extends AnimatedGeoModel<JackInTheBoxItem> {
	private static final Identifier modelPath = new Identifier(GeckoLib.MOD_ID, "geo/jack.geo.json");
	private static final Identifier texturePath = new Identifier(GeckoLib.MOD_ID, "textures/item/jack.png");
	private static final Identifier animationsPath = new Identifier(GeckoLib.MOD_ID, "animations/jackinthebox.animation.json");

	@Override
	public Identifier getModelResource(JackInTheBoxItem animatable) {
		return modelPath;
	}

	@Override
	public Identifier getTextureResource(JackInTheBoxItem animatable) {
		return texturePath;
	}

	@Override
	public Identifier getAnimationResource(JackInTheBoxItem animatable) {
		return animationsPath;
	}
}

Each of these methods handles the location of the model, texture, and animation file, respectively.

Defaulted Models

New to GeckoLib4 are 'Defaulted' GeoModels. These are pre-designed model classes that allow you to make your model with next to no effort. They also encourage consistency of file organisation, and efficient model handling.

It is highly recommended that you use one of the defaulted model classes.

Click here for example
new DefaultedGeoEntityModel(new ResourceLocation(GeckoLib.MOD_ID, "bat"));

This creates a new GeoModel, and sets the following paths automagically:

  • Texture: textures/entity/bat.png
  • Model: geo/entity/bat.geo.json
  • Animation: animations/entity/bat.animation.json

File Locations

Your resources cannot go just in any directory. Otherwise, GeckoLib will not be able to find them during the resource scanning phase. Make sure all your resources are in the correct folder. This is strict because GeckoLib can load your models at runtime, making it easier for people to override your models/animations in resource packs. We also recommend storing the resources with constants like in the examples above.

Models (.geo.json)

Model files have to go in resources/assets/<modid>/geo. They can also be in any subdirectory of the geo folder, so feel free to organize your models however you wish.

Animation Files (.animation.json)

Animation files have to go in resources/assets/<modid>/animations. Similarly to model files, animations can go in any subfolder of /animations

Textures (.png)

Textures are the same as in vanilla. They must go in resources/assets/<modid>/textures, or any subdirectory of that folder.

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