Jump to content

Recommended Posts

Posted

I am trying to work out some AIs but I am having toruble, it doesn't execute anything. This is my code, I have put system output markers all over to see where it goes and all I get is "supered" which is the initialization part, all the others do not occure so it doesn't even TRY to execute anything, why?

Mob:

	public MobThief(World world) {
	super(world);
        System.out.println("Thief is mobbing");
        this.targetTasks.addTask(1, new EntityAIRunIfSeenByTarget(this, EntityPlayer.class, false, false));
}

AI:

package aerosteam.mobs.ai;

import java.util.Comparator;

import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAITarget;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.Vec3;

public class EntityAIRunIfSeenByTarget extends EntityAITarget{

    private final EntityCreature creature;
    private EntityLivingBase target;
    private EntityPlayer player;
    private final Class targetClass;
    private double xPosition;
    private double yPosition;
    private double zPosition;
    /**
     * This filter is applied to the Entity search.  Only matching entities will be targetted.  (null -> no
     * restrictions)
     */

    public EntityAIRunIfSeenByTarget(EntityCreature creature, Class target, boolean b1, boolean b2) {
	super(creature, b1, b2);
	// TODO Auto-generated constructor stub
        System.out.println("supered");
	this.creature = creature; 
        this.targetClass = target;
        this.setMutexBits(1);
}    

public boolean shouldExecute() {
        System.out.println("trying to execute");
	this.target = this.creature.getAttackTarget();
	if (this.target instanceof EntityPlayer){
		this.player = (EntityPlayer) this.target;
		if (isLookedAt(player)){
			return true;
		}
	}
	return false;
}
    public void startExecuting()
    {
        System.out.println("start exxecuting");
    	Vec3 targetVec = Vec3.createVectorHelper(this.creature.posX - this.player.posX, this.creature.boundingBox.minY + (double)(this.creature.height / 2.0F) - (this.player.posY + (double)this.player.getEyeHeight()), this.creature.posZ - this.player.posZ);
    	this.xPosition = this.creature.posX+targetVec.xCoord;
    	this.yPosition = this.creature.posY+targetVec.yCoord;
    	this.zPosition = this.creature.posZ+targetVec.zCoord;
        this.creature.getNavigator().tryMoveToXYZ(this.xPosition, this.yPosition, this.zPosition, 5);
    }

 private boolean isLookedAt(EntityPlayer player)
    {
        Vec3 vec3 = player.getLook(1.0F).normalize();
        System.out.println("look angle: " + vec3.xCoord + ":" + vec3.yCoord + ":" + vec3.zCoord);
        Vec3 vec31 = Vec3.createVectorHelper(this.creature.posX - player.posX, this.creature.boundingBox.minY + (double)(this.creature.height / 2.0F) - (player.posY + (double)player.getEyeHeight()), this.creature.posZ - player.posZ);
        double d0 = vec31.lengthVector();
        vec31 = vec31.normalize();
        System.out.println("monster angle: " + vec31.xCoord + ":" + vec31.yCoord + ":" + vec31.zCoord);
        double d1 = vec3.dotProduct(vec31)-0.75D;
        System.out.println("dot product: " + d1);
        System.out.println("right angle: " + (d1 < 0.0D));
        return d1 > 0.0D && player.canEntityBeSeen(this.creature);
    }
    
}

Posted

first what are you extending for MobThief

second try putting the priority up :  this.targetTasks.addTask(50, n........

also put this in your ai

@Override
public boolean isInterruptible() {
	//System.out.println("isInterruptible");
	return false;
}

 

Posted

so.....priorty isn't first second third order but rather higher number = greater priority....dagnamnit

 

I am extending entitymob

 

What I am trying to create is a mob that spawns randomly throughout the day, runs up to a player if they are not seen and then away if they are seen, once they hit the player they grab one of the players tiems and runs off with it

Posted

I may add that when I tyr putting some code in the MobThief class which si the entitymob extended one

        	Vec3 targetVec = Vec3.createVectorHelper(this.posX - this.lastTarget.posX, this.boundingBox.minY + (double)(this.height / 2.0F) - (this.lastTarget.posY + (double)this.lastTarget.getEyeHeight()), this.posZ - this.lastTarget.posZ);
        	double xPosition = this.posX+20*Math.signum(targetVec.xCoord);
        	double yPosition = this.posY+20*Math.signum(targetVec.yCoord);
        	double zPosition = this.posZ+20*Math.signum(targetVec.zCoord);
            System.out.println("New X: " + xPosition);
            System.out.println("New Y: " + yPosition);
            System.out.println("New Z: " + zPosition);
            System.out.println("Move: " +  this.getNavigator().tryMoveToXYZ(xPosition, yPosition, zPosition, 5));
            this.getNavigator().tryMoveToXYZ(xPosition, yPosition, zPosition, 50);

this code, it seems to get the target but the mob never runs toward it, how come?

 

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.