Advertisement
Tenyar97

EntityRiot_Zombie

Jul 10th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.57 KB | None | 0 0
  1. package assets.betterdefense.entity;
  2.  
  3. import org.lwjgl.Sys;
  4.  
  5. import net.minecraft.enchantment.EnchantmentHelper;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.EntityLiving;
  8. import net.minecraft.entity.EnumCreatureAttribute;
  9. import net.minecraft.entity.SharedMonsterAttributes;
  10. import net.minecraft.entity.ai.EntityAIAttackOnCollide;
  11. import net.minecraft.entity.ai.EntityAIBreakDoor;
  12. import net.minecraft.entity.ai.EntityAIHurtByTarget;
  13. import net.minecraft.entity.ai.EntityAILookIdle;
  14. import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
  15. import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
  16. import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
  17. import net.minecraft.entity.ai.EntityAISwimming;
  18. import net.minecraft.entity.ai.EntityAIWander;
  19. import net.minecraft.entity.ai.EntityAIWatchClosest;
  20. import net.minecraft.entity.monster.EntityMob;
  21. import net.minecraft.entity.passive.EntityVillager;
  22. import net.minecraft.entity.player.EntityPlayer;
  23. import net.minecraft.item.Item;
  24. import net.minecraft.item.ItemStack;
  25. import net.minecraft.util.DamageSource;
  26. import net.minecraft.util.MathHelper;
  27. import net.minecraft.util.ResourceLocation;
  28. import net.minecraft.world.World;
  29. import net.minecraftforge.event.ForgeSubscribe;
  30. import net.minecraftforge.event.entity.living.LivingHurtEvent;
  31. import assets.betterdefense.common.BetterDefense;
  32. import assets.betterdefense.common.EntityAIBreakWood;
  33.  
  34. public class EntityRiot_Zombie extends EntityMob
  35. {
  36. boolean spawnZombie = true;
  37. //Time To Wait after spawning to spawn another
  38. int spawnCooldown = 1;
  39. //Counter. When 0 its okay to spawn another
  40. int spawnTimer = 5;
  41.  
  42. int stage;
  43.  
  44.  
  45. private float heightOffset = -0.5F;
  46.  
  47. /** ticks until heightOffset is randomized */
  48. private int heightOffsetUpdateTime;
  49. private int field_70846_g;
  50. private static final ResourceLocation textureLocation = new ResourceLocation("betterdefense:Riot_Zombie.png");
  51.  
  52.  
  53. public EntityRiot_Zombie(World par1World)
  54. {
  55. super(par1World);
  56. this.isImmuneToFire = true;
  57. this.canBreatheUnderwater();
  58. this.stepHeight = 1.2F;
  59. this.getNavigator().setBreakDoors(true);
  60. this.tasks.addTask(0, new EntityAISwimming(this));
  61. this.tasks.addTask(1, new EntityAIBreakDoor(this));
  62. this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1D, false));
  63. this.tasks.addTask(3, new EntityAIAttackOnCollide(this, EntityVillager.class, 1D, true));
  64. this.tasks.addTask(5, new EntityAIMoveThroughVillage(this, 1D, false));
  65. this.tasks.addTask(6, new EntityAIWander(this, 1D));
  66. this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
  67. this.tasks.addTask(7, new EntityAILookIdle(this));
  68. this.tasks.addTask(8, new EntityAIBreakWood(this));
  69. this.tasks.addTask(9, new EntityAIMoveTowardsRestriction(this, 1.0D));
  70. this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
  71. this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
  72.  
  73. }
  74.  
  75. protected void func_110147_ax()
  76. {
  77. super.func_110147_ax();
  78. // Max Health - default 20.0D - min 0.0D - max Double.MAX_VALUE
  79. this.func_110148_a(SharedMonsterAttributes.field_111267_a).func_111128_a(20.0D);
  80. // Follow Range - default 32.0D - min 0.0D - max 2048.0D
  81. this.func_110148_a(SharedMonsterAttributes.field_111265_b).func_111128_a(45.0D);
  82. // Knockback Resistance - default 0.0D - min 0.0D - max 1.0D
  83. this.func_110148_a(SharedMonsterAttributes.field_111266_c).func_111128_a(0.7D);
  84. // Movement Speed - default 0.699D - min 0.0D - max Double.MAX_VALUE
  85. this.func_110148_a(SharedMonsterAttributes.field_111263_d).func_111128_a(0.11000000417232513D);
  86. // Attack Damage - default 2.0D - min 0.0D - max Doubt.MAX_VALUE
  87. this.func_110148_a(SharedMonsterAttributes.field_111264_e).func_111128_a(2.0D);
  88. }
  89.  
  90. protected ResourceLocation func_110775_a(Entity entity) {
  91. return textureLocation;
  92. }
  93.  
  94. public boolean canBreatheUnderwater()
  95. {
  96. return true;
  97. }
  98. public int getTotalArmorValue()
  99. {
  100. int i = super.getTotalArmorValue() + 2;
  101.  
  102. if (i > 20)
  103. {
  104. i = 20;
  105. }
  106.  
  107. return i;
  108. }
  109.  
  110. public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
  111. {
  112. if (par1DamageSource.isFireDamage())
  113. {
  114. par2 = 0;
  115. }
  116.  
  117. if (super.attackEntityFrom(par1DamageSource, par2))
  118. {
  119. if (par1DamageSource.getEntity() != null)
  120. {
  121. Entity par1Entity = par1DamageSource.getEntity();
  122. int j = 0;
  123. if (par1Entity instanceof EntityLiving)
  124. {
  125. j += EnchantmentHelper.getKnockbackModifier((EntityLiving) par1Entity, this);
  126.  
  127. if (j > 0)
  128. {
  129. this.motionX /= 0.6D;
  130. this.motionZ /= 0.6D;
  131. this.addVelocity((double) (MathHelper.sin(par1Entity.rotationYaw * (float) Math.PI / 180.0F) * (float) j * 0.5F), -0.1D,
  132. (double) (-MathHelper.cos(par1Entity.rotationYaw * (float) Math.PI / 180.0F) * (float) j * 0.5F));
  133. }
  134. }
  135.  
  136. }
  137.  
  138. if (this.getHealth() < this.getMaxHealth() * 0.75 && stage == 0)
  139. {
  140. stage++;
  141. System.out.println("Stage advance!");
  142. } else if (stage == 1 && this.getHealth() < this.getMaxHealth() * 0.5)
  143. {
  144. stage++;
  145. spawnHelp();
  146. this.setDead();
  147. System.out.println("Spawned help, set dead!");
  148. } else if (stage == 2 && this.getHealth() < this.getMaxHealth() * 0.25)
  149. {
  150. stage++;
  151. }
  152. return true;
  153. }
  154.  
  155. return false;
  156. }
  157.  
  158. private void spawnHelp()
  159. {
  160. int numSpawned = 0;
  161.  
  162. if (trySpawnHelp((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
  163. {
  164. numSpawned++;
  165. }
  166. if (numSpawned >= 1)
  167. return;
  168.  
  169. if (trySpawnHelp((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
  170. {
  171. numSpawned++;
  172. }
  173. if (numSpawned >= 1)
  174. return;
  175.  
  176. if (trySpawnHelp((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
  177. {
  178. numSpawned++;
  179. }
  180. if (numSpawned >= 1)
  181. return;
  182.  
  183. if (trySpawnHelp((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
  184. {
  185. numSpawned++;
  186. }
  187. if (numSpawned >= 1)
  188. return;
  189.  
  190. if (trySpawnHelp((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
  191. {
  192. numSpawned++;
  193. }
  194. if (numSpawned >= 1)
  195. return;
  196.  
  197. if (trySpawnHelp((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
  198. {
  199. numSpawned++;
  200. }
  201. if (numSpawned >= 1)
  202. return;
  203.  
  204. if (trySpawnHelp((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
  205. {
  206. numSpawned++;
  207. }
  208. if (numSpawned >= 1)
  209. return;
  210.  
  211. if (trySpawnHelp((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1))
  212. {
  213. numSpawned++;
  214. }
  215. if (numSpawned >= 1)
  216. return;
  217.  
  218. }
  219.  
  220. public boolean trySpawnHelp(int x, int y, int z)
  221. {
  222. EntityZombie HELP = new EntityZombie(worldObj);
  223. zombie1.setPosition(x, y, z);
  224. {
  225. if (!worldObj.isRemote)
  226. worldObj.spawnEntityInWorld(HELP);
  227. HELP.spawnExplosionParticle();
  228. return true;
  229. }
  230. }
  231.  
  232. protected boolean isAIEnabled()
  233. {
  234. return true;
  235. }
  236.  
  237. protected String getDecay()
  238. {
  239. return "townaura";
  240. }
  241.  
  242.  
  243. public void onLivingUpdate()
  244. {
  245.  
  246. for (int i = 0; i < 2; ++i)
  247. {
  248. this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
  249. this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
  250. this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
  251. //this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
  252. //this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
  253. //this.worldObj.spawnParticle(getDecay(), this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D);
  254. }
  255. super.onLivingUpdate();
  256. }
  257.  
  258.  
  259. public boolean attackEntityAsMob(Entity par1Entity)
  260. {
  261. boolean flag = super.attackEntityAsMob(par1Entity);
  262.  
  263. if (flag && this.getHeldItem() == null && this.isBurning() && this.rand.nextFloat() < (float)this.worldObj.difficultySetting * 0.3F)
  264. {
  265. par1Entity.setFire(2 * this.worldObj.difficultySetting);
  266. }
  267.  
  268. return flag;
  269. }
  270.  
  271. /**
  272. * Returns the sound this mob makes while it's alive.
  273. */
  274. protected String getLivingSound()
  275. {
  276. return "mob.zombie.say";
  277. }
  278.  
  279. /**
  280. * Returns the sound this mob makes when it is hurt.
  281. */
  282. protected String getHurtSound()
  283. {
  284. return "mob.zombie.hurt";
  285. }
  286.  
  287. /**
  288. * Returns the sound this mob makes on death.
  289. */
  290. protected String getDeathSound()
  291. {
  292. return "mob.zombie.death";
  293. }
  294.  
  295. /**
  296. * Plays step sound at given x, y, z for the entity
  297. */
  298. protected void playStepSound(int par1, int par2, int par3, int par4)
  299. {
  300. this.playSound("mob.zombie.step", 0.15F, 1.0F);
  301. }
  302.  
  303. /**
  304. * Returns the item ID for the item the mob drops on death.
  305. */
  306. protected int getDropItemId()
  307. {
  308. return Item.rottenFlesh.itemID;
  309. }
  310.  
  311. /**
  312. * Get this Entity's EnumCreatureAttribute
  313. */
  314. public EnumCreatureAttribute getCreatureAttribute()
  315. {
  316. return EnumCreatureAttribute.UNDEAD;
  317. }
  318.  
  319. protected void dropRareDrop(int par1)
  320. {
  321. switch (this.rand.nextInt(3))
  322. {
  323. case 0:
  324. this.dropItem(Item.diamond.itemID, 1);
  325. break;
  326. case 1:
  327. this.dropItem(BetterDefense.HISword.itemID, 1);
  328. break;
  329. case 2:
  330. this.dropItem(Item.ingotIron.itemID, 1);
  331. }
  332. }
  333. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement