Jump to content

[SORTA SOLVED][1.6.4] getting int with metadata from ItemStack


saxon564

Recommended Posts

Heres the code i need help with:

 

this.tasks.addTask(3, new ChickAITempt(this, 1.0D, new ItemStack(Item.dyePowder, 1, 3).itemID, false));

 

i need to pass new ItemStack(Item.dyePowder, 1, 3).itemID on to ChickAITempt with the metadata of 3. but i cant get it to send without changing the constructor of ChickAITempt, which will break it with all the other mobs. could someone show me what i need to do to send the metadata to the ChickAITempt class?

Link to comment
Share on other sites

You probably can't, as the constructor deals with only an item ID (which, why you'd create an item stack only to get the item's ID out of it, when you could just skip the item stack, I have no idea).  If you take a peek inside AITempt, you'll either find out that it doesn't care OR you'll find the variable that holds the information and how to set it.

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

the constructor asks for an int, i can change that if i wanted, but i would have to change several other classes to match it, as for it not caring, thats because it simply is just that, unless there is a way, it doesnt care, and any dye will do what im trying to do, but i only want the cocoa beans to be used.

 

heres the code for EntityAIChick:

package mods.mochickens.misc;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public class ChickAITempt extends EntityAIBase
{
    /** The entity using this AI that is tempted by the player. */
    private EntityCreature temptedEntity;
    private double field_75282_b;

    /** X position of player tempting this mob */
    private double targetX;

    /** Y position of player tempting this mob */
    private double targetY;

    /** Z position of player tempting this mob */
    private double targetZ;
    private double field_75278_f;
    private double field_75279_g;

    /** The player that is tempting the entity that is using this AI. */
    private EntityPlayer temptingPlayer;

    /**
     * A counter that is decremented each time the shouldExecute method is called. The shouldExecute method will always
     * return false if delayTemptCounter is greater than 0.
     */
    private int delayTemptCounter;

    /** True if this EntityAITempt task is running */
    private boolean isRunning;

    /**
     * This field saves the ID of the items that can be used to breed entities with this behaviour.
     */
    private int breedingFood;

    /**
     * Whether the entity using this AI will be scared by the tempter's sudden movement.
     */
    private boolean scaredByPlayerMovement;
    private boolean field_75286_m;

    public ChickAITempt(EntityCreature par1EntityCreature, double par2, int par4, boolean par5)
    {
        this.setTemptedEntity(par1EntityCreature);
        this.field_75282_b = par2;
        this.setBreedingFood(par4);
        this.scaredByPlayerMovement = par5;
        this.setMutexBits(3);
    }

    /**
     * Returns whether the EntityAIBase should begin execution.
     */
    public boolean shouldExecute()
    {
    	String owner = this.getTemptedEntity().getDataWatcher()
    			.getWatchableObjectString(17);
    	
    	if (this.getDelayTemptCounter() > 0) {
		this.setDelayTemptCounter(this.getDelayTemptCounter() - 1);
		return false;
	} else {
		this.setTemptingPlayer(this.getTemptedEntity().worldObj
				.getClosestPlayerToEntity(this.getTemptedEntity(), 10.0D));

		if (this.getTemptingPlayer() == null) {
			return false;
		} else if (this.getTemptingPlayer().getEntityName() != owner) {
			return false;
		} else {
			ItemStack itemstack = this.getTemptingPlayer()
					.getCurrentEquippedItem();
			return itemstack == null ? false : itemstack.itemID == this
					.getBreedingFood();
		}
	}
    }

    /**
     * Returns whether an in-progress EntityAIBase should continue executing
     */
    public boolean continueExecuting()
    {
        if (this.scaredByPlayerMovement)
        {
            if (this.getTemptedEntity().getDistanceSqToEntity(this.getTemptingPlayer()) < 36.0D)
            {
                if (this.getTemptingPlayer().getDistanceSq(this.targetX, this.targetY, this.targetZ) > 0.010000000000000002D)
                {
                    return false;
                }

                if (Math.abs((double)this.getTemptingPlayer().rotationPitch - this.field_75278_f) > 5.0D || Math.abs((double)this.getTemptingPlayer().rotationYaw - this.field_75279_g) > 5.0D)
                {
                    return false;
                }
            }
            else
            {
                this.targetX = this.getTemptingPlayer().posX;
                this.targetY = this.getTemptingPlayer().posY;
                this.targetZ = this.getTemptingPlayer().posZ;
            }

            this.field_75278_f = (double)this.getTemptingPlayer().rotationPitch;
            this.field_75279_g = (double)this.getTemptingPlayer().rotationYaw;
        }

        return this.shouldExecute();
    }

    /**
     * Execute a one shot task or start executing a continuous task
     */
    public void startExecuting()
    {
        this.targetX = this.getTemptingPlayer().posX;
        this.targetY = this.getTemptingPlayer().posY;
        this.targetZ = this.getTemptingPlayer().posZ;
        this.isRunning = true;
        this.field_75286_m = this.getTemptedEntity().getNavigator().getAvoidsWater();
        this.getTemptedEntity().getNavigator().setAvoidsWater(false);
    }

    /**
     * Resets the task
     */
    public void resetTask()
    {
        this.setTemptingPlayer(null);
        this.getTemptedEntity().getNavigator().clearPathEntity();
        this.setDelayTemptCounter(100);
        this.isRunning = false;
        this.getTemptedEntity().getNavigator().setAvoidsWater(this.field_75286_m);
    }

    /**
     * Updates the task
     */
    public void updateTask()
    {
        this.getTemptedEntity().getLookHelper().setLookPositionWithEntity(this.getTemptingPlayer(), 30.0F, (float)this.getTemptedEntity().getVerticalFaceSpeed());

        if (this.getTemptedEntity().getDistanceSqToEntity(this.getTemptingPlayer()) < 6.25D)
        {
            this.getTemptedEntity().getNavigator().clearPathEntity();
        }
        else
        {
            this.getTemptedEntity().getNavigator().tryMoveToEntityLiving(this.getTemptingPlayer(), this.field_75282_b);
        }
    }

    /**
     * @see #isRunning
     */
    public boolean isRunning()
    {
        return this.isRunning;
    }

public int getDelayTemptCounter() {
	return delayTemptCounter;
}

public void setDelayTemptCounter(int delayTemptCounter) {
	this.delayTemptCounter = delayTemptCounter;
}

public EntityPlayer getTemptingPlayer() {
	return temptingPlayer;
}

public void setTemptingPlayer(EntityPlayer temptingPlayer) {
	this.temptingPlayer = temptingPlayer;
}

public EntityCreature getTemptedEntity() {
	return temptedEntity;
}

public void setTemptedEntity(EntityCreature temptedEntity) {
	this.temptedEntity = temptedEntity;
}

public int getBreedingFood() {
	return breedingFood;
}

public void setBreedingFood(int breedingFood) {
	this.breedingFood = breedingFood;
}
}

