NMS Villager

Discussion in 'Plugin Development' started by candyfloss20, Oct 24, 2014.

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

    candyfloss20

    Hello there,
    Well I'm having a problem with this little guy http://prntscr.com/4zabgr (NPC Villager)
    I have got it working so it opens the Stats Inv not the trading Inv.
    BUT I cant find away to stop his move packets. (AND I MEAN FULLSTOP)
    Ie: he cant path find and he can be pushed (With NMS Code)
    I have been trying to do this for weeks but all the ways and post on bukkit just crash my client when I enter the same chuck as him.

    Regards
    candyfloss20
    PS: Thanks in advance you will literally be a life saver
     
  2. Offline

    xTDKx

    Create a custom mob, then override these collision methods:
    Code:java
    1. @Override
    2. public void g(double d0, double d1, double d2) {
    3. return;
    4. }
    5.  
    6. @Override
    7. public void collide(Entity e) {
    8. return;
    9. }
     
  3. Offline

    candyfloss20

    xTDKx
    But how would one spawn said custom mob at a location without it crashing player games
    and Thanks <3

    xTDKx
    so got this:
    Code:java
    1. public class SammyStatsNPC extends EntityWitch {
    2.  
    3. public SammyStatsNPC(org.bukkit.World world) {
    4. super(((CraftWorld)world).getHandle());
    5.  
    6. List goalB = (List) getPrivateField("b", PathfinderGoalSelector.class, goalSelector);
    7. goalB.clear();
    8. List goalC = (List) getPrivateField("c", PathfinderGoalSelector.class, goalSelector);
    9. goalC.clear();
    10. List targetB = (List) getPrivateField("b", PathfinderGoalSelector.class, targetSelector);
    11. targetB.clear();
    12. List targetC = (List) getPrivateField("c", PathfinderGoalSelector.class, targetSelector);
    13. targetC.clear();
    14.  
    15. }
    16.  
    17. public static Object getPrivateField(String fieldName, Class clazz, Object object) {
    18. Field field;
    19. Object o = null;
    20.  
    21. try {
    22. field = clazz.getDeclaredField(fieldName);
    23.  
    24. field.setAccessible(true);
    25.  
    26. o = field.get(object);
    27. } catch (NoSuchFieldException e) {
    28. e.printStackTrace();
    29. } catch (IllegalAccessException e) {
    30. e.printStackTrace();
    31. }
    32.  
    33. return o;
    34. }
    35.  
    36. @Override
    37. public void g(double d0, double d1, double d2) {
    38. return;
    39. }
    40.  
    41. @Override
    42. public void collide(Entity e) {
    43. return;
    44. }
    45.  
    46. public enum EntityTypes {
    47. SAMMY_STATS("Witch", 66, SammyStatsNPC.class);
    48.  
    49. private EntityTypes(String name, int id, Class<? extends Entity> custom) {
    50. addToMaps(custom, name, id);
    51. }
    52.  
    53. public static void spawnEntity(Entity entity, Location loc) {
    54. entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    55. ((CraftWorld) loc.getWorld()).getHandle().addEntity(entity);
    56. }
    57.  
    58. private static void addToMaps(Class clazz, String name, int id) {
    59. ((Map)getPrivateField("c", net.minecraft.server.v1_7_R3.EntityTypes.class, null)).put(name, clazz);
    60. ((Map) getPrivateField("d", net.minecraft.server.v1_7_R3.EntityTypes.class, null)).put(clazz, name);
    61. ((Map)getPrivateField("e", net.minecraft.server.v1_7_R3.EntityTypes.class, null)).put(Integer.valueOf(id), clazz);
    62. ((Map) getPrivateField("f", net.minecraft.server.v1_7_R3.EntityTypes.class, null)).put(clazz, Integer.valueOf(id));
    63. ((Map)getPrivateField("g", net.minecraft.server.v1_7_R3.EntityTypes.class, null)).put(name, Integer.valueOf(id));
    64. }
    65. }
    66. }


    and im spawing it with this:

    Code:java
    1. @Override
    2. public void onEnable() {
    3.  
    4. lm = new ListenerManager(this);
    5. cm = new CommandManager(this);
    6.  
    7. ps = new PointSystem(this);
    8. ss = new StatsSystem(this);
    9. sPs = new SpawnsSystem(this);
    10. prs = new PrefixSystem(this);
    11. kus = new KitUnlockSystem(this);
    12.  
    13. ks = new KitSelector(this);
    14.  
    15. vote = new VotifierListener(this);
    16.  
    17. for (Entity entitys : Bukkit.getWorld("world").getEntities()) {
    18. if (entitys.getType() != EntityType.PLAYER) {
    19. entitys.remove();
    20. }
    21. }
    22.  
    23. SammyStatsNPC.EntityTypes.spawnEntity(new SammyStatsNPC(Bukkit.getWorld("world")), SpawnsSystem.getSpawn(6));
    24.  
    25. }
    26. }
    27.  


    But the entity wont spawn and there is no errors in the console

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

    fireblast709

    candyfloss20 teleport yourself to it's position. Also make sure you entity is alive and well after the addEntity method (for all we know, another plugin could've killed it in the CreatureSpawnEvent)
     
  5. Offline

    candyfloss20

    fireblast709
    the location is fine not in a block or null

    Its set to spawn at Spawn6 in the config:
    http://prntscr.com/4zf62t
    And its not the server I spawned a normal Entity with a /test command and it spawned it ONLY the NMS mob that wont spawn it must be a error
     
Thread Status:
Not open for further replies.

Share This Page