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):
        public void m() {
            if( && 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){
                    me = (EntityMonster)((CraftEntity)e).getHandle();
            // 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
        at net.nordicraft.dayz.CustomZombie.m( ~[?:?]
        at net.minecraft.server.v1_8_R3.EntityLiving.t_( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.EntityInsentient.t_( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.EntityMonster.t_( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.EntityZombie.t_( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.World.entityJoinedWorld( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.World.g( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.World.tickEntities( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.WorldServer.tickEntities( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A( ~[spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at [spigot-1.8.jar:git-Spigot-06ad352-4a7472d]
        at [?: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()