Mob movement and mojang code

Discussion in 'Plugin Development' started by CorrieKay, May 3, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    CorrieKay

    After thinking for a bit, i decided to create my own thread on this.
    Apologies V10lator if this is getting annoying, i understand.. but i really didnt want to hijack the other thread :\

    So i was digging through the mojang code to figure out why this only works for Pig Zombies..

    I went into it thinking possibly it could be the boolean flags, to try and figure out what they mean. (maybe they set if its a hostile mob or not... which reminds me, endermen behave similarly to pig zombies, maybe ill try to use this on them!)

    i came across this code
    PathEntity (open)

    public PathEntity a(Entity entity, int i, int j, int k, float f, boolean flag, boolean flag1, boolean flag2, boolean flag3) {
    // MethodProfiler.a("pathfind"); // CraftBukkit - not in production code
    int l = MathHelper.floor(entity.locX);
    int i1 = MathHelper.floor(entity.locY);
    int j1 = MathHelper.floor(entity.locZ);
    int k1 = (int) (f + 8.0F);
    int l1 = l - k1;
    int i2 = i1 - k1;
    int j2 = j1 - k1;
    int k2 = l + k1;
    int l2 = i1 + k1;
    int i3 = j1 + k1;
    ChunkCache chunkcache = new ChunkCache(this, l1, i2, j2, k2, l2, i3);
    PathEntity pathentity = (new Pathfinder(chunkcache, flag, flag1, flag2, flag3)).a(entity, i, j, k, f);
    // MethodProfiler.a(); // CraftBukkit - not in production code
    return pathentity;
    }

    Well looks like those flags are being used when creating a new Pathfinder object... Thing is, its nowhere to be found :confused:
    Theres no import, which tells me that its in the same package, so... i mean, theres a bunch of Pathfinder* objects, but theyre not the class being used.
    So bukkit forums, (this post isnt necessarily directed at the quoted post, im just using it for reference) Do any of you have any idea where to go from here?

    Edit: HOLY CRAP! i was right! those booleans have *GOT* to be the reason why, i can control endermen and zombie pigs using that code, but not any other mob...
     
  2. Have you been able to find out what any of the individual boolean arguments represent?
     
  3. Offline

    CorrieKay

    No, unfortunately i cant really find the Pathfinder Class file :\

    i feel blind...

    Also, the list of mobs that are controllable: zombie pigs, endermen, spiders, blazes, cave spiders.
    List of mobs that you CANT control: chicken, cow, creeper ghast (this actually throws a class cast exception) giant, iron golem, magma cube (also throws CCE), mushroom cow, ocelot, pig, skeleton

    Im gonna keep trying to find which mobs are controllable using these exact parameters.

    Yknow at this point, i think we have enough information to see whats going on here. I think that these exact parameters are only allowed for specific types of mobs, However the fact that its not throwing exceptions, leads me to believe if i fiddled around with those flags, maybe i can get other types of mobs to spawn.

    In fact, i do believe if i change it around and lock out the previously controllable mobs, we can still get some helpful information out of that.

    So, im thinking, what do zombie pigs, endermen, spiders, blazes, and cave spiders have in common?

    Well, honestly, before blazes, i would have said they were all passive aggressive mobs. Meaning based on conditions, there may be a reason why they dont attack you. aggro for zombie pigs and endermen, and time of day for spiders..

    But why blazes?

    Hmm...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  4. This explains PathFinder via MCP:

    Code:
        public PathFinder(IBlockAccess par1IBlockAccess, boolean par2, boolean par3, boolean par4, boolean par5)
        {
            path = new Path();
            pointMap = new IntHashMap();
            pathOptions = new PathPoint[32];
            worldMap = par1IBlockAccess;
            isWoddenDoorAllowed = par2;
            isMovementBlockAllowed = par3;
            isPathingInWater = par4;
            canEntityDrown = par5;
        }
    
     
  5. Offline

    nisovin

    It's caused by the new AI. Any mob with the old AI can use a path entity to move, but the new AI doesn't use them.

    Edit: To explain further, the following mobs had their AI updated: zombies, skeletons, creepers, wolves, villagers, and all animals. The newer mobs also use the new AI: iron golems and ocelots. There are a few others (ghasts, possibly squids) that never used the same pathing, so they also don't work.
     
  6. Offline

    CorrieKay

    Thats actually really helpful. I guess ill have to create new methods PER special mob class that i make.

    Do you have any idea where to go from here, or how the new mob ai is handled?

    Wait, are the new pathfinder classes the new ai? :O
     
  7. CorrieKay I think you are searching for the classes at https://github.com/Bukkit/CraftBukkit - but that repository only keeps classes modified by the bukkit team. So if you don't find a class there look here: https://github.com/Bukkit/mc-dev instead. That repository keeps all minecraft classes (but hasn't the modifications made by the bukkit team).
    I hope you'll find what you're looking for. :)
     
  8. Offline

    CorrieKay

    Oh my, thanks a ton! this will definitely help.

    If the file can only be found in the second repo, then the bukkit team hasnt modified them, im guessing as you said, so the actual class used by the server should be the same as in the second repo, if i havnt forgotten anything.


    Hopefully i can find what im looking for, and thanks again!
     
  9. Offline

    macmc

    I mean to do the exact same thing, allowing my players to control mobs, unfortunately still haven't found any clean way to do it (setVelocity was a pretty cool way, but it wasn't quite was I expected)
    This setEntityPath solution seems to be the best, tell me if you find anything that makes it work, I'd be highly interested :D
     
  10. Offline

    CorrieKay

    well as stated in the thread, it was the old way to move mobs (though some mobs still move this way, hence why i can control spiders) Ill be on the lookout for ways to set the new mob ai to move today, if i find anything interesting, ill make sure to bump this thread ;)
     
  11. Offline

    Ziden

    couldnt you do something like yourpig extends EntityPig and change its AI to the old one ? :O
     
  12. Offline

    Sagacious_Zed Bukkit Docs

    Its a little more subtle as you also have to replace every instance of EntityPig with YourPig. Also not impossible.
     
  13. Offline

    CorrieKay

    actually, i found a way where you dont have to do that. I can control standard mojang mobs.

    basically, all you have to do is take the mob, get its EntityCreature by doing ((CraftCreature)mob).getHandle()
    then with your entity creature, you make a new Navigation object equal to EntityCreature.al();

    then you do navigation.a(x,y,z,f) where f is the mobs speed in Float.

    The speed is independant of the mob, hence my speedcreepers.

    Lol, i set wolves to 1.4f and they were... really fast xD

    oh yes, and credit to this find...

    bump for help..

    So ive been searching through the code to find a way to modify the max distance i can tell a mob to move, because it seems as though the process just gives up if the target coordinates are too far away... Is there any way to modify it? with the old AI mobs, you can modify the float you pass into the PathEntity object, and it would let you go from almost any distance.. (i went as far away as 100 blocks)

    i thought i found it with Navigator.a(float) but that didnt seem to help at all.. :c

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  14. Offline

    macmc

    Add a scheduledTask maybe? You keep the location in memory, and you divide the path the animal has to go through into several sub-paths, using a Vector or something like that?
    It could work
     
  15. Offline

    CorrieKay

    Possibly, but then i would have to figure out my own pathfinder to create the path.... which i have no idea how to do... and considering this is a 3d environment, thats all the more tricky...
     
  16. Offline

    macmc

    V10, I tried to use Wolf.setTarget to change a wolf's target, it didn't work.
    I looked at your code, and I created this function:
    Code:
    public static void setTarget(Creature entite, LivingEntity target)  {
            EntityCreature entity = ((CraftCreature) entite).getHandle();
            if(target == null) {
                entity.target = null;
            }
            else {
                entity.target = ((CraftLivingEntity) target).getHandle();
                entity.pathEntity = entity.world.findPath(entity, entity.target, 16.0F, true, false, false, true);
            }
        }
    EDIT: Found the solution, farely easy in fact... Thanks to your PathfinderGoalAggressiveTarget (it was all simply entity.b(target)
    The functions' names are so annoying...
     
  17. Offline

    CorrieKay

    yeah.... i really wish they would release an unobfuscated version :c
     
  18. Offline

    macmc

    Me too...
    V10 how to untarget entities ? I can't tell my wolf to stop attacking after using Wolf.getHandle().b(target)!
     
  19. Offline

    macmc

    Because wolf.setTarget(target) does'nt work anymore when I use the navigation tool... In fact in just did entity.b((EntityLiving)null) and it worked
     
  20. Offline

    CorrieKay

    i found out something fairly interesting today.

    Using the old mob movement (setting their path entity), for some reason, affects the client.

    Im not positive, but do you guys think that it sends the path entity to the clients, who then each pathfind?

    I had ten spiders in an arraylist, and on interact, it would take those spiders, and pathfind within a 100 block radius. I know this was gonna cause the server to lag, but... it also caused my client to lag when i used it in rapid succession...
     
  21. Offline

    Graindcafe

    Did you find something new ? I'm very interested on solving this .. I was used to use the old mob movement but apparently it's not possible anymore.
     
  22. Offline

    CorrieKay

    All mobs are controllable, as far as i can tell, you just have to use different methods for different mobs

    here, take a look at the quick tutorial i wrote for this guy
     
  23. Offline

    Graindcafe

    Thank you. I try this before but it seems not to work properly. (FYI, it was on Zombie, I was used to use the second part of code you mention on your "tutorial" but it didn't work anymore ... )
    I finally use the Keyle way you already mentionned : http://forums.bukkit.org/threads/easy-way-to-control-mounted-mobs.73021/page-2#post-1104908

    Thank you, your thread help me a lot
     
  24. Offline

    CorrieKay

    Aye, thats where i got most of my information from. You were supposed to use the first method anyways, for zombies, iirc. ^ ^ Cheers, and good luck!
     
Thread Status:
Not open for further replies.

Share This Page