Spawning Custom NMS Entities Naturally

Discussion in 'Plugin Development' started by Moody3939, Jun 23, 2016.

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

    Moody3939

    I'd like to apologize for possibly putting this in the wrong area. I'm new to the forum.

    I have a custom NMS mob (Zombie) that I can spawn flawlessly. I need to be able to spawn this custom mob rather than spawning vanilla zombies. Is there any way of doing this? I have been researching all day but couldn't find anything.

    Code:
    public static void spawnCustomEntity(Location loc, String name)
        {
            net.minecraft.server.v1_7_R3.World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
            if (name == "CustomZombie")
            {
                CustomZombie zombie = new CustomZombie(nmsWorld);
                zombie.setPosition(loc.getX(), loc.getY(), loc.getZ());
                zombie.setCustomName("Zombie");
                nmsWorld.addEntity(zombie);
            }
        }
    Code:
    public class CustomZombie extends EntityZombie
    {
    
        @SuppressWarnings("rawtypes")
        public StandardZombie(World world)
        {
            super(world);
            List goalB = (List) Main.getPrivateField("b", PathfinderGoalSelector.class, goalSelector); goalB.clear();
            List goalC = (List) Main.getPrivateField("c", PathfinderGoalSelector.class, goalSelector); goalC.clear();
            List targetB = (List) Main.getPrivateField("b", PathfinderGoalSelector.class, targetSelector); targetB.clear();
            List targetC = (List) Main.getPrivateField("c", PathfinderGoalSelector.class, targetSelector); targetC.clear();
        }
       
    }
    
    P. S. I have tried to use CreatureSpawnEvent, but I couldn't find an effective way of replacing the vanilla zombie with the custom zombie without creating an endless loop of death :(
     
  2. Offline

    MisterErwin

    @Moody3939 You might want to take a look at this thread.
    It is slightly outdated (but you most likely will find an update in the comments)
     
  3. Offline

    Moody3939

    Thank's for such a quick reply. Unfortunately I was unable to find an update for that code. But I figured a workaround - I used CreatureSpawnEvent to check the ticks lived, spawned my custom zombie, and the set the ticks lived. Thanks for the help though!
     
Thread Status:
Not open for further replies.

Share This Page