Jump to content

[1.6.4] [SOLVED] Making Mob Only Follow Tempt By Owner


Recommended Posts

Posted

so what i am trying to do now to finish off this mob so i can make the rest of them is make it so the mob will only be tempted by the owner and no one else if they are holding the tempt item, i have thought about it and looked at the code but am coming up blank. im not sure if overriding the method for that is a good idea or if i should remake the EntityAITempt class and modify it to what i need to do.

 

Here is my mobs entity code:

package mods.mochickens.mobs;

import java.util.logging.Logger;

import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.client.Minecraft;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.EnchantmentThorns;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowParent;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIPanic;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;

public class EntityBlueChicken extends EntityTameable {
public boolean field_70885_d = false;
public float field_70886_e = 0.0F;
public float destPos = 0.0F;
public float field_70884_g;
public float field_70888_h;
public float field_70889_i = 1.0F;

/** The time until the next egg is spawned. */
public int timeUntilNextEgg;

public EntityBlueChicken(World par1World) {
	super(par1World);
	this.setSize(0.3F, 0.7F);
	float f = 0.25F;
	this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
	this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
	this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(6, new EntityAIWatchClosest(this,
			EntityPlayer.class, 6.0F));
	this.tasks.addTask(7, new EntityAILookIdle(this));
	this.tasks.addTask(2, new EntityAIAttackOnCollide(this,
			EntityPlayer.class, 1.0D, false));
	this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this,
			EntityPlayer.class, 0, true));
	this.timeUntilNextEgg = -1;
	this.setTamed(false);
}

/**
 * Returns true if the newer Entity AI code should be run
 */
public boolean isAIEnabled() {
	return true;
}

protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth)
			.setAttribute(4.0D);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed)
			.setAttribute(0.25D);
}

@Override
public final void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {
	super.readEntityFromNBT(par1NBTTagCompound);
	String s = par1NBTTagCompound.getString("Owner");

	if (s.length() > 0) {
		this.setTamed(true);
		this.setOwner(s);
	}
}

    @Override
public void setTamed(boolean par1)
    {
        byte b0 = this.dataWatcher.getWatchableObjectByte(16);

        if (par1)
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 4)));
            this.worldObj.setEntityState(this, (byte) 7);
			this.tasks.removeTask(new EntityAIAttackOnCollide(this,
					EntityPlayer.class, 1.0D, false));
			this.targetTasks.taskEntries.clear();
			this.tasks.addTask(3, new EntityAITempt(this, 1.0D,
					Block.blockDiamond.blockID, false));
			this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
        }
        else
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -5)));
        }
    }

public boolean attackEntityAsMob(Entity par1Entity) {
	if (!this.isTamed()) {
		EntityPlayer entityplayer = this.worldObj
				.getClosestVulnerablePlayerToEntity(this, 16.0D);
		// f = damage delt 2.0D = 1 heart
		float f = (float) 5.0D;
		int i = 0;

		if (entityplayer instanceof EntityLivingBase) {
			f += EnchantmentHelper.getEnchantmentModifierLiving(this,
					(EntityLivingBase) entityplayer);
			i += EnchantmentHelper.getKnockbackModifier(this,
					(EntityLivingBase) entityplayer);
			entityplayer.addPotionEffect(new PotionEffect(
					Potion.blindness.id, 200, 1));
			entityplayer.addPotionEffect(new PotionEffect(
					Potion.moveSlowdown.id, 200, 2));
		}

		boolean flag = par1Entity.attackEntityFrom(
				DamageSource.causeMobDamage(this), f);

		if (flag) {
			if (i > 0) {
				entityplayer.addVelocity(
						(double) (-MathHelper.sin(this.rotationYaw
								* (float) Math.PI / 180.0F)
								* (float) i * 0.5F),
						0.1D,
						(double) (MathHelper.cos(this.rotationYaw
								* (float) Math.PI / 180.0F)
								* (float) i * 0.5F));
				this.motionX *= 0.6D;
				this.motionZ *= 0.6D;
			}

			int j = EnchantmentHelper.getFireAspectModifier(this);

			if (j > 0) {
				entityplayer.setFire(j * 4);
			}

			if (entityplayer instanceof EntityLivingBase) {
				EnchantmentThorns.func_92096_a(this,
						(EntityLivingBase) entityplayer, this.rand);
			}
		}

		return flag;
	} else {
		return false;
	}
}

