Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.14 KB | None | 0 0
  1. package ed.enderdeath.mod.entity;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. import cpw.mods.fml.relauncher.Side;
  7. import cpw.mods.fml.relauncher.SideOnly;
  8. import ed.enderdeath.mod.Food.Baie;
  9. import ed.enderdeath.mod.Item.Croquette;
  10. import ed.enderdeath.mod.common.enderdeath;
  11. import net.minecraft.block.Block;
  12. import net.minecraft.block.BlockColored;
  13. import net.minecraft.entity.Entity;
  14. import net.minecraft.entity.EntityAgeable;
  15. import net.minecraft.entity.EntityCreature;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.SharedMonsterAttributes;
  18. import net.minecraft.entity.ai.EntityAIAttackOnCollide;
  19. import net.minecraft.entity.ai.EntityAIFollowOwner;
  20. import net.minecraft.entity.ai.EntityAIHurtByTarget;
  21. import net.minecraft.entity.ai.EntityAILeapAtTarget;
  22. import net.minecraft.entity.ai.EntityAILookIdle;
  23. import net.minecraft.entity.ai.EntityAIMate;
  24. import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
  25. import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
  26. import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
  27. import net.minecraft.entity.ai.EntityAISwimming;
  28. import net.minecraft.entity.ai.EntityAITarget;
  29. import net.minecraft.entity.ai.EntityAITargetNonTamed;
  30. import net.minecraft.entity.ai.EntityAIWander;
  31. import net.minecraft.entity.ai.EntityAIWatchClosest;
  32. import net.minecraft.entity.boss.IBossDisplayData;
  33. import net.minecraft.entity.monster.EntityCreeper;
  34. import net.minecraft.entity.monster.EntityGhast;
  35. import net.minecraft.entity.monster.EntityIronGolem;
  36. import net.minecraft.entity.monster.EntityMob;
  37. import net.minecraft.entity.monster.EntitySnowman;
  38. import net.minecraft.entity.monster.EntityZombie;
  39. import net.minecraft.entity.monster.IMob;
  40. import net.minecraft.entity.passive.EntityAnimal;
  41. import net.minecraft.entity.passive.EntityHorse;
  42. import net.minecraft.entity.passive.EntitySheep;
  43. import net.minecraft.entity.passive.EntityTameable;
  44. import net.minecraft.entity.player.EntityPlayer;
  45. import net.minecraft.entity.projectile.EntityArrow;
  46. import net.minecraft.init.Items;
  47. import net.minecraft.item.ItemStack;
  48. import net.minecraft.nbt.NBTTagCompound;
  49. import net.minecraft.pathfinding.PathEntity;
  50. import net.minecraft.potion.Potion;
  51. import net.minecraft.potion.PotionEffect;
  52. import net.minecraft.util.AxisAlignedBB;
  53. import net.minecraft.util.DamageSource;
  54. import net.minecraft.util.MathHelper;
  55. import net.minecraft.util.ResourceLocation;
  56. import net.minecraft.world.World;
  57.  
  58. public class Familiar extends EntityTameable implements IMob, IBossDisplayData {
  59.  
  60. private float field_70926_e;
  61. private float field_70924_f;
  62. /** true is the wolf is wet else false */
  63. private boolean isShaking;
  64. private boolean field_70928_h;
  65. private float timeWolfIsShaking;
  66. private float prevTimeWolfIsShaking;
  67. public int lvl = 0;
  68. private static final String __OBFID = "CL_00001654";
  69.  
  70. private World world;
  71. private int x;
  72. private int y;
  73. private int z;
  74. private Random random;
  75. private int short1;
  76. private double d3;
  77. private double d4;
  78. private double d5;
  79. private RenderFamiliar RenderFamiliar;
  80.  
  81. private int k;
  82.  
  83. public Familiar(World p_i1696_1_) {
  84. super(p_i1696_1_);
  85. this.setSize(0.6F, 0.8F);
  86. this.getNavigator().setAvoidsWater(true);
  87. this.tasks.addTask(1, new EntityAISwimming(this));
  88. this.tasks.addTask(2, this.aiSit);
  89.  
  90. this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
  91. this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true));
  92. this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
  93. this.tasks.addTask(6, new EntityAIMate(this, 1.0D));
  94. this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
  95.  
  96. this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
  97. this.tasks.addTask(9, new EntityAILookIdle(this));
  98. this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
  99. this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
  100. this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true));
  101. this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false));
  102.  
  103. this.targetTasks.addTask(6, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 3, true));
  104.  
  105. }
  106.  
  107. protected void applyEntityAttributes() {
  108. super.applyEntityAttributes();
  109. this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);
  110.  
  111. if (this.isTamed()) {
  112. this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(5.0D);
  113. } else {
  114. this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
  115. }
  116. }
  117.  
  118. /**
  119. * Returns true if the newer Entity AI code should be run
  120. */
  121. public boolean isAIEnabled() {
  122. return true;
  123. }
  124.  
  125. /**
  126. * Sets the active target the Task system uses for tracking
  127. */
  128. public void setAttackTarget(EntityLivingBase p_70624_1_) {
  129. super.setAttackTarget(p_70624_1_);
  130.  
  131. if (p_70624_1_ == null) {
  132. this.setAngry(false);
  133. } else if (!this.isTamed()) {
  134. this.setAngry(true);
  135. } else if (this.lvl == 1) {
  136. this.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 210, 1));
  137.  
  138. }
  139.  
  140. else if (this.lvl == 3) {
  141. this.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 210, 2));
  142.  
  143. }
  144. }
  145.  
  146. /**
  147. * main AI tick function, replaces updateEntityActionState
  148. */
  149. protected void updateAITick() {
  150. this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth()));
  151. }
  152.  
  153. protected void entityInit() {
  154. super.entityInit();
  155. this.dataWatcher.addObject(18, new Float(this.getHealth()));
  156. this.dataWatcher.addObject(19, new Byte((byte) 0));
  157. this.dataWatcher.addObject(20, new Byte((byte) BlockColored.func_150032_b(1)));
  158. }
  159.  
  160. protected void func_145780_a(int p_145780_1_, int p_145780_2_, int p_145780_3_, Block p_145780_4_) {
  161. this.playSound("mob.wolf.step", 0.15F, 1.0F);
  162. }
  163.  
  164. /**
  165. * (abstract) Protected helper method to write subclass entity data to NBT.
  166. */
  167. public void writeEntityToNBT(NBTTagCompound p_70014_1_) {
  168. super.writeEntityToNBT(p_70014_1_);
  169. p_70014_1_.setBoolean("Angry", this.isAngry());
  170. p_70014_1_.setByte("CollarColor", (byte) this.getCollarColor());
  171. }
  172.  
  173. /**
  174. * (abstract) Protected helper method to read subclass entity data from NBT.
  175. */
  176. public void readEntityFromNBT(NBTTagCompound p_70037_1_) {
  177. super.readEntityFromNBT(p_70037_1_);
  178. this.setAngry(p_70037_1_.getBoolean("Angry"));
  179.  
  180. if (p_70037_1_.hasKey("CollarColor", 99)) {
  181. this.setCollarColor(p_70037_1_.getByte("CollarColor"));
  182. }
  183. }
  184.  
  185. /**
  186. * Returns the sound this mob makes while it's alive.
  187. */
  188. public void updateEntityActionState() {
  189.  
  190. List list = worldObj.getEntitiesWithinAABB(EntityCreature.class,
  191. AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1, posY + 1, posZ + 1));
  192. for (int i = 0; i < list.size(); i++) {
  193. Entity entity = (Entity) list.get(i);
  194. if (!list.isEmpty()) {
  195. if (!(entity instanceof EntityPlayer)) {
  196. this.setTarget(entity);
  197. }
  198. }
  199. }
  200. super.updateEntityActionState();
  201. }
  202.  
  203. /**
  204. * Returns the volume for the sounds this mob makes.
  205. */
  206. protected float getSoundVolume() {
  207. return 0.4F;
  208. }
  209.  
  210. /**
  211. * Called frequently so the entity can update its state every tick as
  212. * required. For example, zombies and skeletons use this to react to
  213. * sunlight and start to burn.
  214. */
  215. public void onLivingUpdate() {
  216. super.onLivingUpdate();
  217.  
  218. if (!this.worldObj.isRemote && this.isShaking && !this.field_70928_h && !this.hasPath() && this.onGround) {
  219. this.field_70928_h = true;
  220. this.timeWolfIsShaking = 0.0F;
  221. this.prevTimeWolfIsShaking = 0.0F;
  222. this.worldObj.setEntityState(this, (byte) 8);
  223. }
  224. for (k = 0; k < 2; ++k) {
  225. this.worldObj.spawnParticle("enchantmenttable",
  226. this.posX + (this.rand.nextDouble() - 0.5D) * (double) this.width,
  227. this.posY + this.rand.nextDouble() * (double) this.height - 0.25D,
  228. this.posZ + (this.rand.nextDouble() - 0.5D) * (double) this.width,
  229. (this.rand.nextDouble() - 0.5D) * 2.0D, -this.rand.nextDouble(),
  230. (this.rand.nextDouble() - 0.5D) * 2.0D);
  231. }
  232. }
  233.  
  234. public void onUpdate() {
  235. super.onUpdate();
  236. this.field_70924_f = this.field_70926_e;
  237.  
  238. if (this.func_70922_bv()) {
  239. this.field_70926_e += (1.0F - this.field_70926_e) * 0.4F;
  240. } else {
  241. this.field_70926_e += (0.0F - this.field_70926_e) * 0.4F;
  242. }
  243.  
  244. if (this.func_70922_bv()) {
  245. this.numTicksToChaseTarget = 10;
  246. }
  247.  
  248. if (this.isWet()) {
  249. this.isShaking = true;
  250. this.field_70928_h = false;
  251. this.timeWolfIsShaking = 0.0F;
  252. this.prevTimeWolfIsShaking = 0.0F;
  253. } else if ((this.isShaking || this.field_70928_h) && this.field_70928_h) {
  254. if (this.timeWolfIsShaking == 0.0F) {
  255. this.playSound("mob.wolf.shake", this.getSoundVolume(),
  256. (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
  257. }
  258.  
  259. this.prevTimeWolfIsShaking = this.timeWolfIsShaking;
  260. this.timeWolfIsShaking += 0.05F;
  261.  
  262. if (this.prevTimeWolfIsShaking >= 2.0F) {
  263. this.isShaking = false;
  264. this.field_70928_h = false;
  265. this.prevTimeWolfIsShaking = 0.0F;
  266. this.timeWolfIsShaking = 0.0F;
  267. }
  268.  
  269. if (this.timeWolfIsShaking > 0.4F) {
  270. float f = (float) this.boundingBox.minY;
  271. int i = (int) (MathHelper.sin((this.timeWolfIsShaking - 0.4F) * (float) Math.PI) * 7.0F);
  272.  
  273. for (int j = 0; j < i; ++j) {
  274. float f1 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F;
  275. float f2 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F;
  276. this.worldObj.spawnParticle("splash", this.posX + (double) f1, (double) (f + 0.8F),
  277. this.posZ + (double) f2, this.motionX, this.motionY, this.motionZ);
  278. }
  279. }
  280. }
  281. }
  282.  
  283. /**
  284. * The speed it takes to move the entityliving's rotationPitch through the
  285. * faceEntity method. This is only currently use in wolves.
  286. */
  287. public int getVerticalFaceSpeed() {
  288. return this.isSitting() ? 20 : super.getVerticalFaceSpeed();
  289. }
  290.  
  291. /**
  292. * Called when the entity is attacked.
  293. */
  294. public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) {
  295. if (this.isEntityInvulnerable()) {
  296. return false;
  297. } else {
  298. Entity entity = p_70097_1_.getEntity();
  299. this.aiSit.setSitting(false);
  300.  
  301. if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow)) {
  302. p_70097_2_ = (p_70097_2_ + 1.0F) / 2.0F;
  303. }
  304.  
  305. return super.attackEntityFrom(p_70097_1_, p_70097_2_);
  306. }
  307. }
  308.  
  309. public boolean attackEntityAsMob(Entity p_70652_1_) {
  310. int i = this.isTamed() ? 4 : 2;
  311. return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), (float) i);
  312. }
  313.  
  314. public void setTamed() {
  315.  
  316. if (this.lvl == 1) {
  317. this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(100.0D);
  318. this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);
  319.  
  320. }
  321. if (this.lvl == 2) {
  322. this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(103.0D);
  323. this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.54D);
  324. }
  325. if (this.lvl == 3) {
  326. this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(107.0D);
  327. this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.549D);
  328. } else if (this.lvl == 0) {
  329. this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
  330. }
  331.  
  332. }
  333.  
  334. /**
  335. * Called when a player interacts with a mob. e.g. gets milk from a cow,
  336. * gets into the saddle on a pig.
  337. */
  338. private Croquette croquette;
  339. private ItemStack stack;
  340.  
  341. public boolean interact(EntityPlayer p_70085_1_) {
  342. ItemStack itemstack = p_70085_1_.inventory.getCurrentItem();
  343.  
  344. if (this.lvl > 0) {
  345. if (itemstack != null) {
  346. if (itemstack.getItem() instanceof Baie) {
  347. Baie itemfood = (Baie) itemstack.getItem();
  348.  
  349. if (itemfood.isFamiliarFavoriteMeat() && this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) {
  350. if (!p_70085_1_.capabilities.isCreativeMode) {
  351. --itemstack.stackSize;
  352. }
  353.  
  354. this.heal((float) itemfood.func_150905_g(itemstack));
  355.  
  356. if (itemstack.stackSize <= 0) {
  357. p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem,
  358. (ItemStack) null);
  359. }
  360.  
  361. return true;
  362. }
  363. }
  364. }
  365. if (this.func_152114_e(p_70085_1_) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack)) {
  366. this.aiSit.setSitting(!this.isSitting());
  367. this.isJumping = false;
  368. this.setPathToEntity((PathEntity) null);
  369. this.setTarget((Entity) null);
  370. this.setAttackTarget((EntityLivingBase) null);
  371. }
  372.  
  373. }
  374. if (itemstack != null && itemstack.getItem() instanceof Croquette) {
  375.  
  376. if (!p_70085_1_.capabilities.isCreativeMode) {
  377. --itemstack.stackSize;
  378. }
  379.  
  380. if (itemstack.stackSize <= 0) {
  381. p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack) null);
  382. }
  383.  
  384. if (!this.worldObj.isRemote) {
  385. if (this.rand.nextInt(3) == 0) {
  386.  
  387. this.setPathToEntity((PathEntity) null);
  388. this.setAttackTarget((EntityLivingBase) null);
  389. this.aiSit.setSitting(true);
  390. if (this.lvl == 10) {
  391. System.out.println("lvl 10!!!");
  392.  
  393. }
  394. this.lvl++;
  395. System.out.println(lvl);
  396. this.func_152115_b(p_70085_1_.getUniqueID().toString());
  397. this.playTameEffect(true);
  398. this.worldObj.setEntityState(this, (byte) 7);
  399. this.setTamed();
  400.  
  401. } else {
  402. this.playTameEffect(false);
  403. this.worldObj.setEntityState(this, (byte) 6);
  404. }
  405. if (itemstack != null && itemstack.getItem() == enderdeath.SkinFire && this.isTamed()) {
  406. this.Chanchelog();
  407. this.onParticuleFire();
  408. }
  409.  
  410. }
  411. return true;
  412. }
  413.  
  414. return super.interact(p_70085_1_);
  415. }
  416.  
  417. private ResourceLocation Chanchelog() {
  418. return RenderFamiliar.textureSkin;
  419.  
  420. }
  421.  
  422. public void onParticuleFire() {
  423. for (k = 0; k < 2; ++k) {
  424. this.worldObj.spawnParticle("fire", this.posX + (this.rand.nextDouble() - 0.5D) * (double) this.width,
  425. this.posY + this.rand.nextDouble() * (double) this.height - 0.25D,
  426. this.posZ + (this.rand.nextDouble() - 0.5D) * (double) this.width,
  427. (this.rand.nextDouble() - 0.5D) * 2.0D, -this.rand.nextDouble(),
  428. (this.rand.nextDouble() - 0.5D) * 2.0D);
  429. }
  430. }
  431.  
  432. @SideOnly(Side.CLIENT)
  433. public float getTailRotation() {
  434. return this.isAngry() ? 1.5393804F
  435. : (this.isTamed()
  436. ? (0.55F - (20.0F - this.dataWatcher.getWatchableObjectFloat(18)) * 0.02F) * (float) Math.PI
  437. : ((float) Math.PI / 5F));
  438. }
  439.  
  440. public boolean isBreedingItem(ItemStack p_70877_1_) {
  441. return p_70877_1_ == null ? false
  442. : (!(p_70877_1_.getItem() instanceof Baie) ? false
  443. : ((Baie) p_70877_1_.getItem()).isFamiliarFavoriteMeat());
  444. }
  445.  
  446. public boolean isAngry() {
  447. return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0;
  448. }
  449.  
  450. public void setAngry(boolean p_70916_1_) {
  451. byte b0 = this.dataWatcher.getWatchableObjectByte(16);
  452.  
  453. if (p_70916_1_) {
  454. this.dataWatcher.updateObject(16, Byte.valueOf((byte) (b0 | 2)));
  455. } else {
  456. this.dataWatcher.updateObject(16, Byte.valueOf((byte) (b0 & -3)));
  457. }
  458. }
  459.  
  460. public int getCollarColor() {
  461. return this.dataWatcher.getWatchableObjectByte(20) & 15;
  462. }
  463.  
  464. public void setCollarColor(int p_82185_1_) {
  465. this.dataWatcher.updateObject(20, Byte.valueOf((byte) (p_82185_1_ & 15)));
  466. }
  467.  
  468. public Familiar createChild(EntityAgeable p_90011_1_) {
  469. Familiar entitywolf = new Familiar(this.worldObj);
  470. String s = this.func_152113_b();
  471.  
  472. if (s != null && s.trim().length() > 0) {
  473. entitywolf.func_152115_b(s);
  474. if (this.lvl >= 1)
  475. ;
  476. }
  477.  
  478. return entitywolf;
  479. }
  480.  
  481. public void func_70918_i(boolean p_70918_1_) {
  482. if (p_70918_1_) {
  483. this.dataWatcher.updateObject(19, Byte.valueOf((byte) 1));
  484. } else {
  485. this.dataWatcher.updateObject(19, Byte.valueOf((byte) 0));
  486. }
  487. }
  488.  
  489. /**
  490. * Returns true if the mob is currently able to mate with the specified mob.
  491. */
  492. public boolean canMateWith(EntityAnimal p_70878_1_) {
  493. if (p_70878_1_ == this) {
  494. return false;
  495. } else if (!this.isTamed()) {
  496. return false;
  497. } else if (!(p_70878_1_ instanceof Familiar)) {
  498. return false;
  499. } else {
  500. Familiar familiar = (Familiar) p_70878_1_;
  501. return !familiar.isTamed() ? false
  502. : (familiar.isSitting() ? false : this.isInLove() && familiar.isInLove());
  503. }
  504. }
  505.  
  506. public boolean func_70922_bv() {
  507. return this.dataWatcher.getWatchableObjectByte(19) == 1;
  508. }
  509.  
  510. /**
  511. * Determines if an entity can be despawned, used on idle far away entities
  512. */
  513. protected boolean canDespawn() {
  514. return !this.isTamed() && this.ticksExisted > 2400;
  515. }
  516.  
  517. public boolean func_142018_a(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_) {
  518. if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast)) {
  519. if (p_142018_1_ instanceof Familiar) {
  520. Familiar entitywolf = (Familiar) p_142018_1_;
  521.  
  522. if (entitywolf.isTamed() && entitywolf.getOwner() == p_142018_2_) {
  523. return false;
  524. }
  525. }
  526.  
  527. return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer
  528. && !((EntityPlayer) p_142018_2_).canAttackPlayer((EntityPlayer) p_142018_1_) ? false
  529. : !(p_142018_1_ instanceof EntityHorse) || !((EntityHorse) p_142018_1_).isTame();
  530. } else {
  531. return false;
  532. }
  533. }
  534. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement