Solved Entity not storing variables

Discussion in 'Plugin Development' started by Niv-Mizzet, Aug 18, 2020.

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

    Niv-Mizzet

    Hi there everyone!
    So I am making a custom entity with a custom pathfinder goal, however the initPathfinder() method can't seem to access the variables assigned in the constructor(specifically team), whenever I reference them it comes out as null.
    The class is called CustomZombie and it extends EntityZombie
    Here is my class:
    Code:
        Team team;
        Player hi;
        public CustomZombie(Location loc, Team t, Player p){
    
            super(EntityTypes.ZOMBIE, ((CraftWorld) loc.getWorld()).getHandle());
            this.team=t;
            this.hi=p;
            this.setPosition(loc.getX(), loc.getY(), loc.getZ());
            if(t!=null){
            this.setCustomName(new ChatComponentText(t.getKind().getColor() +"Zombie - "+t.getName()+" Team"));
            this.setCustomNameVisible(true);
            Zombie nicezombie=(Zombie) this.getBukkitEntity();
            ItemStack helmet=t.getKind().getHat();
            ItemMeta im=helmet.getItemMeta();
           im.setUnbreakable(true);
           helmet.setItemMeta(im);
    
            nicezombie.getEquipment().setHelmet(helmet);
    
            this.team.addNonPlayerEntity(this.getBukkitEntity());}else{
                this.setCustomName(new ChatComponentText("Zombie"));
            }
    
        }
        @Override
        public void initPathfinder(){
            this.goalSelector.a(0, new PathfinderGoalFloat(this));
            this.targetSelector.a(0, new PathfinderGoalHurtByTarget(this));
    
            this.targetSelector.a(1, new PathfinderGoalHelpTeam<EntityLiving>(this, EntityLiving.class, true, this.team));
            this.goalSelector.a(1, new PathfinderGoalMeleeAttack(this, 1.0D, true));
            this.goalSelector.a(2, new PathfinderGoalMoveTowardsRestriction(this, 2.0D));
            this.goalSelector.a(3, new PathfinderGoalMoveThroughVillage(this, 0.2D, false, 1, null));
            this.goalSelector.a(4, new PathfinderGoalRandomStroll(this, 1D));
            this.goalSelector.a(5, new PathfinderGoalRandomLookaround(this));
            this.goalSelector.a(6, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
    
        }
     
Thread Status:
Not open for further replies.

Share This Page