001 package net.minecraft.entity.monster;
002
003 import cpw.mods.fml.relauncher.Side;
004 import cpw.mods.fml.relauncher.SideOnly;
005 import java.util.List;
006 import net.minecraft.entity.Entity;
007 import net.minecraft.entity.player.EntityPlayer;
008 import net.minecraft.item.Item;
009 import net.minecraft.item.ItemStack;
010 import net.minecraft.nbt.NBTTagCompound;
011 import net.minecraft.util.DamageSource;
012 import net.minecraft.world.World;
013
014 public class EntityPigZombie extends EntityZombie
015 {
016 /** Above zero if this PigZombie is Angry. */
017 private int angerLevel = 0;
018
019 /** A random delay until this PigZombie next makes a sound. */
020 private int randomSoundDelay = 0;
021
022 public EntityPigZombie(World par1World)
023 {
024 super(par1World);
025 this.texture = "/mob/pigzombie.png";
026 this.moveSpeed = 0.5F;
027 this.isImmuneToFire = true;
028 }
029
030 /**
031 * Returns true if the newer Entity AI code should be run
032 */
033 protected boolean isAIEnabled()
034 {
035 return false;
036 }
037
038 /**
039 * Called to update the entity's position/logic.
040 */
041 public void onUpdate()
042 {
043 this.moveSpeed = this.entityToAttack != null ? 0.95F : 0.5F;
044
045 if (this.randomSoundDelay > 0 && --this.randomSoundDelay == 0)
046 {
047 this.playSound("mob.zombiepig.zpigangry", this.getSoundVolume() * 2.0F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 1.8F);
048 }
049
050 super.onUpdate();
051 }
052
053 @SideOnly(Side.CLIENT)
054
055 /**
056 * Returns the texture's file path as a String.
057 */
058 public String getTexture()
059 {
060 return "/mob/pigzombie.png";
061 }
062
063 /**
064 * Checks if the entity's current position is a valid location to spawn this entity.
065 */
066 public boolean getCanSpawnHere()
067 {
068 return this.worldObj.difficultySetting > 0 && this.worldObj.checkIfAABBIsClear(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox);
069 }
070
071 /**
072 * (abstract) Protected helper method to write subclass entity data to NBT.
073 */
074 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
075 {
076 super.writeEntityToNBT(par1NBTTagCompound);
077 par1NBTTagCompound.setShort("Anger", (short)this.angerLevel);
078 }
079
080 /**
081 * (abstract) Protected helper method to read subclass entity data from NBT.
082 */
083 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
084 {
085 super.readEntityFromNBT(par1NBTTagCompound);
086 this.angerLevel = par1NBTTagCompound.getShort("Anger");
087 }
088
089 /**
090 * Finds the closest player within 16 blocks to attack, or null if this Entity isn't interested in attacking
091 * (Animals, Spiders at day, peaceful PigZombies).
092 */
093 protected Entity findPlayerToAttack()
094 {
095 return this.angerLevel == 0 ? null : super.findPlayerToAttack();
096 }
097
098 /**
099 * Called when the entity is attacked.
100 */
101 public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
102 {
103 if (this.isEntityInvulnerable())
104 {
105 return false;
106 }
107 else
108 {
109 Entity var3 = par1DamageSource.getEntity();
110
111 if (var3 instanceof EntityPlayer)
112 {
113 List var4 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(32.0D, 32.0D, 32.0D));
114
115 for (int var5 = 0; var5 < var4.size(); ++var5)
116 {
117 Entity var6 = (Entity)var4.get(var5);
118
119 if (var6 instanceof EntityPigZombie)
120 {
121 EntityPigZombie var7 = (EntityPigZombie)var6;
122 var7.becomeAngryAt(var3);
123 }
124 }
125
126 this.becomeAngryAt(var3);
127 }
128
129 return super.attackEntityFrom(par1DamageSource, par2);
130 }
131 }
132
133 /**
134 * Causes this PigZombie to become angry at the supplied Entity (which will be a player).
135 */
136 private void becomeAngryAt(Entity par1Entity)
137 {
138 this.entityToAttack = par1Entity;
139 this.angerLevel = 400 + this.rand.nextInt(400);
140 this.randomSoundDelay = this.rand.nextInt(40);
141 }
142
143 /**
144 * Returns the sound this mob makes while it's alive.
145 */
146 protected String getLivingSound()
147 {
148 return "mob.zombiepig.zpig";
149 }
150
151 /**
152 * Returns the sound this mob makes when it is hurt.
153 */
154 protected String getHurtSound()
155 {
156 return "mob.zombiepig.zpighurt";
157 }
158
159 /**
160 * Returns the sound this mob makes on death.
161 */
162 protected String getDeathSound()
163 {
164 return "mob.zombiepig.zpigdeath";
165 }
166
167 /**
168 * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
169 * par2 - Level of Looting used to kill this mob.
170 */
171 protected void dropFewItems(boolean par1, int par2)
172 {
173 int var3 = this.rand.nextInt(2 + par2);
174 int var4;
175
176 for (var4 = 0; var4 < var3; ++var4)
177 {
178 this.dropItem(Item.rottenFlesh.itemID, 1);
179 }
180
181 var3 = this.rand.nextInt(2 + par2);
182
183 for (var4 = 0; var4 < var3; ++var4)
184 {
185 this.dropItem(Item.goldNugget.itemID, 1);
186 }
187 }
188
189 /**
190 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
191 */
192 public boolean interact(EntityPlayer par1EntityPlayer)
193 {
194 return false;
195 }
196
197 protected void dropRareDrop(int par1)
198 {
199 this.dropItem(Item.ingotGold.itemID, 1);
200 }
201
202 /**
203 * Returns the item ID for the item the mob drops on death.
204 */
205 protected int getDropItemId()
206 {
207 return Item.rottenFlesh.itemID;
208 }
209
210 protected void func_82164_bB()
211 {
212 this.setCurrentItemOrArmor(0, new ItemStack(Item.swordGold));
213 }
214
215 /**
216 * Initialize this creature.
217 */
218 public void initCreature()
219 {
220 super.initCreature();
221 this.setVillager(false);
222 }
223
224 /**
225 * Returns the amount of damage a mob should deal.
226 */
227 public int getAttackStrength(Entity par1Entity)
228 {
229 ItemStack var2 = this.getHeldItem();
230 int var3 = 5;
231
232 if (var2 != null)
233 {
234 var3 += var2.getDamageVsEntity(this);
235 }
236
237 return var3;
238 }
239 }