/**
 * Called frequently so the entity can update its state every tick as
 * required. For example, zombies and skeletons use this to react to
 * sunlight and start to burn.
 */
public void onLivingUpdate() {
	super.onLivingUpdate();
	this.field_70888_h = this.field_70886_e;
	this.field_70884_g = this.destPos;
	this.destPos = (float) ((double) this.destPos + (double) (this.onGround ? -1
			: 4) * 0.3D);

	if (this.destPos < 0.0F) {
		this.destPos = 0.0F;
	}

	if (this.destPos > 1.0F) {
		this.destPos = 1.0F;
	}

	if (!this.onGround && this.field_70889_i < 1.0F) {
		this.field_70889_i = 1.0F;
	}

	this.field_70889_i = (float) ((double) this.field_70889_i * 0.9D);

	if (!this.onGround && this.motionY < 0.0D) {
		this.motionY *= 0.6D;
	}

	this.field_70886_e += this.field_70889_i * 2.0F;

	if (!this.isChild() && !this.worldObj.isRemote
			&& --this.timeUntilNextEgg == 0) {
		this.playSound(
				"mob.chicken.plop",
				1.0F,
				(this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
		this.dropItem(Item.diamond.itemID, 1);
		this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
	}
}

/**
 * Called when the mob is falling. Calculates and applies fall damage.
 */
protected void fall(float par1) {
}

/**
 * Returns the sound this mob makes while it's alive.
 */
protected String getLivingSound() {
	return "mob.chicken.say";
}

/**
 * Returns the sound this mob makes when it is hurt.
 */
protected String getHurtSound() {
	return "mob.chicken.hurt";
}

/**
 * Returns the sound this mob makes on death.
 */
protected String getDeathSound() {
	return "mob.chicken.hurt";
}

/**
 * Plays step sound at given x, y, z for the entity
 */
protected void playStepSound(int par1, int par2, int par3, int par4) {
	this.playSound("mob.chicken.step", 0.15F, 1.0F);
}

/**
 * Returns the item ID for the item the mob drops on death.
 */
protected int getDropItemId() {
	return Item.feather.itemID;
}

/**
 * Drop 0-2 items of this living's type. @param par1 - Whether this entity
 * has recently been hit by a player. @param par2 - Level of Looting used to
 * kill this mob.
 */
protected void dropFewItems(boolean par1, int par2) {
	int j = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);

	for (int k = 0; k < j; ++k) {
		if (this.isTamed()) {
		this.dropItem(Item.diamond.itemID, 1);
		} else {
			this.dropItem(Item.egg.itemID, 1);
		}
	}

	if (this.isBurning()) {
		this.dropItem(Item.chickenCooked.itemID, 1);
	} else {
		this.dropItem(Item.chickenRaw.itemID, 1);
	}
}

/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow,
 * gets into the saddle on a pig.
 */
public boolean interact(EntityPlayer par1EntityPlayer) {
	ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
	if (!this.isTamed()) {
		if (itemstack != null && itemstack.itemID == Item.diamond.itemID) {
			if (!par1EntityPlayer.capabilities.isCreativeMode) {
				--itemstack.stackSize;
			}

			if (itemstack.stackSize <= 0) {
				par1EntityPlayer.inventory.setInventorySlotContents(
						par1EntityPlayer.inventory.currentItem,
						(ItemStack) null);
			}

			if (!this.worldObj.isRemote) {
				if (this.rand.nextInt(3) == 0) {
					this.setTamed(true);
					this.setPathToEntity((PathEntity) null);
					this.setAttackTarget((EntityLivingBase) null);
					this.setTarget(null);
					this.setOwner(par1EntityPlayer.getCommandSenderName());
					this.playTameEffect(true);
				} else {
					this.playTameEffect(false);
					this.worldObj.setEntityState(this, (byte) 6);
				}
			}

			return true;
		}
	}

	return super.interact(par1EntityPlayer);
}

/**
 * This function is used when two same-species animals in 'love mode' breed
 * to generate the new baby animal.
 */
public EntityBlueChicken spawnBabyAnimal(EntityAgeable par1EntityAgeable) {
	EntityBlueChicken entitybluechicken = new EntityBlueChicken(
			this.worldObj);
	String s = this.getOwnerName();

	if (s != null && s.trim().length() > 0) {
		entitybluechicken.setOwner(s);
		entitybluechicken.setTamed(true);
	}

	return entitybluechicken;
}

/**
 * Checks if the parameter is an item which this animal can be fed to breed
 * it (wheat, carrots or seeds depending on the animal type)
 */
public boolean isBreedingItem(ItemStack par1ItemStack) {
	if (this.isTamed()) {
		return par1ItemStack != null
				&& par1ItemStack.itemID == Item.diamond.itemID;
	} else {
		return false;
	}
}

public EntityAgeable createChild(EntityAgeable par1EntityAgeable) {
	return this.spawnBabyAnimal(par1EntityAgeable);
}
}

 

