Solved Disable Entity Movement

Discussion in 'Spigot Plugin Development' started by MissingPotato, Aug 1, 2021.

  1. Hey, I'm wokring on an NPC system for my plugin ( I do not want to depend on other people's packages + I need a lot of freedom in code )

    Does anyone have any suggestion for keeping LivingEntities in one place at all times without disabling their lookat?
    Here is what I tried to date:
    Code (YAML):
    Method 1: Disable AI
    : By disabling the AI the NPC will not be using "lookat" to follow players around and will look like a static image.

    Method 2
    : Disable Gravity
    : Players can push the entity around and make it fly away, if I block the NPC with actual invisible blocks it just looks janky

    # ( Current Method )
    Method 3
    : Pants with attribute slowness 1000
    : Same exact issue as with gravity, but a little better since now the NPC can't just fly away when it's in open space.

    Method 4
    : Riding an invisible entity with gravity OFF and AI OFF
    : It's terribly hard to align the entity in position, spawning it will always make it float off the ground a little bit or something along those lines.
    I would truly appreciate any kind of help, thanks a lot!

    P.S I would like to avoid such events as "PlayerMoveEvent" as they trigger so many times it's going to have a massive effect over TPS.
  2. You could overriding the move(MovementType, Vec3D) method, the movementTick() method or the vector calculation.

    The method for vector calculation in nms 1.16R3 is g(Vec3D vec3d). Didn't know the obfuscated Name it for 1.17 R1.

    Keep in mind. Entities that can move are not LivingEntity the are EntityInsentient. Entities wich extends EntityLiving can take damage.

    Entity//They are ticking. The move method is here. But it is no movement it is more like setVelocity in bukkit. But NMS works with movement vectors. (Vector between Position from to Position to.
    EntityLiving//can take damage
    EntityInsentient//Will walk. Or can change their Position by itself. (move)

    Keep in mind:
    Pretty good NPCs requires to overriding of the Controllers in EntityInsentient, the PathfinderAbstract and it's childs (this isn't PathfinderGoal) and the Navigation.
    I took one week for sth like this in 1.16. But now i have PathTrackers and Navigators ^^

    I hope I could help you.
    Good luck :D
    #2 Player_Schark, Aug 1, 2021
    Last edited: Aug 1, 2021
    • Like Like x 1
  3. Thank you so much my dude, I will take a look at it and give it a spin, not really an Expert on Java as I come from a C++/golang/web backend background.

    Thank you so much again!
  4. Isn’t there a NBTTag to completely freeze entities? I’ve already done this I can check my code once at home
  5. I would highly appreciate this. I'm also interested :)
  6. There is a setWalkSpeed method that might be usable, or more sophisticated the Attribute API.
  7. Have you looked at the new 1.17 API method Mob#setAware()? From the docs:
  8. Unaware mobs will still move if pushed, attacked, etc. but will not move or perform any actions on their own.
  9. Would whole-heartedly appreciate it if you could pass me the NBT tag, this has really been a struggle
  10. Sadly this still leaves the mob open to being pushed by players, it's no different than my current method with the leggings, or simply applying slowness 10000
  11. Did you tried exactly 200. Eg. Jump Boost lvl 200 disables jumping for players. But only 200. This value is hardcoded in nms.

    You could try setCollidable. I am very confident

    If that won't work the nms way could be the only one :/
    • Informative Informative x 1
  12. Let the villager ride an invisble marker armorstand.
    Marker armorstands have a height of 0
    • Funny Funny x 1
    • Informative Informative x 1
  13. Actually the code completely freezes the entity so it cannot look around :/
    • Optimistic Optimistic x 1
  14. Use the vector calculation. Override it and return Vec3d(0,0,0)

    In 1.16R3 this method is called g(Vec3d) in EntityInsentient. Don't know the name in 1.17. But it's parameters should be the same.
    • Like Like x 1
  15. This sounds like a plan, I'll give it a spin, thanks!

    Yeap! The 200 does the trick but the collisions were the problem, as soon as I find some time tomorrow i'll come back with an update on my progress.
    Thanks so much for the help!
  16. Maybe
    • Winner Winner x 1
  17. Setting gravity to false
    Setting collisions to false

    Absolutely perfect and wonderful! Thanks a bunch for the help, I never even checked for the collision condition :)