Topic category: Help with modding (Java Edition)
I'm making a small mod behind the scenes that includes a dragon, and I've noticed this for quite a while now (even before I started working on my first mod): the default flight controller for flying mobs is... really weird. in some occasions, they ignore targeted entities and just fly up to the sky until they disappear from sight, never to return. so I thought, why not make my dragons switch between walking & flying if their AI works weirdly & annoyingly with no-gravity always set to true?
to start solving this problem, I attempted to add an update tick procedure for my dragon that manages an NBT timer determining how many ticks are left before the dragon starts flying, and how many ticks of flight until it stops. it goes like this:
- "BeforeFlyingCD" is a number NBT with an initial value of 600. each update tick of the dragon subtracts the NBT's value by 1.
- "FlyingDuration" is another number NBT with an initial value of 300. between 0 & 300 (about 298) is the number of ticks that the dragon will keep flying.
- once "BeforeFlyingCD" reaches a value equal to/less than 0, "FlyingDuration" starts decrementing.
- once "FlyingDuration" reaches 0, the values of "BeforeFlyingCD" & "FlyingDuration" reset.
then, I tried using execute conditions for the "fly around with speed factor [x]", to only execute once in a while: only if "FlyingDuration" is less than 300 & greater than 0. but that doesn't work, my dragon still keeps flying.
so I changed BeforeFlyingCD & FlyingDuration to "BeforeLandingCD" & "LandingDuration" respectively, then whenever LandingDuration is <300 & >0, set the mob's no-gravity to false. it doesn't work.
I changed the no-gravity setting procedure to one that sets the mob's velocity to -1. but the dragon started acting even weirder on land (rotating like crazy & moving too fast all over the place) and it doesn't work.
when I was about to give up, I then started to want to do something like the movement controller of the dragons in Ice and Fire mod (https://www.curseforge.com/minecraft/mc-mods/ice-and-fire-dragons) where they commonly walk & only fly when targeting and/or chasing other mobs or when they're hurt. something similar to that, just so I could make a dragon that walks on land most of the time & rarely flies. is this possible?
on my mod, i made 2 models, 2 separated entities for that; walking entity and flying entity, then you create a procedure to make
Despawn -> Spawn on a certain condition like me, i use 'when player right-click entity'
thx for the reply, gustavowizard123; I'll try what you said. I'll also check if I can somehow sync the despawned entity's NBT tags to the entity spawned under a condition, coz I forgot to mention that my dragon actually breathes a stream of fire occasionally, controlled by NBT... so yeah, I need to keep those tags & put them on the 2nd entity