-
-
Notifications
You must be signed in to change notification settings - Fork 128
Custom GeckoLib Entity
This wiki page assumes you are in the Entity
setting in your GeckoLib blockbench model. Learn how to change this here
In order to create an entity with GeckoLib you need to do several things.
- Create the Entity class (extends
LivingEntity
or any subtype) - Create the Renderer class (extends
GeoEntityRenderer
) - Create the Model class (extends
GeoModel
)
This wiki almost exclusively uses Mojmap mappings. If you need to figure out the yarn name for a Mojmap class/field/method, check out the Mappings Website
Any GeckoLib object has to extend GeoAnimatable
. This exposes two methods you need to override:
-
getAnimatableInstanceCache()
- All you need to here is return a member field of typeAnimatableInstanceCache
. This needs to be passed in an instance of your entity (usually done by passing inthis
) -
registerControllers
- This method is called every time a new instance of your animatable object (in this case your entity) is created. So, you should create your animation controllers, register listeners, and do any initial setup here. Take a look at the example below for a more obvious example.
public class ExampleEntity extends PathfinderMob implements GeoEntity {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public ExampleEntity(EntityType<? extends ExampleEntity> type, Level level) {
super(type, level);
}
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
controllers.add(new AnimationController<>(this, "idle", 5, state -> state.setAndContinue(DefaultAnimations.IDLE)));
}
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.cache;
}
}
To register the entity, use Deferred Registries for Forge and for Fabric see HERE.
Entity renderers are fairly simple. All you need to do is create a renderer class that extends GeoEntityRenderer
, like this:
public class ExampleGeoRenderer extends GeoEntityRenderer<GeoExampleEntity> {
public ExampleGeoRenderer(EntityRendererProvider.Context renderManager) {
super(renderManager, new ExampleEntityModel());
}
}
Make sure to pass in the correct model class into the super constructor.
If you don't register the renderer, your game will crash.
To register your renderer, place this method call in your EntityRenderersEvent.RegisterRenderers
event handler (or onInitializeClient
in Fabric):
Forge
@SubscribeEvent
public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) {
event.registerEntityRenderer(EntityRegistry.EXAMPLE_ENTITY.get(), ExampleGeoRenderer::new);
}
Fabric
@Override
public void onInitializeClient() {
EntityRendererRegistry.register(EntityRegistry.EXAMPLE_ENTITY, ExampleGeoRenderer::new);
}
Entity models in GeckoLib are the same as models for any other animation type. See the article on models.
Geckolib 3
Geckolib 4
- Installation
- Getting Started
- Upgrading from GeckoLib 3.1.x to 4.0
- Updating to GeckoLib 4.5
- Basic
- Advanced
- Miscellaneous
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.