the line i know i need to focus on for this issue is

this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Block.blockDiamond.blockID, false));

 

does anyone have any ideas as to what i could do to make the mob only follow the owner and no one else holding a diamond block?

Posted

Hi

 

Perhaps you could create a new AI class from the existing one?  eg if you want the pet to follow the closest person if it is the owner and is holding a diamond:

 

class MyEntityAITempt extends EntityAITempt {

@Override
   public boolean shouldExecute()
    {
        if (this.delayTemptCounter > 0)
        {
            --this.delayTemptCounter;
            return false;
        }
        else
        {
            this.temptingPlayer = this.temptedEntity.worldObj.getClosestPlayerToEntity(this.temptedEntity, 10.0D);

/* get owner of a pet
EntityTameable::
    public EntityLivingBase func_130012_q()
    {
        return this.worldObj.getPlayerEntityByName(this.getOwnerName());
    }
*/
            if (this.temptingPlayer != this.func_130012_q()) return false; 
            if (this.temptingPlayer == null)
            {
                return false;
            }
            else
            {
                ItemStack itemstack = this.temptingPlayer.getCurrentEquippedItem();
                return itemstack == null ? false : itemstack.itemID == this.breedingFood;
            }
        }
    }

 

I haven't tested this but I'm pretty sure it will work....

 

-TGG

Posted

using what you said i now have this class:

package mods.mochickens.misc;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.item.ItemStack;

class ChickAITempt extends EntityAITempt {

@Override
public boolean shouldExecute() {
	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() != this.func_130012_q())
			return false;
		if (this.getTemptingPlayer() == null) {
			return false;
		} else {
			ItemStack itemstack = this.getTemptingPlayer()
					.getCurrentEquippedItem();
			return itemstack == null ? false : itemstack.itemID == this
					.getBreedingFood();
		}
	}
}

public EntityLivingBase func_130012_q() {
	return this.worldObj.getPlayerEntityByName(this.getOwnerName());
}  
}

 

it is showing 2 errors.

 

here:

class [u]ChickAITempt[/u] extends EntityAITempt {

telling me i have to make a construtor

 

and here:

return this.[u]worldObj[/u].getPlayerEntityByName([u]this.getOwnerName()[/u]);

worldObj: says to create field or constant

this.getOwnerName(): says to create method

 

i imagine that the this.getOwnerName() will be solved when worldObj is solved, but idk how i need to go about fixing that. as for the constructor, should i make it then call the method?

Posted

Hi

 

Try this constructor

 

    public ChickAITempt(EntityCreature temptedEntityInit, double movementSpeedInit, int temptingItemIDInit, boolean scaredByPlayerMovementInit)
    {
       super(temptedEntityInit, movementSpeedInit, temptingItemIDInit, scaredByPlayerMovementInit);
    }

 

The function func_130012_q is already defined for a tameable entity.  It might be called EntityTameable.getOwnerEntity in your version of Forge.  No need to add it to your ChickAITempt

 

-TGG

 

Posted

so ive tried multiple ways to get the owner but none of them have worked, this is where i have stopped:

package mods.mochickens.misc;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.item.ItemStack;

class ChickAITempt extends EntityAITempt {

public ChickAITempt(EntityCreature temptedEntityInit, double movementSpeedInit, int temptingItemIDInit, boolean scaredByPlayerMovementInit)
    {
       super(temptedEntityInit, movementSpeedInit, temptingItemIDInit, scaredByPlayerMovementInit);
    }

@Override
public boolean shouldExecute() {
	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() != EntityTameable.getOwner())
			return false;
		if (this.getTemptingPlayer() == null) {
			return false;
		} else {
			ItemStack itemstack = this.getTemptingPlayer()
					.getCurrentEquippedItem();
			return itemstack == null ? false : itemstack.itemID == this
					.getBreedingFood();
		}
	}
}

