001 package net.minecraft.src; 002 003 public class EntityPig extends EntityAnimal 004 { 005 public EntityPig(World par1World) 006 { 007 super(par1World); 008 this.texture = "/mob/pig.png"; 009 this.setSize(0.9F, 0.9F); 010 this.getNavigator().setAvoidsWater(true); 011 float var2 = 0.25F; 012 this.tasks.addTask(0, new EntityAISwimming(this)); 013 this.tasks.addTask(1, new EntityAIPanic(this, 0.38F)); 014 this.tasks.addTask(2, new EntityAIMate(this, var2)); 015 this.tasks.addTask(3, new EntityAITempt(this, 0.25F, Item.wheat.shiftedIndex, false)); 016 this.tasks.addTask(4, new EntityAIFollowParent(this, 0.28F)); 017 this.tasks.addTask(5, new EntityAIWander(this, var2)); 018 this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); 019 this.tasks.addTask(7, new EntityAILookIdle(this)); 020 } 021 022 /** 023 * Returns true if the newer Entity AI code should be run 024 */ 025 public boolean isAIEnabled() 026 { 027 return true; 028 } 029 030 public int getMaxHealth() 031 { 032 return 10; 033 } 034 035 protected void entityInit() 036 { 037 super.entityInit(); 038 this.dataWatcher.addObject(16, Byte.valueOf((byte)0)); 039 } 040 041 /** 042 * (abstract) Protected helper method to write subclass entity data to NBT. 043 */ 044 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) 045 { 046 super.writeEntityToNBT(par1NBTTagCompound); 047 par1NBTTagCompound.setBoolean("Saddle", this.getSaddled()); 048 } 049 050 /** 051 * (abstract) Protected helper method to read subclass entity data from NBT. 052 */ 053 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) 054 { 055 super.readEntityFromNBT(par1NBTTagCompound); 056 this.setSaddled(par1NBTTagCompound.getBoolean("Saddle")); 057 } 058 059 /** 060 * Returns the sound this mob makes while it's alive. 061 */ 062 protected String getLivingSound() 063 { 064 return "mob.pig"; 065 } 066 067 /** 068 * Returns the sound this mob makes when it is hurt. 069 */ 070 protected String getHurtSound() 071 { 072 return "mob.pig"; 073 } 074 075 /** 076 * Returns the sound this mob makes on death. 077 */ 078 protected String getDeathSound() 079 { 080 return "mob.pigdeath"; 081 } 082 083 /** 084 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. 085 */ 086 public boolean interact(EntityPlayer par1EntityPlayer) 087 { 088 if (super.interact(par1EntityPlayer)) 089 { 090 return true; 091 } 092 else if (this.getSaddled() && !this.worldObj.isRemote && (this.riddenByEntity == null || this.riddenByEntity == par1EntityPlayer)) 093 { 094 par1EntityPlayer.mountEntity(this); 095 return true; 096 } 097 else 098 { 099 return false; 100 } 101 } 102 103 /** 104 * Returns the item ID for the item the mob drops on death. 105 */ 106 protected int getDropItemId() 107 { 108 return this.isBurning() ? Item.porkCooked.shiftedIndex : Item.porkRaw.shiftedIndex; 109 } 110 111 /** 112 * Drop 0-2 items of this living's type 113 */ 114 protected void dropFewItems(boolean par1, int par2) 115 { 116 int var3 = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + par2); 117 118 for (int var4 = 0; var4 < var3; ++var4) 119 { 120 if (this.isBurning()) 121 { 122 this.dropItem(Item.porkCooked.shiftedIndex, 1); 123 } 124 else 125 { 126 this.dropItem(Item.porkRaw.shiftedIndex, 1); 127 } 128 } 129 } 130 131 /** 132 * Returns true if the pig is saddled. 133 */ 134 public boolean getSaddled() 135 { 136 return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0; 137 } 138 139 /** 140 * Set or remove the saddle of the pig. 141 */ 142 public void setSaddled(boolean par1) 143 { 144 if (par1) 145 { 146 this.dataWatcher.updateObject(16, Byte.valueOf((byte)1)); 147 } 148 else 149 { 150 this.dataWatcher.updateObject(16, Byte.valueOf((byte)0)); 151 } 152 } 153 154 /** 155 * Called when a lightning bolt hits the entity. 156 */ 157 public void onStruckByLightning(EntityLightningBolt par1EntityLightningBolt) 158 { 159 if (!this.worldObj.isRemote) 160 { 161 EntityPigZombie var2 = new EntityPigZombie(this.worldObj); 162 var2.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); 163 this.worldObj.spawnEntityInWorld(var2); 164 this.setDead(); 165 } 166 } 167 168 /** 169 * Called when the mob is falling. Calculates and applies fall damage. 170 */ 171 protected void fall(float par1) 172 { 173 super.fall(par1); 174 175 if (par1 > 5.0F && this.riddenByEntity instanceof EntityPlayer) 176 { 177 ((EntityPlayer)this.riddenByEntity).triggerAchievement(AchievementList.flyPig); 178 } 179 } 180 181 /** 182 * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal. 183 */ 184 public EntityAnimal spawnBabyAnimal(EntityAnimal par1EntityAnimal) 185 { 186 return new EntityPig(this.worldObj); 187 } 188 }