How do I make a flying mob that can walk on land?

Started by Sajevius on

Topic category: Help with modding (Java Edition)

Last seen on 08:14, 28. Nov 2023
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I make a flying mob that can walk on land?

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?

Last seen on 19:53, 2. Jun 2021
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
on my mod, i made 2 models,…
Fri, 03/19/2021 - 06:10

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'

Last seen on 08:14, 28. Nov 2023
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
thx for the reply,…
Fri, 03/19/2021 - 06:26

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

Last seen on 22:31, 11. Nov 2023
Joined Oct 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is mostly just a theory…
Sat, 12/24/2022 - 09:10

This is mostly just a theory so take it with a grain of salt but maybe try to make it so if it touches the ground, gets to a certain height or at a random tick it goes to the ground and can only move if it’s touching a block and can’t jump and goes up blocks like it’s a stair case

Last seen on 07:42, 26. Nov 2023
Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
did you manage to work this…
Sun, 05/07/2023 - 21:45

did you manage to work this out? i want to do something similar, a ground entity that flies when a player is riding it, but i cant evn begin to imagine how to go about it 

Last seen on 04:46, 14. Mar 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
im trying to make this on…
Sun, 11/19/2023 - 10:07

im trying to make this on the same mob with GeckoLib now on 2023, it does work, and just use 1 mob, the problem is that the bird spend liks 99,9% flying he only touches the ground, walk for a little bit and fly again, idk if im doing something wrong on the animation settings, i made Idle, walk and fly, but since it dont spend too much time on the ground it does not Idle.. any ideas guys?

Last seen on 04:46, 14. Mar 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i think this is the part…
Sun, 11/19/2023 - 10:10

i think this is the part that rules those states:

private PlayState movementPredicate(AnimationState event) {

if (this.animationprocedure.equals("empty")) {
if ((event.isMoving() || !(event.getLimbSwingAmount() > -0.15F && event.getLimbSwingAmount() < 0.15F)) && this.onGround()) {
return event.setAndContinue(RawAnimation.begin().thenLoop("walk"));
}
if (!this.onGround()) {
return event.setAndContinue(RawAnimation.begin().thenLoop("fly"));
}
return event.setAndContinue(RawAnimation.begin().thenLoop("idle"));
}
return PlayState.STOP;
}