//public EntityLivingBase func_130012_q() {
//	return this.worldObj.getPlayerEntityByName(this.getOwnerName());
//}  
}

 

im still having the problem on this line:

if (this.getTemptingPlayer() != EntityTameable.getOwner())

there error is saying to change the modifier of getOwner() to static in EntityTameable.

 

ive tried getting it the owner the same way as in other classes ive seen, such as using worldObj.

Posted

Hi

 

Could you please show your chick entity class?

 

If it derives from EntityTameable (like wolf or ocelot), then it will be available from your EntityCreature

 

http://greyminecraftcoder.blogspot.com/2013/10/the-most-important-minecraft-classes_9.html

 

Otherwise, you will need to add your own field to your chick entity class to keep track of the owner.  Or alternatively, add it to the constructor for ChickAITempt

 

public ChickAITempt(EntityCreature temptedEntityInit, EntityPlayer owner, double movementSpeedInit, int temptingItemIDInit, boolean scaredByPlayerMovementInit)
    {
       super(temptedEntityInit, movementSpeedInit, temptingItemIDInit, scaredByPlayerMovementInit);
       this.ownerName = .getCommandSenderName();
    }

private String ownerName = new String();

}

etc

 

Have a look at the code for EntityTameable - around setOwner, getOwner (etc).  It uses a DataWatcher object to keep track of who the owning player is - otherwise it will "forget" every time you save the game.  You will need to add these methods to your chick Class if you want the same "tame" functions.

 

-TGG

 

Posted

ok here it is.

 

Entity class:

package mods.mochickens.mobs;

import java.util.logging.Logger;

import mods.mochickens.misc.ChickAITempt;
import mods.mochickens.misc.ChickTameable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.client.Minecraft;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.EnchantmentThorns;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowParent;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIPanic;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;

public class EntityBlueChicken extends ChickTameable {
public boolean field_70885_d = false;
public float field_70886_e = 0.0F;
public float destPos = 0.0F;
public float field_70884_g;
public float field_70888_h;
public float field_70889_i = 1.0F;

/** The time until the next egg is spawned. */
public int timeUntilNextEgg;

public EntityBlueChicken(World par1World) {
	super(par1World);
	this.setSize(0.3F, 0.7F);
	float f = 0.25F;
	this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
	this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
	this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(6, new EntityAIWatchClosest(this,
			EntityPlayer.class, 6.0F));
	this.tasks.addTask(7, new EntityAILookIdle(this));
	this.tasks.addTask(2, new EntityAIAttackOnCollide(this,
			EntityPlayer.class, 1.0D, false));
	this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this,
			EntityPlayer.class, 0, true));
	this.timeUntilNextEgg = -1;
	this.setTamed(false);
}

/**
 * Returns true if the newer Entity AI code should be run
 */
public boolean isAIEnabled() {
	return true;
}

protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth)
			.setAttribute(4.0D);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed)
			.setAttribute(0.25D);
}

@Override
public final void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {
	super.readEntityFromNBT(par1NBTTagCompound);
	String s = par1NBTTagCompound.getString("Owner");

	if (s.length() > 0) {
		this.setTamed(true);
		this.setOwner(s);
	}
}

    @Override
public void setTamed(boolean par1)
    {
        byte b0 = this.dataWatcher.getWatchableObjectByte(16);

        if (par1)
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 4)));
            this.worldObj.setEntityState(this, (byte) 7);
			this.tasks.removeTask(new EntityAIAttackOnCollide(this,
					EntityPlayer.class, 1.0D, false));
			this.targetTasks.taskEntries.clear();
			this.tasks.addTask(3, new ChickAITempt(this, 1.0D,
					Block.blockDiamond.blockID, false));
			this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
        }
        else
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -5)));
        }
    }

