-
Tamed Mob not following and question about sitting implementation
Hi, I am still having trouble getting my entity to follow me when it is tamed. Tamed and owner is being set once the entity is tamed and isSitting is false when I right click on the entity with an empty hand in game. I have tried everything I can think of. Can anyone see where I am going wrong please? Many thanks Jim package com.malovern.elliesmod.entity; import com.malovern.elliesmod.ElliesMod; import com.malovern.elliesmod.food.FoodChocCookie; 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.EntityAIBeg; import net.minecraft.entity.ai.EntityAIFollowOwner; import net.minecraft.entity.ai.EntityAIFollowParent; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMate; import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget; import net.minecraft.entity.ai.EntityAIOwnerHurtTarget; 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.passive.EntityTameable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.pathfinding.PathEntity; import net.minecraft.util.DamageSource; import net.minecraft.world.World; public class EntityBigBearMob extends EntityTameable { public EntityBigBearMob(World par1World) { super(par1World); this.setSize(1F, 1F); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F)); this.tasks.addTask(2, this.aiSit); this.tasks.addTask(3, new EntityAIWander(this,0.6D)); this.tasks.addTask(4, new EntityAIPanic(this,0.7D)); this.tasks.addTask(5, new EntityAILookIdle(this)); this.tasks.addTask(6, new EntityAIFollowParent(this, 0.6F)); this.tasks.addTask(7, new EntityAIMate(this, 0.3F)); this.tasks.addTask(8, new EntityAITempt(this,0.7D,Items.apple,false)); this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true)); this.setTamed(false); } protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(18, new Float(this.getHealth())); this.dataWatcher.addObject(19, new Byte((byte)0)); } public boolean isAIEnabled() { return true; } @Override public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(16.0F); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5F); this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D); } @Override public boolean canDespawn() { return false; } @Override protected float getSoundVolume() { return 0.4F; } public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) { if (this.isEntityInvulnerable()) { return false; } else { this.aiSit.setSitting(false); return super.attackEntityFrom(par1DamageSource, par2); } } @Override protected String getLivingSound() { if (this.rand.nextInt(4)==0) { return ElliesMod.MODID + ":BigBearLiving"; } else if (this.rand.nextInt(4)==1) { return ElliesMod.MODID + ":BigBearLiving1"; } else { return ElliesMod.MODID + ":BigBearLiving2"; } } @Override protected String getHurtSound() { return ElliesMod.MODID + ":BigBearHurt"; } @Override protected String getDeathSound() { return ElliesMod.MODID + ":BigBearDeath"; } public boolean interact(EntityPlayer par1EntityPlayer) { ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem(); if (this.isTamed()) { if (itemstack != null) { if (itemstack.getItem() instanceof ItemFood) { ItemFood itemfood = (ItemFood)itemstack.getItem(); if (itemfood.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) { if (!par1EntityPlayer.capabilities.isCreativeMode) { --itemstack.stackSize; } this.heal((float)itemfood.func_150905_g(itemstack)); if (itemstack.stackSize <= 0) { par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null); } return true; } } } if (par1EntityPlayer.getCommandSenderName().equalsIgnoreCase(this.getOwnerName()) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack)) { System.out.println("Owner Name = " + par1EntityPlayer.getCommandSenderName()); System.out.println("Sitting = " + this.isSitting()); System.out.println("Tamed = " + this.isTamed()); this.setSitting(false); //this.aiSit.setSitting(!this.isSitting()); this.isJumping = false; //this.setPathToEntity((PathEntity)null); //this.setTarget((Entity)null); //this.setAttackTarget((EntityLivingBase)null); } } else if (itemstack != null && itemstack.getItem() == Items.apple) { 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); System.out.println("Tamed = " + this.isTamed()); //this.setPathToEntity((PathEntity)null); //this.setAttackTarget((EntityLivingBase)null); this.setSitting(false); this.setHealth(20.0F); this.setOwner (par1EntityPlayer.getCommandSenderName()); System.out.println("Owner = " + this.getOwnerName()); this.playTameEffect(true); this.worldObj.setEntityState(this, (byte)7); } else { this.playTameEffect(false); this.worldObj.setEntityState(this, (byte)6); } } return true; } return super.interact(par1EntityPlayer); } public void setOwner(String par1Str) { this.dataWatcher.updateObject(17, par1Str); } public String getOwnerName() { return this.dataWatcher.getWatchableObjectString(17); } // public void setTameValue(byte par0) { // // this.dataWatcher.updateObject(20, par0); // } // // public byte getTameValue() { // // return this.dataWatcher.getWatchableObjectByte(20); // } @Override public void setTamed(boolean param) { super.setTamed(param); if (param) { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); } else { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D); } } // @Override public EntityBigBearMob createChild(EntityAgeable par1EntityAgeable) { EntityBigBearMob var2 = new EntityBigBearMob(this.worldObj); this.worldObj.spawnEntityInWorld(var2); System.out.println("createChild is tamed: " + this.isTamed()); if (this.isTamed()) { var2.setOwner(this.getCommandSenderName()); var2.setTamed(true); System.out.println("createChild : Second Player name : " + this.getCommandSenderName()); } return var2; } public boolean isBreedingItem(ItemStack par1ItemStack) { return par1ItemStack != null && par1ItemStack.getItem() == FoodChocCookie.itemChocCookie; } }
-
Tamed Mob not following and question about sitting implementation
Hi jabelar, That makes sense - I will look at that tomorrow and thank you vm for the tutorial links I will definately check those out
-
Tamed Mob not following and question about sitting implementation
Hi all, Just starting out in the forge world with a mod for my daughter - modelling her bear in MC - unfortunately, I cannot seem to get the mob to follow me once tamed. I have checked whether or not the mob is sitting (although I have no animation for that yet) and checked the EntityWolf class for clues but I just cannot figure it out. Everything else works, breeding, taming and following me when I hold an apple (set to fav). Also, can anyone give me any pointers on how to create a sitting animation / code ? Any help appreciated! Jim package com.malovern.elliesmod.entity; import com.malovern.elliesmod.ElliesMod; import com.malovern.elliesmod.food.FoodChocCookie; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIFollowOwner; import net.minecraft.entity.ai.EntityAIFollowParent; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMate; import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget; import net.minecraft.entity.ai.EntityAIOwnerHurtTarget; 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.passive.EntityTameable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.world.World; public class EntityBigBearMob extends EntityTameable { public EntityBigBearMob(World par1World) { super(par1World); this.setSize(1F, 1F); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIFollowOwner(this, 0.6F, 10.0F, 0.7F)); this.tasks.addTask(2, this.aiSit); this.tasks.addTask(3, new EntityAIWander(this,0.6D)); this.tasks.addTask(4, new EntityAIPanic(this,0.7D)); this.tasks.addTask(5, new EntityAILookIdle(this)); this.tasks.addTask(6, new EntityAIFollowParent(this, 0.6F)); this.tasks.addTask(7, new EntityAIMate(this, 0.3F)); this.tasks.addTask(8, new EntityAITempt(this,0.7D,Items.apple,false)); this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true)); this.setTamed(false); } public boolean isAIEnabled() { return true; } @Override public void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(16.0F); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5F); this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(40.0D); } @Override public boolean canDespawn() { return false; } @Override protected float getSoundVolume() { return 0.4F; } public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) { if (this.isEntityInvulnerable()) { return false; } else { this.aiSit.setSitting(false); return super.attackEntityFrom(par1DamageSource, par2); } } @Override protected String getLivingSound() { //return this.isTamed() ? (this.isInLove() ? "mob.cat.purr" : (this.rand.nextInt(4) == 0 ? "mob.cat.purreow" : "mob.cat.meow")) if (this.rand.nextInt(4)==0) { return ElliesMod.MODID + ":BigBearLiving"; } else if (this.rand.nextInt(4)==1) { return ElliesMod.MODID + ":BigBearLiving1"; } else { return ElliesMod.MODID + ":BigBearLiving2"; } } @Override protected String getHurtSound() { return ElliesMod.MODID + ":BigBearHurt"; } @Override protected String getDeathSound() { return ElliesMod.MODID + ":BigBearDeath"; } public boolean interact(EntityPlayer par1EntityPlayer) { ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem(); if (this.isTamed()) { if (itemstack != null) { if (itemstack.getItem() instanceof ItemFood) { ItemFood itemfood = (ItemFood)itemstack.getItem(); if (itemfood.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) { if (!par1EntityPlayer.capabilities.isCreativeMode) { --itemstack.stackSize; } this.heal((float)itemfood.func_150905_g(itemstack)); if (itemstack.stackSize <= 0) { par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null); } return true; } } } if (par1EntityPlayer.getCommandSenderName().equalsIgnoreCase(this.getOwnerName()) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack)) { this.setOwner(par1EntityPlayer.getCommandSenderName()); //this.setSitting(!this.isSitting()); this.aiSit.setSitting(!this.isSitting()); this.isJumping = false; this.setPathToEntity(null); this.setTarget(null); this.setAttackTarget(null); } } else if (itemstack != null && itemstack.getItem() == Items.apple) { 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(null); this.setAttackTarget(null); this.aiSit.setSitting(true); this.setHealth(20.0F); this.setOwner (par1EntityPlayer.getCommandSenderName()); this.playTameEffect(true); this.worldObj.setEntityState(this, (byte)7); } else { this.playTameEffect(false); this.worldObj.setEntityState(this, (byte)6); } } return true; } return super.interact(par1EntityPlayer); } public void setOwner(String par1Str) { this.dataWatcher.updateObject(17, par1Str); } public String getOwnerName() { return this.dataWatcher.getWatchableObjectString(17); } public void setTameValue(byte par0) { this.dataWatcher.updateObject(20, par0); } public byte getTameValue() { return this.dataWatcher.getWatchableObjectByte(20); } public void setTamed(boolean param) { super.setTamed(param); if (param) { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D); } else { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D); } } @Override public EntityBigBearMob createChild(EntityAgeable par1EntityAgeable) { EntityBigBearMob var2 = new EntityBigBearMob(this.worldObj); this.worldObj.spawnEntityInWorld(var2); //System.out.println("createChild is tamed: " + this.isTamed()); //if (this.isTamed()) //{ var2.setOwner(this.getCommandSenderName()); var2.setTamed(true); System.out.println("createChild : Second Player name : " + this.getCommandSenderName()); //} return var2; } public boolean isBreedingItem(ItemStack par1ItemStack) { return par1ItemStack != null && par1ItemStack.getItem() == FoodChocCookie.itemChocCookie; } }
IPS spam blocked by CleanTalk.