Plugin Help (NMS) CustomZombie Not registering, network id already in use.

Discussion in 'Plugin Help/Development/Requests' started by yewtree8, Aug 1, 2015.

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

    yewtree8

    So I'm working with NMS, here's my main zombie class:

    Code:
    package cl.bwukkit.objects;
    
    import java.lang.reflect.Field;
    
    import net.minecraft.server.v1_7_R4.EntityHuman;
    import net.minecraft.server.v1_7_R4.EntityIronGolem;
    import net.minecraft.server.v1_7_R4.EntityVillager;
    import net.minecraft.server.v1_7_R4.EntityZombie;
    import net.minecraft.server.v1_7_R4.GenericAttributes;
    import net.minecraft.server.v1_7_R4.PathfinderGoalBreakDoor;
    import net.minecraft.server.v1_7_R4.PathfinderGoalFloat;
    import net.minecraft.server.v1_7_R4.PathfinderGoalHurtByTarget;
    import net.minecraft.server.v1_7_R4.PathfinderGoalLookAtPlayer;
    import net.minecraft.server.v1_7_R4.PathfinderGoalMeleeAttack;
    import net.minecraft.server.v1_7_R4.PathfinderGoalMoveThroughVillage;
    import net.minecraft.server.v1_7_R4.PathfinderGoalMoveTowardsRestriction;
    import net.minecraft.server.v1_7_R4.PathfinderGoalNearestAttackableTarget;
    import net.minecraft.server.v1_7_R4.PathfinderGoalRandomLookaround;
    import net.minecraft.server.v1_7_R4.PathfinderGoalRandomStroll;
    import net.minecraft.server.v1_7_R4.PathfinderGoalSelector;
    import net.minecraft.server.v1_7_R4.World;
    
    import org.bukkit.craftbukkit.v1_7_R4.util.UnsafeList;
    
    import cl.bwukkit.zombies.Main;
    
    
    
    public class CustomZombie extends EntityZombie {
    public int damage;
    private float bw;
    @Override
    protected void aD() {
    super.aD();
    this.getAttributeInstance(GenericAttributes.b).setValue(70.0D);
    }
    @SuppressWarnings("rawtypes")
    public CustomZombie(World world) {
    super(world);
    this.bw = 2.0F; //Change this to your liking. This is were you set the speed
    this.damage = Main.getInstance().getConfig().getInt("Zombie_Damage")*2; // set the damage
    this.expToDrop=0;
    //There's also a ton of options of you do this. play around with it
    try {
        Field gsa = PathfinderGoalSelector.class.getDeclaredField("a");
        gsa.setAccessible(true);
    
        gsa.set(this.goalSelector, new UnsafeList());
        gsa.set(this.targetSelector, new UnsafeList());
    
    
          this.goalSelector.a(0, new PathfinderGoalFloat(this));
          this.goalSelector.a(1, new PathfinderGoalBreakDoor(this));
          this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, this.bh, false));
          this.goalSelector.a(3, new PathfinderGoalMeleeAttack(this, EntityVillager.class, this.bh, true));
          this.goalSelector.a(4, new PathfinderGoalMoveTowardsRestriction(this, (float) this.bw));
          this.goalSelector.a(5, new PathfinderGoalMoveThroughVillage(this, this.bh, false));
          this.goalSelector.a(6, new PathfinderGoalRandomStroll(this, (float) this.bw));
          this.goalSelector.a(7, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
          this.goalSelector.a(7, new PathfinderGoalRandomLookaround(this));
    
          this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, false));
          this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
          this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityVillager.class, 0, false));
          this.getAttributeInstance(GenericAttributes.b).setValue(70.0D);
    } catch (Exception e) {
          e.printStackTrace();
    }
    }
    }
    My method of registering the object with bukkit.

    Code:
    private void registerEntity(Class entityClass, String entityName, int entityId){
            try {
                Method a = EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class);
                a.setAccessible(true);
                a.invoke(a, entityClass, entityName, entityId);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    Then enabling it in my onEnable method.
    Code:
    public void onEnable()
        {
           
            instance = this;
            scm("Instance Registered, Config Setup Initing.");
            saveDefaultConfig();
            check();
            scm("Registering Listeners");
            regListeners();
            registerEntity(CustomZombie.class, "CustomZombie", 54);
        }
        

    Then during the server startup the stack trace given is claiming to not be able to register it as the network id of zombie (54) is already taken?

    Help is appreciated.
     
Thread Status:
Not open for further replies.

Share This Page