Repository navigation
RiftLibrary Entities
Creating an entity in RiftLibrary 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
The first step is to implement the IAnimatable interface on your entity class, and override the two methods your IDE may ask you to. These methods are:
-
registerControllers(AnimationData data): This method is where animations for your entity are registered and controlled -
getFactory(): This method returns an instance of AnimationFactory
The final step is to define a new instance of AnimationFactory as a global variable, and in its constructor put this. Make getFactory() return this global variable.
Here's an example class showing the result:
public class ExampleEntity extends EntityLiving implements IAnimatable {
private final AnimationBuilder FLY_ANIM = new AnimationBuilder().addAnimation("move.fly", true);
private final AnimationFactory factory = new AnimationFactory(this);
public ExampleEntity(World worldIn) {
super(worldIn);
}
@Override
public void registerControllers(AnimationData data) {
data.addAnimationController(new AnimationController<>(this, "flying", 0, this::flyAnimController));
}
private PlayState flyAnimController(AnimationEvent event) {
if (event.isMoving()) {
event.getController().setAnimation(FLY_ANIM);
return PlayState.CONTINUE;
}
return PlayState.STOP;
}
@Override
public AnimationFactory getFactory() {
return this.factory;
}
}Like any other entity, you need to assign a renderer to your entity. It must extend GeoEntityRenderer<T>, with T being the entity you're making the renderer for. Here's an example renderer class:
public class ExampleEntityRenderer extends GeoEntityRenderer<ExampleEntity> {
public ExampleEntityRenderer(RenderManager renderManager) {
super(renderManager, new ExampleEntityModel());
}
}Finally, in the FMLPreInitializationEvent event of your mod, register your entity renderer as so:
RenderingRegistry.registerEntityRenderingHandler(ExampleEntity.class, ExampleEntityRenderer::new);IAnimatable happens to have a scale() method that, by default, returns 1. You can override this to change the scale of your entity's model.
You can override the render(GeoModel model, T animatable, float partialTicks, float red, float green, float blue, float alpha) method in your GeoEntityRenderer class to change how your entity may be rendered. Some examples include:
- Changing overall color or transparency
- Hiding bones in the model You may check the renderer class for Prehistoric Rift's creatures as an example.