/moCreatures/server/.metadata/.plugins/org.eclipse.core.resources/.history/8c/b07facde0a8000101cbdd28cb20c0c30

https://code.google.com/p/minecraft-smp-mocreatures/ · #! · 449 lines · 416 code · 33 blank · 0 comment · 0 complexity · 748d4d081df21300830d3e0865b35f9d MD5 · raw file

  1. package net.minecraft.src;
  2. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  3. // Jad home page: http://www.kpdus.com/jad.html
  4. // Decompiler options: packimports(3) braces deadcode
  5. import java.util.List;
  6. import net.minecraft.src.AxisAlignedBB;
  7. import net.minecraft.src.Block;
  8. import net.minecraft.src.Entity;
  9. import net.minecraft.src.EntityAnimal;
  10. import net.minecraft.src.EntityItem;
  11. import net.minecraft.src.EntityLiving;
  12. import net.minecraft.src.Item;
  13. import net.minecraft.src.Material;
  14. import net.minecraft.src.MathHelper;
  15. import net.minecraft.src.NBTTagCompound;
  16. import net.minecraft.src.World;
  17. import net.minecraft.src.mod_MoCreatures;
  18. public class EntityBird extends EntityAnimal
  19. {
  20. private boolean hasReproduced;
  21. public int typeInt;
  22. public boolean typeChosen;
  23. private boolean fleeing;
  24. public float wingB;
  25. public float wingC;
  26. public float wingD;
  27. public float wingE;
  28. public float wingH;
  29. public boolean tamed;
  30. public static int counterEntity;
  31. public EntityBird(World world)
  32. {
  33. super(world);
  34. texture = "/mob/birdblue.png";
  35. setSize(0.5F, 0.3F);
  36. health = 2;
  37. isCollidedVertically = true;
  38. wingB = 0.0F;
  39. wingC = 0.0F;
  40. wingH = 1.0F;
  41. fleeing = false;
  42. tamed = false;
  43. typeInt = 0;
  44. typeChosen = false;
  45. hasReproduced = false;
  46. }
  47. protected void fall(float f)
  48. {
  49. }
  50. public int getMaxSpawnedInChunk()
  51. {
  52. return 6;
  53. }
  54. public void onLivingUpdate()
  55. {
  56. super.onLivingUpdate();
  57. wingE = wingB;
  58. wingD = wingC;
  59. wingC = (float)(wingC + (onGround ? -1 : 4) * 0.3D);
  60. if(wingC < 0.0F)
  61. wingC = 0.0F;
  62. if(wingC > 1.0F)
  63. wingC = 1.0F;
  64. if(!onGround && wingH < 1.0F)
  65. wingH = 1.0F;
  66. wingH = (float)(wingH * 0.9D);
  67. if(!onGround && motionY < 0.0D)
  68. motionY *= 0.8D;
  69. wingB += wingH * 2.0F;
  70. EntityLiving entityliving = getClosestEntityLiving(this, 4.0D);
  71. if(entityliving != null && !tamed && canEntityBeSeen(entityliving))
  72. fleeing = true;
  73. if(rand.nextInt(300) == 0)
  74. fleeing = true;
  75. if(fleeing)
  76. {
  77. if(flyToNextTree())
  78. fleeing = false;
  79. int ai[] = returnNearestMaterialCoord(this, Material.leaves, Double.valueOf(16.0D));
  80. if(ai[0] == -1)
  81. {
  82. for(int i = 0; i < 2; i++)
  83. wingFlap();
  84. fleeing = false;
  85. }
  86. if(rand.nextInt(50) == 0)
  87. fleeing = false;
  88. }
  89. if(!fleeing)
  90. {
  91. EntityItem entityitem = getClosestSeeds(this, 12.0D);
  92. if(entityitem != null)
  93. {
  94. flyToNextEntity(entityitem);
  95. EntityItem entityitem1 = getClosestSeeds(this, 1.0D);
  96. if(rand.nextInt(50) == 0 && entityitem1 != null)
  97. {
  98. entityitem1.setEntityDead();
  99. tamed = true;
  100. }
  101. }
  102. }
  103. }
  104. protected void updatePlayerActionState()
  105. {
  106. if(onGround && rand.nextInt(10) == 0 && (motionX > 0.05D || motionZ > 0.05D || motionX < -0.05D || motionZ < -0.05D))
  107. motionY = 0.25D;
  108. if(!fleeing)
  109. super.updatePlayerActionState();
  110. }
  111. public void setEntityDead()
  112. {
  113. if(!tamed || health <= 0)
  114. {
  115. counterEntity--;
  116. super.setEntityDead();
  117. }
  118. }
  119. @SuppressWarnings("unchecked")
  120. private EntityItem getClosestSeeds(Entity entity, double d)
  121. {
  122. double d1 = -1.0D;
  123. EntityItem entityitem = null;
  124. List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(d, d, d));
  125. for(int i = 0; i < list.size(); i++)
  126. {
  127. Entity entity1 = list.get(i);
  128. if(!(entity1 instanceof EntityItem))
  129. continue;
  130. EntityItem entityitem1 = (EntityItem)entity1;
  131. if(entityitem1.item.itemID != Item.seeds.shiftedIndex)
  132. continue;
  133. double d2 = entityitem1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
  134. if((d < 0.0D || d2 < d * d) && (d1 == -1.0D || d2 < d1))
  135. {
  136. d1 = d2;
  137. entityitem = entityitem1;
  138. }
  139. }
  140. return entityitem;
  141. }
  142. @SuppressWarnings("unchecked")
  143. private EntityLiving getClosestEntityLiving(Entity entity, double d)
  144. {
  145. double d1 = -1.0D;
  146. EntityLiving entityliving = null;
  147. List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(d, d, d));
  148. for(int i = 0; i < list.size(); i++)
  149. {
  150. Entity entity1 = list.get(i);
  151. if(!(entity1 instanceof EntityLiving) || (entity1 instanceof EntityBird))
  152. continue;
  153. double d2 = entity1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
  154. if((d < 0.0D || d2 < d * d) && (d1 == -1.0D || d2 < d1) && ((EntityLiving)entity1).canEntityBeSeen(entity))
  155. {
  156. d1 = d2;
  157. entityliving = (EntityLiving)entity1;
  158. }
  159. }
  160. return entityliving;
  161. }
  162. private boolean flyToNextEntity(Entity entity)
  163. {
  164. if(entity != null)
  165. {
  166. int i = MathHelper.floor_double(entity.posX);
  167. int j = MathHelper.floor_double(entity.posY);
  168. int k = MathHelper.floor_double(entity.posZ);
  169. faceTreeTop(i, j, k, 30.0F);
  170. if(MathHelper.floor_double(posY) < j)
  171. {
  172. motionY += 0.15D;
  173. }
  174. if(posX < entity.posX)
  175. {
  176. double d = entity.posX - posX;
  177. if(d > 0.5D)
  178. motionX += 0.05D;
  179. } else
  180. {
  181. double d1 = posX - entity.posX;
  182. if(d1 > 0.5D)
  183. motionX -= 0.05D;
  184. }
  185. if(posZ < entity.posZ)
  186. {
  187. double d2 = entity.posZ - posZ;
  188. if(d2 > 0.5D)
  189. motionZ += 0.05D;
  190. } else
  191. {
  192. double d3 = posZ - entity.posZ;
  193. if(d3 > 0.5D)
  194. motionZ -= 0.05D;
  195. }
  196. return true;
  197. }
  198. return false;
  199. }
  200. private void wingFlap()
  201. {
  202. motionY += 0.05D;
  203. if(rand.nextInt(30) == 0)
  204. motionX += 0.2D;
  205. if(rand.nextInt(30) == 0)
  206. motionX -= 0.2D;
  207. if(rand.nextInt(30) == 0)
  208. motionZ += 0.2D;
  209. if(rand.nextInt(30) == 0)
  210. motionZ -= 0.2D;
  211. }
  212. private boolean flyToNextTree()
  213. {
  214. int ai[] = returnNearestMaterialCoord(this, Material.leaves, Double.valueOf(20.0D));
  215. int ai1[] = findTreeTop(ai[0], ai[1], ai[2]);
  216. if(ai1[1] != 0)
  217. {
  218. int i = ai1[0];
  219. int j = ai1[1];
  220. int k = ai1[2];
  221. faceTreeTop(i, j, k, 30.0F);
  222. if(j - MathHelper.floor_double(posY) > 2)
  223. motionY += 0.15D;
  224. int l = 0;
  225. int i1 = 0;
  226. if(posX < i)
  227. {
  228. l = i - MathHelper.floor_double(posX);
  229. motionX += 0.05D;
  230. } else
  231. {
  232. l = MathHelper.floor_double(posX) - i;
  233. motionX -= 0.05D;
  234. }
  235. if(posZ < k)
  236. {
  237. i1 = k - MathHelper.floor_double(posZ);
  238. motionZ += 0.05D;
  239. } else
  240. {
  241. i1 = MathHelper.floor_double(posX) - k;
  242. motionZ -= 0.05D;
  243. }
  244. double d = l + i1;
  245. if(d < 3.0D)
  246. return true;
  247. }
  248. return false;
  249. }
  250. public void setType(int i)
  251. {
  252. typeInt = i;
  253. typeChosen = false;
  254. chooseType();
  255. }
  256. public void chooseType()
  257. {
  258. if(typeInt == 0)
  259. {
  260. int i = rand.nextInt(100);
  261. if(i <= 15)
  262. typeInt = 1;
  263. else if(i <= 30)
  264. typeInt = 2;
  265. else if(i <= 45)
  266. typeInt = 3;
  267. else if(i <= 60)
  268. typeInt = 4;
  269. else if(i <= 75)
  270. typeInt = 5;
  271. else if(i <= 90)
  272. typeInt = 6;
  273. else
  274. typeInt = 2;
  275. }
  276. if(!typeChosen)
  277. texture = new StringBuilder("/mob/").append(getLivingSound()).append(".png").toString();
  278. typeChosen = true;
  279. }
  280. public void faceTreeTop(int i, int j, int k, float f)
  281. {
  282. double d = i - posX;
  283. double d1 = k - posZ;
  284. double d2 = j - posY;
  285. double d3 = MathHelper.sqrt_double(d * d + d1 * d1);
  286. float f1 = (float)((Math.atan2(d1, d) * 180.0D) / Math.PI) - 90.0F;
  287. float f2 = (float)((Math.atan2(d2, d3) * 180.0D) / Math.PI);
  288. rotationPitch = -updateRotation(rotationPitch, f2, f);
  289. rotationYaw = updateRotation(rotationYaw, f1, f);
  290. }
  291. private float updateRotation(float f, float f1, float f2)
  292. {
  293. float f3 = f1;
  294. for(f3 = f1 - f; f3 < -180.0F; f3 += 360.0F);
  295. while (f3 >= 180.0F)
  296. f3 -= 360.0F;
  297. if(f3 > f2)
  298. f3 = f2;
  299. if(f3 < -f2)
  300. f3 = -f2;
  301. return f + f3;
  302. }
  303. private int[] findTreeTop(int i, int j, int k)
  304. {
  305. int l = i - 5;
  306. int i1 = k - 5;
  307. int j1 = i + 5;
  308. int k1 = j + 7;
  309. int l1 = k + 5;
  310. for(int i2 = l; i2 < j1; i2++)
  311. {
  312. for(int j2 = i1; j2 < l1; j2++)
  313. {
  314. int k2 = worldObj.getBlockId(i2, j, j2);
  315. if(k2 == 0 || Block.blocksList[k2].blockMaterial != Material.wood)
  316. continue;
  317. int l2 = j;
  318. while (l2 < k1)
  319. {
  320. int i3 = worldObj.getBlockId(i2, l2, j2);
  321. if(i3 == 0)
  322. return (new int[] { i2, l2 + 2, j2 });
  323. l2++;
  324. }
  325. }
  326. }
  327. return (new int[] { 0, 0, 0 });
  328. }
  329. public int[] returnNearestMaterialCoord(Entity entity, Material material, Double double1)
  330. {
  331. AxisAlignedBB axisalignedbb = entity.boundingBox.expand(double1.doubleValue(), double1.doubleValue(), double1.doubleValue());
  332. int i = MathHelper.floor_double(axisalignedbb.minX);
  333. int j = MathHelper.floor_double(axisalignedbb.maxX + 1.0D);
  334. int k = MathHelper.floor_double(axisalignedbb.minY);
  335. int l = MathHelper.floor_double(axisalignedbb.maxY + 1.0D);
  336. int i1 = MathHelper.floor_double(axisalignedbb.minZ);
  337. int j1 = MathHelper.floor_double(axisalignedbb.maxZ + 1.0D);
  338. for(int k1 = i; k1 < j; k1++)
  339. {
  340. for(int l1 = k; l1 < l; l1++)
  341. {
  342. for(int i2 = i1; i2 < j1; i2++)
  343. {
  344. int j2 = worldObj.getBlockId(k1, l1, i2);
  345. if(j2 != 0 && Block.blocksList[j2].blockMaterial == material)
  346. return (new int[] { k1, l1, i2 });
  347. }
  348. }
  349. }
  350. return (new int[] { -1, 0, 0 });
  351. }
  352. protected int getDropItemId()
  353. {
  354. if(rand.nextInt(2) == 0)
  355. return Item.feather.shiftedIndex;
  356. return Item.seeds.shiftedIndex;
  357. }
  358. public void writeEntityToNBT(NBTTagCompound nbttagcompound)
  359. {
  360. super.writeEntityToNBT(nbttagcompound);
  361. nbttagcompound.setInteger("TypeInt", typeInt);
  362. nbttagcompound.setBoolean("HasReproduced", hasReproduced);
  363. nbttagcompound.setBoolean("Tamed", tamed);
  364. nbttagcompound.setInteger("CounterEntity", counterEntity);
  365. }
  366. public void readEntityFromNBT(NBTTagCompound nbttagcompound)
  367. {
  368. super.readEntityFromNBT(nbttagcompound);
  369. hasReproduced = nbttagcompound.getBoolean("HasReproduced");
  370. tamed = nbttagcompound.getBoolean("Tamed");
  371. typeInt = nbttagcompound.getInteger("TypeInt");
  372. counterEntity = nbttagcompound.getInteger("CounterEntity");
  373. }
  374. protected String getLivingSound()
  375. {
  376. switch (typeInt)
  377. {
  378. case 1:
  379. return "birdwhite";
  380. case 2:
  381. return "birdblack";
  382. case 3:
  383. return "birdgreen";
  384. case 4:
  385. return "birdblue";
  386. case 5:
  387. return "birdyellow";
  388. default:
  389. case 6:
  390. return "birdred";
  391. }
  392. }
  393. protected String getHurtSound()
  394. {
  395. return "birdhurt";
  396. }
  397. protected String getDeathSound()
  398. {
  399. return "birddying";
  400. }
  401. public boolean getCanSpawnHere()
  402. {
  403. int i = MathHelper.floor_double(posX);
  404. int j = MathHelper.floor_double(boundingBox.minY);
  405. int k = MathHelper.floor_double(posZ);
  406. worldObj.getBlockId(i, j - 1, k);
  407. if(super.getCanSpawnHere())
  408. {
  409. if(counterEntity >= mod_MoCreatures.maxBirds)
  410. return false;
  411. counterEntity++;
  412. return true;
  413. }
  414. return false;
  415. }
  416. }