Solved [NMS] Unpushable Mobs

Discussion in 'Plugin Development' started by TGRHavoc, Aug 7, 2014.

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

    TGRHavoc

    Ok, so I've created a custom villager, I have removed most of his default pathfinders to make sure that he doesn't wonder around on his own. I now want to make it so that he cannot be pushed by any other entities. I have tried adding the mob effect "SLOWER_MOVEMENT" to him when he spawns however, the player is still able to move him. I really don't want to use schedulers but, it's looking more like that's the only way to go. I thought that there would be a method in the NMS code with the params "Entity" to check whether he is being pushed however, I found no such method. I have also tried to set the walking speed of the villager to the minimum value of a double. If anyone has any idea of how to do this without using schedulers, I would appreciate the help.

    Code I have so far:
    Code:java
    1.  
    2. package net.subplex.TGRHavoc.VillagerSelect.Entities;
    3.  
    4. public class CustomVillager extends EntityVillager {
    5.  
    6. public CustomVillager(World world, int i) {
    7. super(world);
    8.  
    9. this.setProfession(i);
    10.  
    11. try{
    12. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    13. bField.setAccessible(true);
    14. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    15. cField.setAccessible(true);
    16.  
    17. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    18. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    19. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    20. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    21.  
    22. }catch (Exception e){
    23. e.printStackTrace();
    24. }
    25. setUp();
    26. }
    27.  
    28. public void setUp(){
    29. this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
    30. this.addEffect(new MobEffect(MobEffectList.SLOWER_MOVEMENT.id, 10000, 10000));
    31. }
    32.  
    33. @Override
    34. protected void aC(){
    35. super.aC();
    36. this.getAttributeInstance(GenericAttributes.d).setValue(Double.MIN_VALUE);
    37. this.getAttributeInstance(GenericAttributes.a).setValue(Double.MAX_VALUE);
    38. this.getAttributeInstance(GenericAttributes.c).setValue(Double.MAX_VALUE);
    39. }
    40. }
    41.  


    Ah ha! I think I have figured it out! At last...
    So, I have tested this and it works... Even if the the villager is falling. All I had to do is override the entities "move(double, double, double)" method and put no code inside.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    Plugers11

  3. Offline

    macboinc

    Can you post this code on the resources page, many people are looking for this type of information.​
     
  4. Offline

    TGRHavoc

    Plugers11
    It's in the resource section of the developer forums. (Here)
    macboinc
    Thanks for the heads up, posted the thread on there.
     
    Plugers11 likes this.
Thread Status:
Not open for further replies.

Share This Page