11package org.cneko.justarod.entity
22
3- import net.minecraft.entity.Entity
4- import net.minecraft.entity.EntityStatuses
5- import net.minecraft.entity.EntityType
6- import net.minecraft.entity.LivingEntity
3+ import net.minecraft.entity.*
74import net.minecraft.entity.ai.goal.*
85import net.minecraft.entity.attribute.DefaultAttributeContainer
96import net.minecraft.entity.attribute.EntityAttributes
@@ -20,6 +17,7 @@ import net.minecraft.item.ItemStack
2017import net.minecraft.item.Items
2118import net.minecraft.nbt.NbtCompound
2219import net.minecraft.particle.ParticleTypes
20+ import net.minecraft.registry.tag.FluidTags
2321import net.minecraft.server.world.ServerWorld
2422import net.minecraft.util.ActionResult
2523import net.minecraft.util.Hand
@@ -34,6 +32,11 @@ import org.cneko.toneko.common.mod.misc.mixininterface.SlowTickable
3432import software.bernie.geckolib.animatable.GeoEntity
3533import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache
3634import software.bernie.geckolib.animation.AnimatableManager
35+ import software.bernie.geckolib.animation.AnimationController
36+ import software.bernie.geckolib.animation.AnimationController.AnimationStateHandler
37+ import software.bernie.geckolib.animation.AnimationState
38+ import software.bernie.geckolib.animation.RawAnimation
39+ import software.bernie.geckolib.constant.DefaultAnimations
3740import software.bernie.geckolib.util.GeckoLibUtil
3841import java.util.*
3942
@@ -106,6 +109,23 @@ class RodEntity(private val entityType:EntityType<RodEntity>, world: World):Tame
106109 }
107110
108111 override fun registerControllers (controllers : AnimatableManager .ControllerRegistrar ? ) {
112+ controllers!! .add(AnimationController <RodEntity >(this , 20 , AnimationStateHandler { state: AnimationState <* >? ->
113+ if (this .pose == EntityPose .SWIMMING && ! this .isInFluid) {
114+ return @AnimationStateHandler state!! .setAndContinue(DefaultAnimations .CRAWL )
115+ } else if (this .isInFluid && this .isSubmergedIn(FluidTags .WATER )) {
116+ return @AnimationStateHandler if (state!! .isMoving) state.setAndContinue(DefaultAnimations .SWIM ) else state.setAndContinue(
117+ DefaultAnimations .CRAWL
118+ )
119+ } else if (! state!! .isMoving) {
120+ return @AnimationStateHandler if (this .isSitting) state.setAndContinue(
121+ RawAnimation .begin().thenLoop(" misc.sit" )
122+ ) else state.setAndContinue(DefaultAnimations .IDLE )
123+ } else {
124+ return @AnimationStateHandler if (this .velocity.length() > 0.2 ) state.setAndContinue(
125+ DefaultAnimations .RUN
126+ ) else state.setAndContinue(DefaultAnimations .WALK )
127+ }
128+ }))
109129 }
110130
111131 override fun getAnimatableInstanceCache (): AnimatableInstanceCache {
0 commit comments