Stop mob/NPC from moving

Discussion in 'Plugin Development' started by lololmaker, Jul 11, 2012.

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

    lololmaker

    I want to be able to stop every npc's movement, except maybe yaw, pitch. How can I accomplish this with as clean code as possible, since there is no EntityMoveEvent (Bukkit should add one ?).
    That's it, just want to keep them in place, not be able to move, I believe Citizens can do this, but can't find it in source code.
     
  2. Offline

    EnvisionRed

    ferrybig and lololmaker like this.
  3. Offline

    lololmaker

    Anyone else maybe ?
    Basically I have list of mob IDs, possibly in DIFFRENT worlds (multiverse etc.) and I want to stop their movement.
    It could be done with for loops and Async repeating tasks, but it would cause lag, checking and comparing 30k+ ids, then setting their position, it wouldn't be smooth at all.
     
  4. Correction, you should use Sync repeating tasks, because async repeating tasks cannot access bukkit methods.
     
  5. Offline

    EnvisionRed

    I access bukkit methods in my asyncrepeatingtask with no issue. Of course it's just stuff like getConfig so there shouldn't be a huge issue. I haven't noticed any errors so far.

    I've done something like this in MCPets.
    You realize that in a custom mob class, if you don't have the entity actually move if the MoveEvent is cancelled, that's the solution to your issue?

    Let's say you've got a list of UniqueIds.

    You could do something like this:
    Code:
    @EventHandler
    public void stopFrozenMobs(MobMoveEvent event){
    List<UUID>frozenMobs; //declare it as actually equal to whatever your list is in your code
    Entity e = event.getEntity();
    if (frozenMobs.contains(e.getUniqueId())){
    event.setCancelled(true);
    return;
    }else{
    return;
    }
    }
     
  6. Offline

    lololmaker

    Is there something like MobMoveEvent ? Didn't check ...
     
  7. Offline

    EnvisionRed

    There is not one included in Bukkit, but you can create your own custom mobs which throw this event every time they are about to move. Everything as detailed in:
    But I guess you didn't read that.
     
  8. Offline

    lololmaker

    I didn't really read it all, but I will, thanks anyway !
    Will report back later how it goes ... I'm storing Unique IDs and some other values in MultiMap by Google, didn't really find a way to store multiple values per key, is there on already in Java ?
     
  9. Offline

    EnvisionRed

    Er, not that I know of.
    I found that for MCPets I had to store a lot of values in hashmaps; I eventually gave up everything to do with hashmaps and had it write pet data (owner name, pet name, sitting, sittingLocation) to a Pets.yml file.
     
  10. Offline

    lololmaker

    Anyway, this is what I was talking about:
    http://code.google.com/p/guava-libraries/

    Usage:
    http://tomjefferys.blogspot.com/2011/09/multimaps-google-guava.html


    Gonna play a few games of Battlefield and than try controlling NPC ;)

    I don't quite understand, since it's changing actual behaviour.

    I extend EntityZombie, but when it comes to
    Code:
    ZombieMoveEvent event = new ZombieMoveEvent(zombie, from, to);
    It errors.
    "Cannot resolve symbol ZombieMoveEvent", Because it obviously doesn't exist...

    Also it cannot resolve
    Code:
    super.s_();
    Anything, anyone ?

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

    SchmidtMathias

    I just tried the same and received an answer from md_5 telling me I need to reflect the EntityMonster and EntityAnimal classes and wipe out all the AI-Features.
     
  12. Offline

    EnvisionRed

    That was an old post, the move method is now "F_" not "s_"
     
  13. Offline

    lololmaker

    Okay, I will try that later, doing some other plugin atm.
     
Thread Status:
Not open for further replies.

Share This Page