[URGENT] NMS entities

Discussion in 'Plugin Development' started by CaptainUniverse, Nov 14, 2014.

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

    CaptainUniverse

    Hi people! HUGE PROBLEM! I Finally got NMS entities to work but now they are spawning the custom way even in my survival world (I only want them to spawn custom in hub)

    CustomZombie.class
    Code:java
    1. public class CustomZombie extends EntityZombie{
    2. public CustomZombie(org.bukkit.World world) {
    3. super(((CraftWorld)world).getHandle());
    4. if (world.getName().equals("hub")) {
    5. this.getAttributeInstance(GenericAttributes.d).setValue(0.0D);
    6. this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 10.0F));
    7. Zombie v = (Zombie)this.getBukkitEntity();
    8. v.setRemoveWhenFarAway(false);
    9. }
    10. this.world = ((CraftWorld)world).getHandle();
    11. }
    12. public CustomZombie(World world) {
    13. super(world);
    14. if (world.getWorld().getName().equals("hub")) {
    15. this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
    16. this.getAttributeInstance(GenericAttributes.d).setValue(0.0D);
    17. Zombie v = (Zombie)this.getBukkitEntity();
    18. v.setRemoveWhenFarAway(false);
    19. }
    20. this.world = world;
    21. }
    22. protected String t() {
    23. if (world == ((CraftWorld)Bukkit.getWorld("hub")).getHandle()) {
    24. return null;
    25. }else{
    26. return "mob.zombie.say";
    27. }
    28. }
    29. public World world;
    30. public void g(double d0, double d1, double d2) {
    31. if (world == ((CraftWorld)Bukkit.getWorld("hub")).getHandle()) {
    32. return;
    33. }else{
    34. this.motX += d0;
    35. this.motY += d1;
    36. this.motZ += d2;
    37. this.al = true;
    38. }
    39. }


    Main (onEnable) where i spawn my "Zombie"
    Code:java
    1. //on enable
    2. registerEntity("Zombie",54,EntityZombie.class, CustomZombie.class);
    3. CustomZombie z = new CustomZombie(Bukkit.getWorld("hub"));
    4. z.setCustomName(ChatColor.AQUA + "" + ChatColor.BOLD + "AstroCraft Helper " + ChatColor.GREEN + "" + ChatColor.DARK_GREEN + "[" + ChatColor.GREEN + "EARN COINS" + ChatColor.DARK_GREEN + "]");
    5. z.world.addEntity(z, SpawnReason.CUSTOM);
    6. z.setPosition(104, 2, 101);
    7. //register entity from tutorial
    8. @SuppressWarnings({ "rawtypes", "unchecked" })
    9. public void registerEntity(String name, int id, Class<? extends EntityInsentient> nmsClass, Class<? extends EntityInsentient> customClass)
    10. {
    11. try
    12. {
    13. List<Map<?, ?>> dataMaps = new ArrayList();
    14. for (Field f : EntityTypes.class.getDeclaredFields()) {
    15. if (f.getType().getSimpleName().equals(Map.class.getSimpleName()))
    16. {
    17. f.setAccessible(true);
    18. dataMaps.add((Map)f.get(null));
    19. }
    20. }
    21. if (((Map)dataMaps.get(2)).containsKey(Integer.valueOf(id)))
    22. {
    23. ((Map)dataMaps.get(0)).remove(name);
    24. ((Map)dataMaps.get(2)).remove(Integer.valueOf(id));
    25. }
    26. Method method = EntityTypes.class.getDeclaredMethod("a", new Class[] { Class.class, String.class, Integer.TYPE });
    27. method.setAccessible(true);
    28. method.invoke(null, new Object[] { customClass, name, Integer.valueOf(id) });
    29. for (Field f : BiomeBase.class.getDeclaredFields()) {
    30. if ((f.getType().getSimpleName().equals(BiomeBase.class.getSimpleName())) &&
    31. (f.get(null) != null)) {
    32. for (Field list : BiomeBase.class.getDeclaredFields()) {
    33. if (list.getType().getSimpleName().equals(List.class.getSimpleName()))
    34. {
    35. list.setAccessible(true);
    36.  
    37. List<BiomeMeta> metaList = (List)list.get(f.get(null));
    38. for (BiomeMeta meta : metaList)
    39. {
    40. Field clazz = BiomeMeta.class.getDeclaredFields()[0];
    41. if (clazz.get(meta).equals(nmsClass))
    42. {
    43. clazz.set(meta, customClass);
    44. }
    45. }
    46. }
    47. }
    48. }
    49. }
    50. }
    51. catch (Exception e)
    52. {
    53. e.printStackTrace();
    54. }
     
  2. Offline

    xTrollxDudex

    You are replacing the original zombie class with your own when you register it.
     
  3. CaptainUniverse Also, this isn't urgent. Please don't do that, it's rude to other posters :)
     
Thread Status:
Not open for further replies.

Share This Page