Zombie speed and/or behavior Modification

Discussion in 'Plugin Development' started by Major_Derp, Dec 22, 2012.

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

    Major_Derp

    I wanted to know, how can i modify Zombie Speed/Behavior modification with a zombie using a minecraft plugin. I studied a little, and i found some tutorials, but they were unclear, and alot of the code has errors. Here is the code i am trying to use, any help on how to get it to work, or on any other ways i could use would be nice.
    Here is the Separate SuperZombie class:
    Code:
    public class SuperZombie extends net.minecraft.server.EntityZombie {
        public SuperZombie(World world) {
            super(world);
            this.bw = 0.28F;  //Change this to your liking. This is were you set the speed
            this.damage = 5; // set the damage
    //Theres also a ton of options of you do this.  play around with it
         
     
            try {
                Field gsa = net.minecraft.server.PathfinderGoalSelector.class.getDeclaredField("a");
                gsa.setAccessible(true);
     
                gsa.set(this.goalSelector, new UnsafeList());
                gsa.set(this.targetSelector, new UnsafeList());
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
     
            this.goalSelector.a(0, new PathfinderGoalFloat(this));
            this.goalSelector.a(1, new PathfinderGoalBreakDoor(this));
            this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, this.bw * 1.9f, false)); // this one to attack human
            this.goalSelector.a(3, new PathfinderGoalMeleeAttack(this, EntityVillager.class, this.bw, true));
            this.goalSelector.a(4, new PathfinderGoalMoveTowardsRestriction(this, this.bw));
            this.goalSelector.a(5, new PathfinderGoalMoveThroughVillage(this, this.bw, false));
            this.goalSelector.a(6, new PathfinderGoalRandomStroll(this, this.bw));
            this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F)); // this one to look at human
            this.goalSelector.a(7, new PathfinderGoalRandomLookaround(this));
            this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, false));
            this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 8.0F, 0, true)); // this one to target human
            this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityVillager.class, 16.0F, 0, false));
        }
    
    Here is the part that goes in the onEnable Section:
    Code:
    try{
                @SuppressWarnings("rawtypes")
                Class[] args = new Class[3];
                args[0] = Class.class;
                args[1] = String.class;
                args[2] = int.class;
     
                Method a = net.minecraft.server.EntityTypes.class.getDeclaredMethod("a", args);
                a.setAccessible(true);
     
                a.invoke(a, SuperZombie.class, "Zombie", 54);
            }catch (Exception e){
                e.printStackTrace();
                this.setEnabled(false);
            }
    And Here is the event to spawn the zombies in as regular:
    Code:
    @EventHandler
        public void onCreatureSpawn(CreatureSpawnEvent event){
            if (event.isCancelled()) return;
     
            Location location = event.getLocation();
            Entity entity = event.getEntity();
            CreatureType creatureType = event.getCreatureType();
            World world = location.getWorld();
     
            net.minecraft.server.World mcWorld = ((CraftWorld) world).getHandle();
            net.minecraft.server.Entity mcEntity = (((CraftEntity) entity).getHandle());
     
            if (creatureType == CreatureType.ZOMBIE && mcEntity instanceof SuperZombie == false){
                SuperZombie bloodMoonEntityZombie = new SuperZombie(mcWorld);
     
                bloodMoonEntityZombie.setPosition(location.getX(), location.getY(), location.getZ());
     
                mcWorld.removeEntity((net.minecraft.server.EntityZombie) mcEntity);
                mcWorld.addEntity(bloodMoonEntityZombie, SpawnReason.CUSTOM);
     
                return;
            }
        }
    I know that the CreatureType is deapreciated, but even with using EntityType theres still even more errors. Any help with this would be very nice.
     
Thread Status:
Not open for further replies.

Share This Page