Issue with custom Zombie

Discussion in 'Spigot Plugin Development' started by dadus33, May 29, 2016.

  1. Hello guys, I'm trying to make a zombie that doesn't burn in the sun. I know, I could simply cancel that with an event handler, but I also want to change it's behavior in the sun (like hiding in dark places to avoid sun). AFAIK, this can only be accomplished through NMS. I made a CustomZombie class that extends EntityZombie, but simply @Overriding the m() method (which I discovered is the one responsible with making them burn) won't work, because, in the original Zombie class, the m() method had a call to it's supperclass m() method (that is, EntityMonster.m() ). However, calling super.m() from my CustomZombie.class will instead call not the EntityMonster.m() method, but the original EntityZombie.m() method, ruining all I've tried to do. Also, because of the restrictions of java, there's no way I can use something like super.super.m()... I've tried even using reflection, but ended up each time with InvocationTargetException. The last thing I tried was actually getting my EntityZombie as a more generalized EntityZombie. I accomplished this by getting the chunk my zombie was in, got all the entities in it and checked which one had the exact same UUID as my zombie (which automatically meant it was my zombie) and casted that to EntityMonster. It proved to be working in theory, but when I tried spawinig a zombie on my server I ended up crashing it...
    Here's the code for the above thing:

    Code (Text):
        @Override
        public void m() {
            if(this.au() && this.getGoalTarget() != null && this.vehicle instanceof EntityChicken) {
                ((EntityInsentient)this.vehicle).getNavigation().a(this.getNavigation().j(), 1.5D);
            }
           
           
           
           
            EntityMonster me = null;
            org.bukkit.entity.Entity[] entits = world.getChunkAt((int)Math.round(this.locX), (int)Math.round(this.locZ)).bukkitChunk.getEntities();
            for(org.bukkit.entity.Entity e : entits){
                if(e.getUniqueId().equals(this.getUniqueID())){
                    me = (EntityMonster)((CraftEntity)e).getHandle();
                    break;
                }
            }
            me.m(this);
               
            // The whole block above is meant to mimic the action of super.m() as it would have been run from the original EntityZombie class.
        }
    And here's the error I'm getting:
    Code (Text):
    [16:36:20 ERROR]:     Cause of unexpected exception was
    java.lang.NullPointerException
        at net.nordicraft.dayz.CustomZombie.m(CustomZombie.java:182) ~[?:?]
        at net.minecraft.server.v1_8_R3.EntityLiving.t_(EntityLiving.java:1487) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.EntityInsentient.t_(EntityInsentient.java:193) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.EntityMonster.t_(EntityMonster.java:24) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.EntityZombie.t_(EntityZombie.java:221) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.World.entityJoinedWorld(World.java:1607) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.World.g(World.java:1582) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.World.tickEntities(World.java:1425) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.WorldServer.tickEntities(WorldServer.java:597) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:786) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]
    And then the server crashes.
    Thanks for the help!



    BTW I'm using 1.8.
     
  2. Where is line 182?
     
  3. at me.m(); btw ignore the this argument, it should have only been me.m()