Custom NMS entity auto death?

Discussion in 'Plugin Development' started by Zacky1, May 6, 2014.

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

    Zacky1

    Hello everyone! So I was making a custom NMS entity and for some odd reason, it keeps killing my entities, its really weird. Ive tried debugging with setting broadcastMessages in the appropriate places (death method, sethealth method ect.) nothing is helping. Which is why I am coming here for help!

    This is using TeeePeee s NMS tutorial btw. Can be found here.

    The following constructor is being called right after onEnable();
    Code:java
    1. public MobManager(Manager manager){
    2. man = manager;
    3. loadSpawnerConfig(manager.getMcMain().getDataFolder(), true);
    4. CustomEntityType.registerEntities();
    5. }


    CustomEntityType's class works for sure, its an exact replica, and I haven't modified after my first try (which worked).

    However CustomEntityType does register the class CustomEntityZombie which looks like this:
    Code:java
    1. public class CustomEntityZombie extends EntityZombie{
    2.  
    3. private int level;
    4. private double dmg = 1.0D;
    5. private double health = 20.0D; [B]//Basically these are the only 4 things ive modified.[/B]
    6. private double range = 10.0D;
    7.  
    8. public CustomEntityZombie(World world) {
    9. super(world);
    10. Location loc = this.getBukkitEntity().getLocation();
    11. level = MobManager.getMobLevel(loc);
    12. if(level <= 5){
    13. dmg = (level*0.75) + 2;
    14. health = 20.0;
    15. }else{
    16. dmg = (level*1.5) + 2;
    17. health = 30.0;
    18. }
    19. try {
    20. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    21. bField.setAccessible(true);
    22. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    23. cField.setAccessible(true);
    24. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    25. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    26. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    27. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    28. } catch (Exception exc) {
    29. exc.printStackTrace();
    30. }
    31. this.goalSelector.a(0, new PathfinderGoalFloat(this));
    32. this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, true));
    33. this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
    34. this.goalSelector.a(6, new PathfinderGoalMoveThroughVillage(this, 1.0D, false));
    35. this.goalSelector.a(7, new PathfinderGoalRandomStroll(this, 1.0D));
    36. this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
    37. this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
    38. this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
    39. this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
    40. ItemStackTools.setEntityArmor(level, this); //[B]Nothing wrong here either[/B]
    41. }
    42.  
    43. @Override
    44. protected void aD() {
    45. super.aD();
    46. //this.bc().b(GenericAttributes.e);
    47. //this.bc().b(GenericAttributes.b); Not needed for some reason
    48. //this.bc().b(GenericAttributes.a);
    49. this.getAttributeInstance(GenericAttributes.a).setValue(health);//mob max health
    50. this.getAttributeInstance(GenericAttributes.b).setValue(range);//mob range
    51. this.getAttributeInstance(GenericAttributes.e).setValue(dmg); //mob damage
    52. }
    53.  
    54. @Override
    55. public boolean bk() {
    56. return false;
    57. }
    58.  
    59. @Override
    60. public void setHealth(float f) {
    61. super.setHealth(f);
    62. this.setCustomName("Zombie"); //Decoy for the moment
    63. }
    64. }


    So once again, this class basically registers my custom entity in the NMS to spawn every time a zombie must be spawned, however as soon as they are spawned, they die. (They're there for half a sec then they turn red and die.)

    Might I add that no errors are thrown nor messages in debug mode
     
Thread Status:
Not open for further replies.

Share This Page