TLDR: I pass data into the instantiation of a mob. Part of that instantiation proccess involves instantiating AI for the mob. I want the data I pass into the mob to be passed into the AI for the mob. This is difficult because of a forced Super() call among other things.
The story: I am creating my own version of Monsters inside a game.
I have coded myself pathFinders (AI goals that entities use to navigate the world). Then I took an existing mob (in this case a cow) and erased its normal AI and replaced it with my own: PathFinderGoalRpgMeleeAttack.
I would like to create new instances of my cow (i.e. RpgCow rpgCow = new rpgCow(damage,knockback)).
The issue is that when I instantiate a new mob (which extends another class remember) I am forced to call super(). The super method calls method r() (which I override to add my own AI). Since the super() calls r(), the values of damage and knockback are still 0.0 and 0.0 (default java values for double) since damage and knockback have not had a chance to be set yet.
Any thoughts on how I can get around this and insert the data I pass into the cow creation into the PathFinder creation?
I have heard abstraction or reflection might be a good thing to look into, but just reading documentation on the two subjects, neither seems like it would help me.
EDIT, cause I guess I wasn't that clear: The issue is that the values of Damage and Knockback are still 0 when I pass them into the PathFinder, which means later on when I do this.getDamage in my pathFinder, regardless of what values I passed into the mob on creation the damage and knockback will always be 0.
Code:
public class RpgCow extends EntityCow
{
private double damage;
private double knockback;
public RpgCow(World world, double damage, double knockback)
{
super(world);
this.damage = damage;
this.knockback = knockback;
this.bukkitEntity = new CraftRpgCow(this.world.getServer(), this);
}
@Override
protected void r()
{
this.goalSelector.a(3,new PathFinderGoalRpgMeleeAttack(this,damage,knockback));
}
private static class CraftRpgCow extends CraftCow
{
private CraftRpgCow(CraftServer server, EntityCow parent)
{
super(server, parent);
}
}
}