1. In my EntityAISaveResources class, at startExecuting()
2. Yes, 0.5D
3. Does that methode exist?
4. Yes
My Villager class
public abstract class Villager extends EntityCreature {
protected ItemStack[] inventory = new ItemStack[10];
private WorkingState state = WorkingState.Config;
public Villager(World worldIn,int GetResourcesMaximum) {
super(worldIn);
this.state.setMaximums( GetResourcesMaximum );
this.setSize(0.6F, 1.8F);
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIOpenDoor(this, true));
this.setAIMoveSpeed(0.5f);
}
@Override protected void applyEntityAttributes() {
super.applyEntityAttributes();
this.getEntityAttribute( SharedMonsterAttributes.maxHealth ).setBaseValue(12);
this.getEntityAttribute( SharedMonsterAttributes.movementSpeed ).setBaseValue(0.5D);
this.getEntityAttribute( SharedMonsterAttributes.followRange ).setBaseValue(20D);
}
public ItemStack[] getVillagerInventory() {
return inventory;
}
@Override public void onStruckByLightning(EntityLightningBolt lightningBolt)
{
if (!this.worldObj.isRemote)
{
EntityWitch entitywitch = new EntityWitch(this.worldObj);
entitywitch.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
entitywitch.func_180482_a(this.worldObj.getDifficultyForLocation(new BlockPos(entitywitch)), (IEntityLivingData)null);
this.worldObj.spawnEntityInWorld(entitywitch);
this.setDead();
}
}
@Override public boolean getAlwaysRenderNameTag() {
return true;
}
@Override protected String getLivingSound()
{
return "mob.villager.idle";
}
@Override protected String getHurtSound()
{
return "mob.villager.hit";
}
@Override protected String getDeathSound()
{
return "mob.villager.death";
}
public void setReady() {
if( this.state == WorkingState.Config ) WorkingState.increment(state);
}
public void increment() {
WorkingState.increment(state);
}
public WorkingState getState(){
return state;
}
public void setSave() {
this.state = WorkingState.SaveResources;
}
@Override public float getAIMoveSpeed() {
return super.getAIMoveSpeed();
}
My Villager subclass( extends Villlager )
public class VillagerWorker extends Villager {
private ItemStack[] recipe = new ItemStack[9];
private BlockPos workbench;
private BlockPos[] input = new BlockPos[9];
private ItemStack itemoutput;
private BlockPos output;
public VillagerWorker(World worldIn) {
super(worldIn, ;
this.setReady();
output = new BlockPos( 0, 0,0 );
this.setSave();
this.tasks.addTask(2, new EntityAISaveResources(this, output));
}
}
My EntityAISaveResources - class
public class EntityAISaveResources extends EntityAIBase {
private BlockPos pos;
private Villager villager;
public EntityAISaveResources(Villager villager, BlockPos pos) {
this.villager = villager;
this.pos = pos;
this.setMutexBits(5);
}
@Override public boolean shouldExecute() {
return villager.getState() == WorkingState.SaveResources;
}
@Override public void startExecuting() {
System.out.println( pos.up(5) );
System.out.println( villager.getNavigator().tryMoveToXYZ(pos.getX(), pos.getY(), pos.getZ(), 0.5D) );
villager.increment();
}
}
WorkingState is just an Enum
public enum WorkingState {
GetResources,DoWork,SaveResources,Config;
int GetResourcesCounter,GetResourcesMaximum;
public void setMaximums( int GetResourcesMaximum ) {
this.GetResourcesCounter = 0;
this.GetResourcesMaximum = GetResourcesMaximum;
}
public static void increment( WorkingState state ){
if( state == GetResources ) {
if( state.GetResourcesCounter < state.GetResourcesMaximum ) {
state.GetResourcesCounter++;
}
else {
state.GetResourcesCounter = 0;
state = DoWork;
}
}
else if( state == SaveResources ) state = GetResources;
else if( state == DoWork ) state = SaveResources;
else if( state == Config ) state = GetResources;
}
}
Hope thats helpful