-
-
Notifications
You must be signed in to change notification settings - Fork 128
Geckolib Entities (Geckolib3)
Creating a GeckoLib entity requires the following steps:
- Creating your Blockbench Model
- Creating your Geo Model
- Creating your entity class
- 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 and #4
Quick Summary
- implement
IAnimatable
- Override
getFactory
andregisterControllers
- Instantiate a new
AnimationFactory
viaGeckoLibUtil.createFactory(this)
at the top of your entity class and return it ingetFactory
- Add any controllers you want for animations in
registerControllers
There are only a few things needed to set up a GeckoLib entity's class.
The first is to implement IAnimatable
on your entity class, and override the two methods your IDE will tell you to override.
This interface is the base of all animatable objects in GeckoLib, and lets the various other features of the mod pick up your entity as an animatable entity.
Next, we'll create an instance of an AnimationFactory
for our entity. This stores our animatable instance so that it can be retrieved by the renderer and other outside areas.
To do this, we'll instantiate a new factory via GeckoLibUtil.createFactory(this)
at the top of your entity class, caching it in a final variable.
Next, we'll override getFactory
in our entity class if it hasn't been done already, and return the factory instance we just created.
And finally, override registerControllers
in your entity class. This method is called when your entity is first being used for animations, and is where you define your actual animation handling.
Your class is all set up! The only thing left to do is define your animations in registerControllers
public class ExampleEntity extends PathfinderMob implements IAnimatable {
protected static final AnimationBuilder FLY_ANIM = new AnimationBuilder().addAnimation("move.fly", true);
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
public ExampleEntity(EntityType<? extends ExampleEntity> type, Level level) {
super(type, level);
}
@Override
public void registerControllers(final AnimationData data) {
data.addAnimationController(new AnimationController<>(this, "Flying", 5, this::flyAnimController));
}
protected <E extends ExampleEntity> PlayState flyAnimController(final AnimationEvent<E> event) {
if (event.isMoving()) {
event.getController().setAnimation(FLY_ANIM);
return PlayState.CONTINUE;
}
return PlayState.STOP;
}
@Override
public AnimationFactory getFactory() {
return this.factory;
}
}
To have your entity show up in the world, you'll need to register your entity's renderer - like you would for any other entity.
The difference with GeckoLib is that you must register an instance of GeoEntityRenderer
, instead of any vanilla renderers.
One bonus to this is that you don't need to register any model layers or mesh definitions like you do with non-GeckoLib models, and instead can skip straight to registering the renderer itself. The renderer will take the render context and your Geo Model instance.
public class ExampleEntityRenderer extends GeoEntityRenderer<ExampleEntity> {
public ExampleEntityRenderer(EntityRendererProvider.Context context) {
super(context, new ExampleEntityModel());
}
}
If you're getting a crash that says something like this:
java.lang.NullPointerException: Cannot invoke "net.minecraft.client.renderer.entity.EntityRenderer.shouldRender(net.minecraft.world.entity.Entity, net.minecraft.client.renderer.culling.Frustum, double, double, double)" because "entityrenderer" is null
You forgot to register your renderer
This loop type is not supported in GeckoLib3, and was only added in GeckoLib4.
To make your functionality work, you should make a second animation that is just a single keyframe of the position you want your animation to stay in, then set it to loop. Then, in your AnimationBuilder, set that looped animation to follow the first one.
This will cause the animation to play the first animation, then hold onto it until you tell it to stop
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.