Cancelling mob movement

Discussion in 'Plugin Development' started by xigsag, Feb 1, 2017.

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

    xigsag

    I am trying to stop a mob (villager) from moving.

    setAI(false) turns it completely into a statue, so that's a no-go. I am also not familiar with NMS, and am not up to date to the field name changes, but from what I've seen, the field for the entity's speed changes every few updates.

    Can I get some help with the best way to stop a mob from moving? Specifically, a villager that doesn't walk around, but turns it's head around. Preferably, I wouldn't want to use runnables.

    Please and thank you.
     
  2. Offline

    ShaneCraftDev

    If you do not want to use NMS, you can try to make use of your villager mounting a projectile (arrow, snowball) without velocity. I am not sure if the body rotates freely, but the head yaw and pitch does for sure.
     
  3. Offline

    Zombie_Striker

  4. Offline

    Drkmaster83

    @xigsag Alternatively, you can set the Mob's movements speed attribute to 0, but this still allows them to be pushed around by other entities.
     
  5. @xigsag
    You could also use the old workaround of giving the Villager slowness 5. Although @Drkmaster83's method is way cleaner.
     
  6. Offline

    xigsag

    Thanks for the replies!

    I am not on my computer right now, so I will try these out when I am.
    But for now, I think @ShaneCraftDev 's idea is interesting.


    @Drkmaster83 Doesn't that use NMS? As mentioned, does the field managing the speed attribute change over updates? I've never done much NMS, and I honestly don't know much about how to figure out which field does what. But that doesn't stop it from being pushed around either, does it? I will look into this further, but going in blindly, I won't count on it.


    @AlvinB Yes, that solves the villager moving on it's own. Now to prevent it from being pushed around.

    @Zombie_Striker Yes, I have seen that and have also seen many people being linked to it. Possibly by you as well. I was a bit skeptical about this, seeing as it's based off 1.7 nms, but since it's still being referenced I'm sure there won't be too big of a codebase gap, especially after the frostburn update.

    Then again, I'm only coming back to plugin development after a really long time, so I'm gonna have a lot to keep up to.
     
  7. @xigsag
    @Drkmaster83's method does not use NMS, you can edit attributes with Bukkit.
    Code:java
    1. villager.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0);
    And to solve the pushing, I'd use the setCollidable(false) method. Although if you do use that, you should be aware of this (from the javadocs):

    "Note that collisions are bidirectional, so this method would need to be set to false on both the collidee and the collidant to ensure no collisions take place."
     
  8. Offline

    xigsag

    @AlvinB This is very helpful. Didn't know that you could do that now. Thanks a lot for the help.
     
  9. Offline

    Drkmaster83

    That'd be interesting test... I remember having to use spigot since I didn't want to use NMS a few years ago, you could do the same thing, it was just exclusive to spigot. Do you know if that's saying that entities won't move if their collidable is false, or if they won't move only if both are set to false? I would hate for it to be the latter. What if I want players to collide with each other but not villagers? (Perhaps the answer is proximity to a nearby villager, say, distance < 1, but still, players wouldn't be able to collide with each other within that radius/[/user]

    Also, @AlvinB thanks for the credit! I guess I didn't want to look up the method, but it does indeed exist outside of NMS!
     
Thread Status:
Not open for further replies.

Share This Page