Link to comment
Share on other sites

You know you can have multiple constructors...right?

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

tried multiple constructors and it still didnt work, so i decided just to make another AI class to deal with meta blocks which now works.

 

package mods.mochickens.misc;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;

public class ChickAITemptDye extends EntityAIBase {
/** The entity using this AI that is tempted by the player. */
private EntityCreature temptedEntity;
private double field_75282_b;

/** X position of player tempting this mob */
private double targetX;

/** Y position of player tempting this mob */
private double targetY;

/** Z position of player tempting this mob */
private double targetZ;
private double field_75278_f;
private double field_75279_g;

/** The player that is tempting the entity that is using this AI. */
private EntityPlayer temptingPlayer;

/**
 * A counter that is decremented each time the shouldExecute method is
 * called. The shouldExecute method will always return false if
 * delayTemptCounter is greater than 0.
 */
private int delayTemptCounter;

/** True if this EntityAITempt task is running */
private boolean isRunning;

/**
 * This field saves the ID of the items that can be used to breed entities
 * with this behaviour.
 */
private String breedingFood;

/**
 * Whether the entity using this AI will be scared by the tempter's sudden
 * movement.
 */
private boolean scaredByPlayerMovement;
private boolean field_75286_m;

public ChickAITemptDye(EntityCreature par1EntityCreature, double par2,
		String par4, boolean par5) {
	this.setTemptedEntity(par1EntityCreature);
	this.field_75282_b = par2;
	this.setBreedingFood(par4);
	this.scaredByPlayerMovement = par5;
	this.setMutexBits(3);
}

/**
 * Returns whether the EntityAIBase should begin execution.
 */
public boolean shouldExecute() {
	String owner = this.getTemptedEntity().getDataWatcher()
			.getWatchableObjectString(17);

	if (this.getDelayTemptCounter() > 0) {
		this.setDelayTemptCounter(this.getDelayTemptCounter() - 1);
		return false;
	} else {
		this.setTemptingPlayer(this.getTemptedEntity().worldObj
				.getClosestPlayerToEntity(this.getTemptedEntity(), 10.0D));

		if (this.getTemptingPlayer() == null) {
			return false;
		} else if (this.getTemptingPlayer().getEntityName() != owner) {
			return false;
		} else {
			ItemStack itemstack = this.getTemptingPlayer()
					.getCurrentEquippedItem();
			return itemstack == null ? false : itemstack.getDisplayName().equalsIgnoreCase(this.getBreedingFood());
		}
	}
}

/**
 * Returns whether an in-progress EntityAIBase should continue executing
 */
public boolean continueExecuting() {
	if (this.scaredByPlayerMovement) {
		if (this.getTemptedEntity().getDistanceSqToEntity(
				this.getTemptingPlayer()) < 36.0D) {
			if (this.getTemptingPlayer().getDistanceSq(this.targetX,
					this.targetY, this.targetZ) > 0.010000000000000002D) {
				return false;
			}

			if (Math.abs((double) this.getTemptingPlayer().rotationPitch
					- this.field_75278_f) > 5.0D
					|| Math.abs((double) this.getTemptingPlayer().rotationYaw
							- this.field_75279_g) > 5.0D) {
				return false;
			}
		} else {
			this.targetX = this.getTemptingPlayer().posX;
			this.targetY = this.getTemptingPlayer().posY;
			this.targetZ = this.getTemptingPlayer().posZ;
		}

		this.field_75278_f = (double) this.getTemptingPlayer().rotationPitch;
		this.field_75279_g = (double) this.getTemptingPlayer().rotationYaw;
	}

	return this.shouldExecute();
}

/**
 * Execute a one shot task or start executing a continuous task
 */
public void startExecuting() {
	this.targetX = this.getTemptingPlayer().posX;
	this.targetY = this.getTemptingPlayer().posY;
	this.targetZ = this.getTemptingPlayer().posZ;
	this.isRunning = true;
	this.field_75286_m = this.getTemptedEntity().getNavigator()
			.getAvoidsWater();
	this.getTemptedEntity().getNavigator().setAvoidsWater(false);
}

/**
 * Resets the task
 */
public void resetTask() {
	this.setTemptingPlayer(null);
	this.getTemptedEntity().getNavigator().clearPathEntity();
	this.setDelayTemptCounter(100);
	this.isRunning = false;
	this.getTemptedEntity().getNavigator()
			.setAvoidsWater(this.field_75286_m);
}

/**
 * Updates the task
 */
public void updateTask() {
	this.getTemptedEntity()
			.getLookHelper()
			.setLookPositionWithEntity(this.getTemptingPlayer(), 30.0F,
					(float) this.getTemptedEntity().getVerticalFaceSpeed());

	if (this.getTemptedEntity().getDistanceSqToEntity(
			this.getTemptingPlayer()) < 6.25D) {
		this.getTemptedEntity().getNavigator().clearPathEntity();
	} else {
		this.getTemptedEntity()
				.getNavigator()
				.tryMoveToEntityLiving(this.getTemptingPlayer(),
						this.field_75282_b);
	}
}

/**
 * @see #isRunning
 */
public boolean isRunning() {
	return this.isRunning;
}

public int getDelayTemptCounter() {
	return delayTemptCounter;
}

public void setDelayTemptCounter(int delayTemptCounter) {
	this.delayTemptCounter = delayTemptCounter;
}

public EntityPlayer getTemptingPlayer() {
	return temptingPlayer;
}

public void setTemptingPlayer(EntityPlayer temptingPlayer) {
	this.temptingPlayer = temptingPlayer;
}

public EntityCreature getTemptedEntity() {
	return temptedEntity;
}

public void setTemptedEntity(EntityCreature temptedEntity) {
	this.temptedEntity = temptedEntity;
}

public String getBreedingFood() {
	return breedingFood;
}


public void setBreedingFood(String par4) {
	this.breedingFood = par4;
}
}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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