Stop an entity from moving

Discussion in 'Plugin Development' started by MCCoding, May 18, 2014.

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

    MCCoding

    I have been looking around to try and find out on how to completely stop an entity from moving, but i can't find one that is working and using NMS so that i don't need to have a runnable teleporting the entity every tick. I'm wanting to know if there is a NMS way or reflection way to do this. All i'm trying to do is if you spawn in a entity it will just freeze there, with out a runnable in the background using up lots of memory. If you know how or know of a attribute i can override let me know as i have been looking around and can't find anything of use.
     
  2. Offline

    Wingzzz

    There are a few ways of doing this. You could:
    1. Use a beautiful runnable that teleports the entity to its location (oh the performance joy!)
    2. Override the entity via NMS (you can find tutorials by jacek on the forums about custom entities)
    3. Use a slowness potion that is ambient (unless you want the swirls). Although I've noticed this approach (at least on players) will still let them move 0.000001 or so each time they move. Not sure with mobs.
    4. Set the mobs "speed" attribute to 0. This would require you to use NMS (either with or without reflection)- dangerous, but if you're willing to keep up the code or use a version handler you should be fine. You can find a tutorial here: https://forums.bukkit.org/threads/tutorial-setting-entity-attributes.158065/
    Hopefully one of those fits your needs!
     
  3. Offline

    MCCoding

    Wingzzz how would number 3 work? With out the potion swirls, and would it stop the mob from moving completely? Also is there a way of preventing players from pushing the entity?
     
  4. Offline

    Wingzzz

    You would just need to give the mob a potion effect of really high slowness. As for whether or not it will stop moving 100% completely I'm unsure. With players they can still sort-of move but it's so minuscule that it's perfect for short-term freezing.

    As for preventing players from pushing an entity from what I know that is handled client-side. I don't believe you can stop this without intercepting packets (if there is even a packet for this- which I don't think there is after a quick peak at http://wiki.vg/Protocol).
     
  5. Offline

    MCCoding

    Wingzzz
    Ah okay then adding a potion effect won't work them since it won't be short term, NMS is looking like the best way to go I just need to find the attribute to override to stop movement which I have no idea what it is
     
  6. Offline

    Wingzzz

    View #4 that I mentioned. It will allow you to get the entities "speed" attribute and set it to 0.
     
  7. Offline

    MCCoding

    Wingzzz
    Ah okay that should work, do you happen to know what the Villagers speed attribute is ?
     
  8. Offline

    Wingzzz

    After quick glance at https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/GenericAttributes.java
    I can see:
    Code:java
    1. public static final IAttribute d = (new AttributeRanged("generic.movementSpeed", 0.699999988079071D, 0.0D, Double.MAX_VALUE)).a("Movement Speed").a(true);


    Which I would assume is the default for villagers perhaps (not sure since this is generic)? You could simply get the value of a villager and then log what it is and work off that :)
     
Thread Status:
Not open for further replies.

Share This Page