Jump to content

saxon564

Forge Modder
  • Posts

    490
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by saxon564

  1. for most of them, just one i want custom which is in the onLivingUpdae() method. and before you point me toward your tutorial, i have looked at it and thats how i got to this point, i just cant get it to play in game. 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.worldObj.playSoundAtEntity(this, "mochickens:sounds/layDiamond", 1.0F, 1.0F); this.dropItem(Item.diamond.itemID, 1); this.timeUntilNextEgg = this.rand.nextInt(1) + 60; } } specifically this block of it if (!this.isChild() && !this.worldObj.isRemote && --this.timeUntilNextEgg == 0) { this.worldObj.playSoundAtEntity(this, "mochickens:sounds/layDiamond", 1.0F, 1.0F); this.dropItem(Item.diamond.itemID, 1); this.timeUntilNextEgg = this.rand.nextInt(1) + 60; } line is this.worldObj.playSoundAtEntity(this, "mochickens:sounds/layDiamond", 1.0F, 1.0F);
  2. I have looked at several other threads and tutorials on this but it just doesnt seem to want to work. I am trying to add a custom sound to a mob, though this sound isnt nessecary i would still like to add it to my mob. here is what i have. classes: As i said, i have tried everything i have seen to fix this. the sound file is in src/assets/mochickens/sounds/layDiamond.ogg
  3. 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! thank you for your help.
  4. 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.
  5. 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.
  6. 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?
  7. 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?
  8. FINALLY!!!! targetTasks.taskEntries.clear() was all i needed. i replaced this.targetTasks.removeTask(newEntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true)); with the clear() and now it works! thank you so much!
  9. 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; } } the check on if the mob is tamed or not causes it not to do damage if its tamed. targetTasks does not have a clear() method. the field_7088x is not something i coded, i told the code from vanilla files that did essentially what i wanted, i just had to modify it to what i need it to do, which is whats causing the trouble. the method removeTask() is shown as this: public void removeTask(EntityAIBase par1EntityAIBase) { Iterator iterator = this.taskEntries.iterator(); while (iterator.hasNext()) { EntityAITaskEntry entityaitaskentry = (EntityAITaskEntry)iterator.next(); EntityAIBase entityaibase1 = entityaitaskentry.action; if (entityaibase1 == par1EntityAIBase) { if (this.executingTaskEntries.contains(entityaitaskentry)) { entityaibase1.resetTask(); this.executingTaskEntries.remove(entityaitaskentry); } iterator.remove(); } } } this does not show much much in which i could change in my code. I added a couple lines to the logging process to make it easier to see where it is coming from and here is what im getting. updated 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; MinecraftServer.getServer().getLogAgent().logInfo("entity init"); 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"); MinecraftServer.getServer().getLogAgent().logInfo("reading NBT"); if (s.length() > 0) { MinecraftServer.getServer().getLogAgent().logInfo("setting tamed"); MinecraftServer.getServer().getLogAgent().logInfo("Owner: " + s); this.setTamed(true); this.setOwner(s); } } @Override public void setTamed(boolean par1) { byte b0 = this.dataWatcher.getWatchableObjectByte(16); MinecraftServer.getServer().getLogAgent().logInfo("in setTamed"); 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.removeTask(new EntityAINearestAttackableTarget( this, EntityPlayer.class, 0, true)); this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Block.blockDiamond.blockID, false)); this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; MinecraftServer.getServer().getLogAgent().logInfo("set tasks"); } else { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -5))); MinecraftServer.getServer().getLogAgent().logInfo("not tasks"); } } 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) { this.dropItem(Item.diamond.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); this.worldObj.setEntityState(this, (byte) 7); this.tasks.removeTask(new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false)); this.targetTasks .removeTask(new EntityAINearestAttackableTarget( this, EntityPlayer.class, 0, true)); this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Block.blockDiamond.blockID, false)); this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; } 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); } } new logs: from what i am seeing, it is setting up 3 more entities after the tamed one, i am wondering if there is a way to see if they are the same instance of the tamed one, or if they are different instances or it. if they are the same instance then that would explain why the targetTask doesnt seem to be getting removed.
  10. here is my most recent 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"); MinecraftServer.getServer().getLogAgent().logInfo("reading NBT"); if (s.length() > 0) { MinecraftServer.getServer().getLogAgent().logInfo("setting tamed"); this.setTamed(true); this.setOwner(s); } } @Override public void setTamed(boolean par1) { byte b0 = this.dataWatcher.getWatchableObjectByte(16); MinecraftServer.getServer().getLogAgent().logInfo("in setTamed"); if (par1) { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 4))); MinecraftServer.getServer().getLogAgent().logInfo("set tasks"); } else { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -5))); this.worldObj.setEntityState(this, (byte) 7); this.tasks.removeTask(new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false)); this.targetTasks.removeTask(new EntityAINearestAttackableTarget( this, EntityPlayer.class, 0, true)); this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Block.blockDiamond.blockID, false)); this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; MinecraftServer.getServer().getLogAgent().logInfo("not tasks"); } } 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) { this.dropItem(Item.diamond.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); this.worldObj.setEntityState(this, (byte) 7); this.tasks.removeTask(new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false)); this.targetTasks .removeTask(new EntityAINearestAttackableTarget( this, EntityPlayer.class, 0, true)); this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Block.blockDiamond.blockID, false)); this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; } 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); } } here are the world load logs: ive tried putting the tasks in either part of the if in the setTamed and neither of the changes seemed to work, the chicken still chased other players without dealing damage after restarting the world.
  11. lets see if im understand this right, if i am and i'm in fact doing it right, then its still not working, otherwise, a more in depth explanation might help? so what your saying is, i need to override the readEntityFromNBT and call on another method if the section that sets the mob being tamed to set the tasks the way they need to be set? eg. public final void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { super.readEntityFromNBT(par1NBTTagCompound); String s = par1NBTTagCompound.getString("Owner"); if (s.length() > 0) { this.setTamed(true); this.setOwner(s); this.setTasks(); } } public void setTasks() { if (this.isTamed()) { this.worldObj.setEntityState(this, (byte) 7); this.tasks.removeTask(new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false)); this.targetTasks.removeTask(new EntityAINearestAttackableTarget( this, EntityPlayer.class, 0, true)); this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Block.blockDiamond.blockID, false)); this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; } }
  12. upon further testing, i found out that what i did actually didnt work, it stopped the mob from chasing players, but it set it to that with mobs that werent tamed. im just lost with this. could someone show me some sort of an example so i can see what it should look like?
  13. ok, well i looked through the readEntityNBT method and changed the check in the constructor from !isTamed() to if (this.getOwner() == null). now the last thing id like to get working is that it will only be tempted by its owner. I've looked at everything about tempting that i could find and the only way i could figure out is to remake the EntityAITempt class and modify it, the problem is that I dont know where the ShouldExicute() method is called and used and I can't call on entity.getOwner() to check if the tempting player is its owner or not. are there any suggestions for what i should to to get around this? or where to look?
  14. but even if the owner isnt anywhere i dont want it chasing any other players. thats where the problem is, i dont know what i need to change to stop it from chasing other players.
  15. still hasn't been solved. if there is any information that you need that isn't on here, just let me know and i will add it.
  16. anyone have any thoughts about this?
  17. Everything ive tried to fix it before i made this post didnt work. Does anyone have any ideas?
  18. I'm having a problem with my mob where once its tamed it works fine, but when I shut down the game for a day then come back, it is no longer acting as if its tamed even though it doesn't deal damage. So by default its suppose to be hostile, but when you tame it, its no longer hostile and isn't suppose to attack anyone or anything, this works like it should, but the problem i stated above then come into play where after a day of not running the game, it will target you like its not tamed, but won't do damage as if it is. Also the other thing that goes hand in hand with this issue, is that since this is a chicken, i want it to lay something only when its tamed. But as with the targeting it will stop laying the item. Does anyone have any idea why this is? Heres my code:
  19. and for those that want to see the end product of this mobs entity code, here it is!
  20. Awesome! Thank you so much! No that this mob is done the rest will be easy to make since they all follow the same basic idea! You guys are so awesome with being able to help. Again, thank you so much!
  21. this is the last error i have with my mod right now. for some reason it is not showing the name in game like it should and i didnt change the code for that from the last time it worked. it shows "Entity.mochickens.Blue Chicken.name" instead of the name. im sure i know the problem is because of that space, but where the space is getting added is what i dont get. Here is the code: package mods.mochickens; import java.util.List; import mods.mochickens.client.ClientProxyMoChickens; import mods.mochickens.mobs.EntityBlueChicken; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityEggInfo; import net.minecraft.entity.EntityList; import net.minecraft.entity.EnumCreatureType; import net.minecraft.item.EnumToolMaterial; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.Configuration; import net.minecraftforge.common.EnumHelper; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.PreInit; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = "mochickens", name = "Mo' Chickens", version = "1.0") @NetworkMod(clientSideRequired = true, serverSideRequired = true) public class MoChickens { @Instance("mochickens") public static MoChickens instance; @SidedProxy(clientSide = "mods.mochickens.client.ClientProxyMoChickens", serverSide = "mods.mochickens.common.CommonProxyMoChickens") public static ClientProxyMoChickens proxy; int blueChickenEggID; static int startEntityId = 300; @EventHandler public void preInit(FMLPreInitializationEvent event) { Configuration config = new Configuration(event.getSuggestedConfigurationFile()); blueChickenEggID = config.get("Item IDs", "Blue Chicken Egg ID", 514).getInt(); config.save(); } @EventHandler public void load(FMLInitializationEvent event){ languageRegisters(); entityRegisters(); EggRegisters(); proxy.registerRenders(); } // Add Spawn Egg public static int getUniqueEntityID() { do { startEntityId++; } while(EntityList.getStringFromID(startEntityId) != null); return startEntityId; } public static void registerEntityEgg(Class <? extends Entity> entity, int primaryColor, int secondaryColor) { int id = getUniqueEntityID(); EntityList.IDtoClassMapping.put(id, entity); EntityList.entityEggs.put(id, new EntityEggInfo(id, primaryColor, secondaryColor)); } public void EggRegisters() { registerEntityEgg(EntityBlueChicken.class, 0x0000FF, 0x000000); } //Add Mobs public void entityRegisters() { EntityRegistry.registerModEntity(EntityBlueChicken.class,"Blue Chicken", 2, this , 40, 3, true); EntityRegistry.addSpawn(EntityBlueChicken.class, 5, 1, 2, EnumCreatureType.creature, BiomeGenBase.beach, BiomeGenBase.extremeHills, BiomeGenBase.extremeHillsEdge, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.mushroomIsland, BiomeGenBase.mushroomIslandShore, BiomeGenBase.ocean, BiomeGenBase.plains, BiomeGenBase.river, BiomeGenBase.swampland); } private static void languageRegisters() { LanguageRegistry.instance().addStringLocalization("entity.mochickens.BlueChicken.name", "Blue Chicken"); } }
  22. Thanks! i had actually just figured it out myself, but used a lot more lines of code because i copied it from the EntityMob class. I think i'll use the way i found because it shows more of how i can customize what happens to the player, but your help was still much appreciated. now on to making it so you can tame it and it will stop attacking you. think this will be a bit easier than the damage thing was, though once i thought of it i realized that it was an easy thing to get working. anyway thanks for your help! Code i am using for those that are seeing this in the future: public boolean attackEntityAsMob(Entity par1Entity) { EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); float f = (float) 3.0D; int i = 0; if (entityplayer instanceof EntityLivingBase) { f += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase)entityplayer); i += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase)entityplayer); } 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; } (some of this isnt needed but im keeping it for refernce)
  23. I've looked at the wolf class because i do want it to be possible to tame the mob, so i set the extending class to EntityTameable. which still didnt fix the problem. the error sounds like the collision is returning null. at this point im wondering if there is a way to manually code this in. if i make it extend EntityCreature or EntityMob its breaks the mating part of it as well as means i cant make it tameable. code and error did not change except for trying to extend the different entities and ended on EntityTamable. @Draco EntityWolf is in the passive package, not the hostile package.
  24. added that method and the problem persists. i really have no idea what exactly i need to do to get it to work. Updated Code: package mods.mochickens.mobs; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityAgeable; 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.EntityAnimal; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemSeeds; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class EntityBlueChicken extends EntityAnimal { 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); this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000; float f = 0.25F; this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIPanic(this, 1.4D)); this.tasks.addTask(2, new EntityAIMate(this, 1.0D)); this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false)); this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Block.blockDiamond.blockID, false)); 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.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true)); } /** * Returns true if the newer Entity AI code should be run */ public boolean isAIEnabled() { return true; } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(3.0D); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(4.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.25D); } public boolean attackEntityAsMob(Entity par1Entity) { return true; } /** * 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.diamond.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) { this.dropItem(Item.diamond.itemID, 1); } if (this.isBurning()) { this.dropItem(Item.chickenCooked.itemID, 1); } else { this.dropItem(Item.chickenRaw.itemID, 1); } } /** * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal. */ public EntityBlueChicken spawnBabyAnimal(EntityAgeable par1EntityAgeable) { return new EntityBlueChicken(this.worldObj); } /** * 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) { return par1ItemStack != null && par1ItemStack.itemID == Item.diamond.itemID; } public EntityAgeable createChild(EntityAgeable par1EntityAgeable) { return this.spawnBabyAnimal(par1EntityAgeable); } } most recent error:
  25. Now that I have the textures fixed, and another bug repaired, now i want to get the mob to deal damage to a player. I've looked at the code of other mobs and pasted the code that made sence in, but the line i added just causes the mob to "crash" so it doesnt spawn or despawns if already spawned. Here is the code I have: here is the line that ive been trying to add to the applyEntityAttributes() method: this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(3.0D); Here is the error i have been getting:
×
×
  • Create New...

Important Information

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