Animation jitters when new entitiy does not extend `LivingEntity`
LucunJi opened this issue ยท 0 comments
Versions (from my gradle.peoperties):
minecraft_version=1.20.1
forge_version=47.0.3
geckolib_minecraft_version=1.20
geckolib_version=4.2
What happened?
I was trying to make a new boat entity.
If my new entity does not extend LivingEntity
, the animation jitters when multiple instances are rendered.
Peek.2023-06-18.20-41.mp4
Reproduce
Here's my code (imports are skipped). The assets are borrowed from the bike example.
You can change the super class of the entity into Boat
and see the same issue.
But as long as the super class is LivingEntity
or any of its subclass (e.g. Animal
), the jittering disappears.
public class SomeEntity extends EndCrystal implements GeoEntity {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public SomeEntity(EntityType<SomeEntity> entityType, Level level) {super(entityType, level);}
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllerRegistrar) {
controllerRegistrar.add(DefaultAnimations.genericIdleController(this));
}
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {return this.cache;}
}
Registration:
public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MODID);
public static final RegistryObject<EntityType<SomeEntity>> SOME_BOAT = ENTITIES.register("some_boat",
() -> EntityType.Builder.of(SomeEntity::new, MobCategory.MISC)
.sized(1.375F, 0.5625F)
.clientTrackingRange(10)
.build("some_boat"));
public SomeBoat() {
ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
}
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class ClientModEvents {
@SubscribeEvent
public static void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) {
event.registerEntityRenderer(SOME_BOAT.get(), context ->
new GeoEntityRenderer<>(context, new DefaultedEntityGeoModel<>(new ResourceLocation(MODID, "bike"))));
}
}
My investigation
I looked for the all the references of LivingEntity
in geckolib, and found line 143 in GeoModel.java
suspicious:
When the input entity is not a LivingEntity
, the partial tick returned by getFrameTime
is not used.
I do not understand why we do not use partial tick when the input is not a LivingEntity
,
but after setting a breakpoint to set currentFrameTime = currentTick + mc.getFrameTime()
regardless of the class of input animatable entity, the jittering disappears.