Jump to content

Making mobs move toward their block mob spawner


juanitodelavega

Recommended Posts

I have a custom creature spawner who can spawn any entityliving (mobs and creatures ) from vanilla and other mods .

I want those creatures to move to the spawner they just have been spawned from .

 

Right after spawning them to the world with :

this.getSpawnerWorld().spawnEntityInWorld(par1Entity);

 

I tried to set their path to the spawner:

entityliving.getNavigator().tryMoveToXYZ(this.getSpawnerX(), this.getSpawnerY(), this.getSpawnerZ(), 1.0D);

 

I tried to tell them where to move :

entityliving.getMoveHelper().setMoveTo(this.getSpawnerX(), this.getSpawnerY(), this.getSpawnerZ(), 1.0D);

 

I tried to add a custom AI task which set their path to the spawner:

entityliving.tasks.addTask(0, new EntityAIMoveToBlock(entityliving,this.getSpawnerX(),this.getSpawnerY(),this.getSpawnerZ()))

But it looks like the task is ignored by the creature.

 

None of those methods works i dont know if there is another way to tell any kind of creature to move to a said location; or if there is a way to add AI task after a creature has been created ?

Link to comment
Share on other sites

You need to understand how AI Task priority, Mutexbits, and CanBeInterrupted work together.

 

Suffice to say, I need more code, like the whole tasks.addTask() list

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Here is where i update my spawner and where i try to add Ai task or try to set the entity spawned path when it spawn an entity

 

public void updateSpawner() {
	if (isActivated()) {
		double d2;
		if (this.getSpawnerWorld().isRemote) {
			//particles
		} else {				
			if (this.spawnDelay == -1) {
				this.resetTimer();
			}

			if(this.spawnDelay==0){
				if(!spawnConditions()){
					this.resetTimer();
					return;
				}
			}

			if (this.spawnDelay > 0) {
				--this.spawnDelay;
				return;
			}
                boolean flag = false;

                for (int i = 0; i < this.spawnCount; ++i)
                {
                    Entity entity = EntityList.createEntityByName(this.getEntityNameToSpawn(), this.getSpawnerWorld());
                    
                    if (entity == null)
                    {
                        return;
                    }
                    entity.getEntityData().setIntArray(SpawnerBlock.KEY_SPAWN, new int[]{this.getSpawnerX(),this.getSpawnerY(),this.getSpawnerZ()});
        			
                    int j = this.getSpawnerWorld().getEntitiesWithinAABB(entity.getClass(), AxisAlignedBB.getBoundingBox((double)this.getSpawnerX(), (double)this.getSpawnerY(), (double)this.getSpawnerZ(), (double)(this.getSpawnerX() + 1), (double)(this.getSpawnerY() + 1), (double)(this.getSpawnerZ() + 1)).expand((double)(this.spawnRange * 2), 4.0D, (double)(this.spawnRange * 2))).size();

                    if (j >= this.maxNearbyEntities)
                    {
                        this.resetTimer();
                        return;
                    }

                    d2 = (double)this.getSpawnerX() + (this.getSpawnerWorld().rand.nextDouble() - this.getSpawnerWorld().rand.nextDouble()) * (double)this.spawnRange;
                    double d3 = (double)(this.getSpawnerY() + this.getSpawnerWorld().rand.nextInt(3) - 1);
                    double d4 = (double)this.getSpawnerZ() + (this.getSpawnerWorld().rand.nextDouble() - this.getSpawnerWorld().rand.nextDouble()) * (double)this.spawnRange;
                    EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving)entity : null;
                    entity.setLocationAndAngles(d2, d3, d4, this.getSpawnerWorld().rand.nextFloat() * 360.0F, 0.0F);
                    if (( entityliving == null || (entityliving.getCanSpawnHere() || !followVanillaSpawnRules) ) && getSpawnerWorld().getBlock((int)d2, (int)d3, (int)d4) == Blocks.air )
                    {
                        //entityliving.getNavigator().tryMoveToXYZ(this.getSpawnerX(), this.getSpawnerY(), this.getSpawnerZ(), 1.0D);
    		//entityliving.getMoveHelper().setMoveTo(this.getSpawnerX(), this.getSpawnerY(), this.getSpawnerZ(), 1.0D);
                        //entityliving.tasks.addTask(0, new EntityAIMoveToBlock(entityliving,this.getSpawnerX(),this.getSpawnerY(),this.getSpawnerZ()));
                        this.spawnEntity(entity);
                        this.getSpawnerWorld().playAuxSFX(2004, this.getSpawnerX(), this.getSpawnerY(), this.getSpawnerZ(), 0);

                        if (entityliving != null)
                        {
                            entityliving.spawnExplosionParticle();
                        }

                        flag = true;
                    }
                }

                if (flag)
                {
                    this.resetTimer();
                }
                

        		/*for(EntityLiving ecr :this.listEToRemove){
        			
        			this.listE.remove(ecr);
        		}
        		this.listEToRemove.clear();*/
		}


	}

public Entity spawnEntity(Entity par1Entity) {
	if (par1Entity instanceof EntityLivingBase && par1Entity.worldObj != null) {
		((EntityLiving)par1Entity).func_110163_bv();
		this.getSpawnerWorld().spawnEntityInWorld(par1Entity);
	}
	return par1Entity;
}

 

 

Here my AI task

public class EntityAIMoveToBlock  extends EntityAIBase{

EntityLiving entitySpawn;
    int xBlock;
    int yBlock;
    int zBlock;

public EntityAIMoveToBlock(EntityLiving entity, int x, int y, int z){
	this.entitySpawn = entity;
	this.xBlock = x;
	this.yBlock = y;
	this.zBlock = z;
	setMutexBits(7);
}

@Override
public boolean shouldExecute() {
	if (entitySpawn == null){
		return false;
	}
	else if (!entitySpawn.isEntityAlive()){
		return false;
	}
	else{
		return true;
        }
}

public boolean continueExecuting(){
        return entitySpawn.isEntityAlive() && !entitySpawn.getNavigator().noPath() && entitySpawn.getDistanceSq(xBlock, yBlock, zBlock)>2.0*2.0;
    }

    public void startExecuting(){
    	entitySpawn.getNavigator().tryMoveToXYZ(this.xBlock, this.yBlock, this.zBlock, 2.0);
    }
    
    public void resetTask(){
    	entitySpawn = null;
    }
}

 

Im applying that task to any entity spawned by the spawner even vanilla ones not only my custom ones so there is no list of tasks.addTask()

, i know about Mutexbits but what is CanBeInterrupted ?

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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