Creating the GeoReplacedEntity Class
The first step in making a GeckoLib replaced entity is to create the entity class itself.
Quick Summary
Just looking for a quick summary? Expand the section below!
Click to expand
Here are the quick steps required to create a GeckoLib entity class:
- Create a new class implementing
GeoReplacedEntity - Override the
getReplacingEntityType()method and return theEntityTypeyou're replacing - Override the
getAnimatableInstanceCacheandregisterControllermethods fromGeoEntity - Instantiate a new
AnimatableInstanceCachein afinalfield at the top of your class viaGeckoLibUtil.createInstanceCache(this) - Return the
AnimatableInstanceCachein thegetAnimatableInstanceCachemethod - Add any animation controllers you want to use in
registerControllers
You now have a working GeckoLib replaced entity!
Making the class
This example replaces the vanilla CREEPER entity, as an example.
You will need to replace this with the EntityType you're replacing.
Green highlights show added or modified lines of code for each step.
First, we will make the base replaced entity class:
public class ExampleReplacedEntity implements GeoReplacedEntity {
}
Then, we will implement the getReplacingEntityType interface and return the EntityType we're replacing:
public class ExampleReplacedEntity implements GeoReplacedEntity {
@Override
public EntityType<?> getReplacingEntityType() {
return EntityType.CREEPER;
}
}
Then, we will override the getAnimatableInstanceCache and registerControllers methods:
public class ExampleReplacedEntity implements GeoReplacedEntity {
@Override
public EntityType<?> getReplacingEntityType() {
return EntityType.CREEPER;
}
@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 ExampleReplacedEntity implements GeoReplacedEntity {
private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);
@Override
public EntityType<?> getReplacingEntityType() {
return EntityType.CREEPER;
}
@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.