public boolean attackEntityAsMob(Entity par1Entity) {
	if (!this.isTamed()) {
		EntityPlayer entityplayer = this.worldObj
				.getClosestVulnerablePlayerToEntity(this, 16.0D);
		// f = damage delt 2.0D = 1 heart
		float f = (float) 5.0D;
		int i = 0;

		if (entityplayer instanceof EntityLivingBase) {
			f += EnchantmentHelper.getEnchantmentModifierLiving(this,
					(EntityLivingBase) entityplayer);
			i += EnchantmentHelper.getKnockbackModifier(this,
					(EntityLivingBase) entityplayer);
			entityplayer.addPotionEffect(new PotionEffect(
					Potion.blindness.id, 200, 1));
			entityplayer.addPotionEffect(new PotionEffect(
					Potion.moveSlowdown.id, 200, 2));
		}

		boolean flag = par1Entity.attackEntityFrom(
				DamageSource.causeMobDamage(this), f);

		if (flag) {
			if (i > 0) {
				entityplayer.addVelocity(
						(double) (-MathHelper.sin(this.rotationYaw
								* (float) Math.PI / 180.0F)
								* (float) i * 0.5F),
						0.1D,
						(double) (MathHelper.cos(this.rotationYaw
								* (float) Math.PI / 180.0F)
								* (float) i * 0.5F));
				this.motionX *= 0.6D;
				this.motionZ *= 0.6D;
			}

			int j = EnchantmentHelper.getFireAspectModifier(this);

			if (j > 0) {
				entityplayer.setFire(j * 4);
			}

			if (entityplayer instanceof EntityLivingBase) {
				EnchantmentThorns.func_92096_a(this,
						(EntityLivingBase) entityplayer, this.rand);
			}
		}

		return flag;
	} else {
		return false;
	}
}

/**
 * Called frequently so the entity can update its state every tick as
 * required. For example, zombies and skeletons use this to react to
 * sunlight and start to burn.
 */
