Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello guys,

 

I'am working on a Entity that goes to a position, but the

entity.getNavigator().tryMoveToXYZ(0,4,0,0.5D)

methode ( I've spawned the entity at 10,4,10 with followRange 20 ) doesnt work( it's executed ).

Sorry if there are mistakes in my english

We need more context:

 

1. Where do you call that code?

 

2. Does your entity have a movement speed attribute > 0 ?

 

3. How about #getBlockPathWeight - what does your entity return for that?

 

4. Are you calling super from all overridden update methods?

 

etc. etc.

 

We need to see your entire Entity class along with any custom AI you may have for it in order to determine what's wrong.

  • Author

1. Where do you call that code?

1. In my EntityAISaveResources class, at startExecuting()

2. Does your entity have a movement speed attribute > 0 ?

2. Yes, 0.5D

3. How about #getBlockPathWeight - what does your entity return for that?

3. Does that methode exist?  ???

4. Are you calling super from all overridden update methods?

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

Sorry if there are mistakes in my english

It doesn't look like you ever add the EntityAISaveResources task to your villager's AI task list.

 

You may want to take a closer look at some of the vanilla AI - setting the BlockPos from the AI constructor doesn't make much sense, for example, unless you don't anticipate the location ever changing; but what if a player removes all those blocks? :P

  • Author

It doesn't look like you ever add the EntityAISaveResources task to your villager's AI task list.

Look at this, I called it in my VillagerWorker - class, because that's the class I'm using

this.tasks.addTask(2, new EntityAISaveResources(this, output));

 

I know that it cannot work if someone destroys the blocks the entity has to go to. I looked into EntityAIMoveToBlock, but I hadn't understood what some methodes do, for exsample the abstract methode func_179488_a(). And it looks like the destanationBlock is get randomly, but my Entity must go to a fixed position, in my case and just for debugging 0,0,0.

Sorry if there are mistakes in my english

Oh, I didn't see that class, just saw the Villager one. Well, (0, 0, 0) is at the bottom of the world, even on a super-flat world I doubt your entity will be able to make it there. You're going to want to use an actual block position near the entity that it can reach.

  • Author

Sorry, my mistake. I play in a flat - world and has a y-offset of 5, I use a offset of four before, still not work.

 

System.out.println( pos.up(5) );

 

 

Sorry if there are mistakes in my english

  • 2 weeks later...
  • Author

Fixed it, it looks like I haven't overrided the navigator of my villager, canNavigate() was never true. Why can't I use the normal navigator? :o

Sorry if there are mistakes in my english

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.