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