public void onLivingUpdate() {
	super.onLivingUpdate();
	this.field_70888_h = this.field_70886_e;
	this.field_70884_g = this.destPos;
	this.destPos = (float) ((double) this.destPos + (double) (this.onGround ? -1
			: 4) * 0.3D);

	if (this.destPos < 0.0F) {
		this.destPos = 0.0F;
	}

	if (this.destPos > 1.0F) {
		this.destPos = 1.0F;
	}

	if (!this.onGround && this.field_70889_i < 1.0F) {
		this.field_70889_i = 1.0F;
	}

	this.field_70889_i = (float) ((double) this.field_70889_i * 0.9D);

	if (!this.onGround && this.motionY < 0.0D) {
		this.motionY *= 0.6D;
	}

	this.field_70886_e += this.field_70889_i * 2.0F;

	if (!this.isChild() && !this.worldObj.isRemote
			&& --this.timeUntilNextEgg == 0) {
		this.playSound(
				"mob.chicken.plop",
				1.0F,
				(this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
		this.dropItem(Item.diamond.itemID, 1);
		this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
	}
}

/**
 * Called when the mob is falling. Calculates and applies fall damage.
 */
protected void fall(float par1) {
}

/**
 * Returns the sound this mob makes while it's alive.
 */
protected String getLivingSound() {
	return "mob.chicken.say";
}

/**
 * Returns the sound this mob makes when it is hurt.
 */
protected String getHurtSound() {
	return "mob.chicken.hurt";
}

/**
 * Returns the sound this mob makes on death.
 */
protected String getDeathSound() {
	return "mob.chicken.hurt";
}

/**
 * Plays step sound at given x, y, z for the entity
 */
protected void playStepSound(int par1, int par2, int par3, int par4) {
	this.playSound("mob.chicken.step", 0.15F, 1.0F);
}

/**
 * Returns the item ID for the item the mob drops on death.
 */
protected int getDropItemId() {
	return Item.feather.itemID;
}

/**
 * Drop 0-2 items of this living's type. @param par1 - Whether this entity
 * has recently been hit by a player. @param par2 - Level of Looting used to
 * kill this mob.
 */
protected void dropFewItems(boolean par1, int par2) {
	int j = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);

	for (int k = 0; k < j; ++k) {
		if (this.isTamed()) {
		this.dropItem(Item.diamond.itemID, 1);
		} else {
			this.dropItem(Item.egg.itemID, 1);
		}
	}

	if (this.isBurning()) {
		this.dropItem(Item.chickenCooked.itemID, 1);
	} else {
		this.dropItem(Item.chickenRaw.itemID, 1);
	}
}

/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow,
 * gets into the saddle on a pig.
 */
public boolean interact(EntityPlayer par1EntityPlayer) {
	ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
	if (!this.isTamed()) {
		if (itemstack != null && itemstack.itemID == Item.diamond.itemID) {
			if (!par1EntityPlayer.capabilities.isCreativeMode) {
				--itemstack.stackSize;
			}

			if (itemstack.stackSize <= 0) {
				par1EntityPlayer.inventory.setInventorySlotContents(
						par1EntityPlayer.inventory.currentItem,
						(ItemStack) null);
			}

			if (!this.worldObj.isRemote) {
				if (this.rand.nextInt(3) == 0) {
					this.setTamed(true);
					this.setPathToEntity((PathEntity) null);
					this.setAttackTarget((EntityLivingBase) null);
					this.setTarget(null);
					this.setOwner(par1EntityPlayer.getCommandSenderName());
					this.playTameEffect(true);
				} else {
					this.playTameEffect(false);
					this.worldObj.setEntityState(this, (byte) 6);
				}
			}

			return true;
		}
	}

	return super.interact(par1EntityPlayer);
}

/**
 * This function is used when two same-species animals in 'love mode' breed
 * to generate the new baby animal.
 */
public EntityBlueChicken spawnBabyAnimal(EntityAgeable par1EntityAgeable) {
	EntityBlueChicken entitybluechicken = new EntityBlueChicken(
			this.worldObj);
	String s = this.getOwnerName();

	if (s != null && s.trim().length() > 0) {
		entitybluechicken.setOwner(s);
		entitybluechicken.setTamed(true);
	}

	return entitybluechicken;
}

/**
 * Checks if the parameter is an item which this animal can be fed to breed
 * it (wheat, carrots or seeds depending on the animal type)
 */
public boolean isBreedingItem(ItemStack par1ItemStack) {
	if (this.isTamed()) {
		return par1ItemStack != null
				&& par1ItemStack.itemID == Item.diamond.itemID;
	} else {
		return false;
	}
}

public EntityAgeable createChild(EntityAgeable par1EntityAgeable) {
	return this.spawnBabyAnimal(par1EntityAgeable);
}
}

 

ChickAITempt:

package mods.mochickens.misc;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.item.ItemStack;

public class ChickAITempt extends EntityAITempt {

public ChickAITempt(EntityCreature temptedEntityInit, double movementSpeedInit, int temptingItemIDInit, boolean scaredByPlayerMovementInit)
    {
       super(temptedEntityInit, movementSpeedInit, temptingItemIDInit, scaredByPlayerMovementInit);
    }

@Override
public boolean shouldExecute() {
	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() != EntityTameable.getOwner())
			return false;
		if (this.getTemptingPlayer() == null) {
			return false;
		} else {
			ItemStack itemstack = this.getTemptingPlayer()
					.getCurrentEquippedItem();
			return itemstack == null ? false : itemstack.itemID == this
					.getBreedingFood();
		}
	}
}

//public EntityLivingBase func_130012_q() {
//	return this.worldObj.getPlayerEntityByName(this.getOwnerName());
//}  
}

 

I cannot call on a dataWatcher to get the owner, otherwise it tells me to set it to a static method which dataWatcher cannot run in. so im getting stuck in a loop of "set the method to a static method" "remove static modifier from this method" and the only way to get past that is to modify the entity class which i refuse to do. i tried adding my own dataWatcher but the game crashed when i tried spawning in the mob with the error: id already taken.

Posted

i figured it out. i got around the static problem by setting a variable equal to the owner. then i did some logger data to fix issues with the tempting player and the owner not matching when i knew it should match. so now here is my updated shouldExicute() method.

 

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();
		}
	}
}

 

ive tested it and it works like it should, i can now finally get on and finish the mod! :D thank you for your help.

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.