NMS odd error

Discussion in 'Plugin Development' started by dNiym, Feb 14, 2017.

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

    dNiym

    Okay I have been playing around with some NMS code and was able to create my own extended version of a zombie, modify its AI and some other things.

    Thus i figured I would work on making rabid dogs that run around and attack players, so I went about this the same way.

    However; I have run into two issues:
    #1) If the wolf falls from a height where it would normally take damage it crashes the server, I got around this by just cancelling fall damage as a band-aid.

    #2) I get a NPE whenever I attack the dog it has been attached here: http://pastebin.com/nUEfYMH1

    14.02 17:15:31 [Server] INFO at NMS.sdWolf.damageEntity(sdWolf.java:91) ~[?:?]
    The above line is simply where the code passes the values back to the super..
    return super.damageEntity(damagesource, f);

    At this point in the code, just before control is sent back to the super the values are:
    14.02 17:15:31 [Server] INFO Damage source was: net.minecraft.server.v1_11_R1.EntityDamageSource@c095858 for: 6.0

    so damage isn't null and the damagesource isn't null.

    Any ideas?
    Just in case you need it here is my extended wolf class. http://pastebin.com/CseVNJ9N
    *edit* here's a copy of the crash report when the wolf took fall damage. http://pastebin.com/aeHRqcAn


    Thanks in advance!
     
  2. Offline

    Zombie_Striker

    @dNiym
    For both, have you tried debugging? If you "Comment-out" all the lines for the damage method, does that fix the NPE and crashing issue? If so, slowly re-add each line until you find out which line is causing the problem. Once you do, post it here.
     
  3. Offline

    dNiym

    The damage method is an exact copy of what's in the EntityWolf.java file, I only copied it out and overrode it to add the debug line to make sure damagesource wasn't somehow null. If I Comment the function out completely I get the same error in EntityWolf.java which sdWolf.java extends.


    http://pastebin.com/DHZFBe58 <- stack trace with damage method commented out.

    The line in EntityWolf.java that causes the error is the same as when I just copied it out and overrode it:
    return super.damageEntity(damagesource, f);



    http://pastebin.com/bNg52aXY <-- updated sdWolf.java with damage method commented out.

    http://pastebin.com/V0aJPEWa <-- EntityLiving.java (well part of it, line 870 is marked where the first error is

    EntityLiving.java seems to be the first thing to show a NPE on the line
    this.a((EntityLiving) entity1);

    which does not make a whole lot of sense to me since the a() method in this file appears to have to do with block position?

    I don't really have anything that modifies damage written in yet, I was just experimenting with creating some custom AI for npcs, the zombie works fine, the witch works fine (Which I made after the wolf) , this wolf however not so much.
     
  4. Offline

    Zombie_Striker

    @dNiym
    If your witch and zombie works fine, then it has something to do with the way you set up the world/ something with the wolf itself. What happens if you comment everything in the wolf class, so it has no AI and so there is no modifications to the wolf.
     
  5. Offline

    dNiym

    @Zombie_Striker

    /*
    @Override
    public void r() {

    }
    */

    Okay I commented out this bit and the wolf no longer crashes the server on fall damage and does not produce the NPE... HOWEVER it seems to have default AI with the exception of being angry.

    the stock r() method does the following. http://pastebin.com/G5abB4W8
    Which appears to be all pathfinder code and nothing else.. I am setting different pathfinding goals in my setDefaultGoals() method however I don't really understand what the r() method is doing to the mob other than setting the goals.

    I tried adding setDefaultGoals() into the r() method with nothing else and still get the server crash / npe when attacking the mob.


    EDIT: Okay I found whats causing the server to crash if omitted in the r() method.
    this.goalSit = new PathfinderGoalSit(this);
    If this line is commented out the server will crash if the wolf falls from a height where it would normally take damage.

    If i leave this line in however, and then add back in my setDefaultGoals() code the wolf just stands there and only growls, it will not pursue players or attack back if attacked. It does behave as desired with the goalSit line commented out.
     
    Last edited: Feb 15, 2017
  6. Offline

    JanTuck

    Try adding. 'super.r()' in the function as a fallback.

    Sendt fra min ALE-L21 med Tapatalk
     
  7. Offline

    dNiym

    @JanTuck
    Adding in super.r();
    does prevent the server from crashing when the mob takes fall damage, but it does not let me set the AI as expected.
    if this line exists in r() or if super.r() is called
    this.goalSit = new PathfinderGoalSit(this);

    none of my Pathfinder goals seem to do anything. Something else is clearly overriding the behavior of the wolf. It will occasionally turn and look at me but nothing else from the AI fires.
     
    Last edited: Feb 15, 2017
  8. Offline

    JanTuck

    Have you looked at the source?

    Code:
    
    @Override protected void r() { this.goalSit = new PathfinderGoalSit(this); this.goalSelector.a(1, new PathfinderGoalFloat(this)); this.goalSelector.a(2, this.goalSit); this.goalSelector.a(3, new a(this, EntityLlama.class, 24.0f, 1.5, 1.5)); this.goalSelector.a(4, new PathfinderGoalLeapAtTarget(this, 0.4f)); this.goalSelector.a(5, new PathfinderGoalMeleeAttack(this, 1.0, true)); this.goalSelector.a(6, new PathfinderGoalFollowOwner(this, 1.0, 10.0f, 2.0f)); this.goalSelector.a(7, new PathfinderGoalBreed(this, 1.0)); this.goalSelector.a(8, new PathfinderGoalRandomStrollLand(this, 1.0)); this.goalSelector.a(9, new PathfinderGoalBeg(this, 8.0f)); this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0f)); this.goalSelector.a(10, new PathfinderGoalRandomLookaround(this)); this.targetSelector.a(1, new PathfinderGoalOwnerHurtByTarget(this)); this.targetSelector.a(2, new PathfinderGoalOwnerHurtTarget(this)); this.targetSelector.a(3, new PathfinderGoalHurtByTarget(this, true, new Class[0])); this.targetSelector.a(4, new PathfinderGoalRandomTargetNonTamed<EntityAnimal>(this, EntityAnimal.class, false, new Predicate(){ public boolean a(@Nullable Entity entity) { if (!(entity instanceof EntitySheep) && !(entity instanceof EntityRabbit)) { return false; } return true; } public boolean apply(@Nullable Object object) { return this.a((Entity)object); } })); this.targetSelector.a(5, new PathfinderGoalNearestAttackableTarget<EntitySkeletonAbstract>(this, EntitySkeletonAbstract.class, false)); }
    
     
  9. Offline

    dNiym

    @JanTuck
    yes, which is where i'm confused at. I don't see anything in the r() function that references fall damage, or taking melee damage. I assume the NPE and fall damage were because
    this.goalSit = was not set thus null. By setting that then my own pathfinder goals it should be fine right? Well the crashing and NPE's are gone but the Wolf's AI does not function like it does without the goal.sit line & the rest of r() overridden / commented out.

    Not really sure where to look next, the EntityWolf class extends EntityTamableAnimal but there is no EntityTamableAnimal in my craftbukkit NMS folder.
     
Thread Status:
Not open for further replies.

Share This Page