Advertisement
Guest User

Entity

a guest
Aug 26th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.93 KB | None | 0 0
  1. package infinicraft.entity.BeardedDragon;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.entity.Entity;
  5. import net.minecraft.entity.EntityAgeable;
  6. import net.minecraft.entity.IEntityLivingData;
  7. import net.minecraft.entity.SharedMonsterAttributes;
  8. import net.minecraft.entity.ai.EntityAIAvoidEntity;
  9. import net.minecraft.entity.ai.EntityAIFollowOwner;
  10. import net.minecraft.entity.ai.EntityAILeapAtTarget;
  11. import net.minecraft.entity.ai.EntityAIMate;
  12. import net.minecraft.entity.ai.EntityAIOcelotAttack;
  13. import net.minecraft.entity.ai.EntityAISwimming;
  14. import net.minecraft.entity.ai.EntityAITargetNonTamed;
  15. import net.minecraft.entity.ai.EntityAITempt;
  16. import net.minecraft.entity.ai.EntityAIWander;
  17. import net.minecraft.entity.ai.EntityAIWatchClosest;
  18. import net.minecraft.entity.passive.EntityAnimal;
  19. import net.minecraft.entity.passive.EntityChicken;
  20. import net.minecraft.entity.passive.EntityOcelot;
  21. import net.minecraft.entity.passive.EntityTameable;
  22. import net.minecraft.entity.player.EntityPlayer;
  23. import net.minecraft.init.Blocks;
  24. import net.minecraft.init.Items;
  25. import net.minecraft.item.Item;
  26. import net.minecraft.item.ItemStack;
  27. import net.minecraft.nbt.NBTTagCompound;
  28. import net.minecraft.util.DamageSource;
  29. import net.minecraft.util.MathHelper;
  30. import net.minecraft.util.StatCollector;
  31. import net.minecraft.world.World;
  32.  
  33. public class EntityBeardedDragon extends EntityTameable
  34. {
  35. /**
  36. * The tempt AI task for this mob, used to prevent taming while it is fleeing.
  37. */
  38. private EntityAITempt aiTempt;
  39.  
  40. public EntityBeardedDragon(World par1World)
  41. {
  42. super(par1World);
  43. this.setSize(0.6F, 0.8F);
  44. this.getNavigator().setAvoidsWater(true);
  45. this.tasks.addTask(1, new EntityAISwimming(this));
  46. this.tasks.addTask(3, this.aiTempt = new EntityAITempt(this, 0.6D, Items.wheat_seeds, true));
  47. this.tasks.addTask(4, new EntityAIAvoidEntity(this, EntityPlayer.class, 16.0F, 0.8D, 1.33D));
  48. this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 5.0F));
  49. // this.tasks.addTask(6, new EntityAIOcelotSit(this, 1.33D));
  50. this.tasks.addTask(7, new EntityAILeapAtTarget(this, 0.3F));
  51. this.tasks.addTask(8, new EntityAIOcelotAttack(this));
  52. this.tasks.addTask(9, new EntityAIMate(this, 0.8D));
  53. this.tasks.addTask(10, new EntityAIWander(this, 0.8D));
  54. this.tasks.addTask(11, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F));
  55. this.targetTasks.addTask(1, new EntityAITargetNonTamed(this, EntityChicken.class, 750, false));
  56. }
  57.  
  58. protected void entityInit()
  59. {
  60. super.entityInit();
  61. this.dataWatcher.addObject(18, Byte.valueOf((byte)0));
  62. }
  63.  
  64. /**
  65. * main AI tick function, replaces updateEntityActionState
  66. */
  67. public void updateAITick()
  68. {
  69. if (this.getMoveHelper().isUpdating())
  70. {
  71. double d0 = this.getMoveHelper().getSpeed();
  72.  
  73. if (d0 == 0.6D)
  74. {
  75. this.setSneaking(true);
  76. this.setSprinting(false);
  77. }
  78. else if (d0 == 1.33D)
  79. {
  80. this.setSneaking(false);
  81. this.setSprinting(true);
  82. }
  83. else
  84. {
  85. this.setSneaking(false);
  86. this.setSprinting(false);
  87. }
  88. }
  89. else
  90. {
  91. this.setSneaking(false);
  92. this.setSprinting(false);
  93. }
  94. }
  95.  
  96. /**
  97. * Determines if an entity can be despawned, used on idle far away entities
  98. */
  99. protected boolean canDespawn()
  100. {
  101. return !this.isTamed() && this.ticksExisted > 2400;
  102. }
  103.  
  104. /**
  105. * Returns true if the newer Entity AI code should be run
  106. */
  107. public boolean isAIEnabled()
  108. {
  109. return true;
  110. }
  111.  
  112. protected void applyEntityAttributes()
  113. {
  114. super.applyEntityAttributes();
  115. this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(5.0D);
  116. this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);
  117. }
  118.  
  119. /**
  120. * Called when the mob is falling. Calculates and applies fall damage.
  121. */
  122. protected void fall(float par1) {}
  123.  
  124. /**
  125. * (abstract) Protected helper method to write subclass entity data to NBT.
  126. */
  127. public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
  128. {
  129. super.writeEntityToNBT(par1NBTTagCompound);
  130. par1NBTTagCompound.setInteger("CatType", this.getTameSkin());
  131. }
  132.  
  133. /**
  134. * (abstract) Protected helper method to read subclass entity data from NBT.
  135. */
  136. public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
  137. {
  138. super.readEntityFromNBT(par1NBTTagCompound);
  139. this.setTameSkin(par1NBTTagCompound.getInteger("CatType"));
  140. }
  141.  
  142. /**
  143. * Returns the sound this mob makes while it's alive.
  144. */
  145. protected String getLivingSound()
  146. {
  147. return this.isTamed() ? (this.isInLove() ? "mob.cow.step" : (this.rand.nextInt(4) == 0 ? "mob.cow.step" : "mob.cow.step")) : "";
  148. }
  149.  
  150. /**
  151. * Returns the sound this mob makes when it is hurt.
  152. */
  153. protected String getHurtSound()
  154. {
  155. return "mob.cow.step";
  156. }
  157.  
  158. /**
  159. * Returns the sound this mob makes on death.
  160. */
  161. protected String getDeathSound()
  162. {
  163. return "mob.cow.step";
  164. }
  165.  
  166. /**
  167. * Returns the volume for the sounds this mob makes.
  168. */
  169. protected float getSoundVolume()
  170. {
  171. return 0.4F;
  172. }
  173.  
  174. /**
  175. * Returns the item ID for the item the mob drops on death.
  176. */
  177. protected Item getDropItemId()
  178. {
  179. return Items.leather;
  180. }
  181.  
  182. public boolean attackEntityAsMob(Entity par1Entity)
  183. {
  184. return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), 3.0F);
  185. }
  186.  
  187. /**
  188. * Called when the entity is attacked.
  189. */
  190. public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
  191. {
  192. if (this.isEntityInvulnerable())
  193. {
  194. return false;
  195. }
  196. else
  197. {
  198. this.aiSit.setSitting(false);
  199. return super.attackEntityFrom(par1DamageSource, par2);
  200. }
  201. }
  202.  
  203. /**
  204. * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
  205. * par2 - Level of Looting used to kill this mob.
  206. */
  207. protected void dropFewItems(boolean par1, int par2) {}
  208.  
  209. /**
  210. * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
  211. */
  212. public boolean interact(EntityPlayer p_70085_1_)
  213. {
  214. ItemStack itemstack = p_70085_1_.inventory.getCurrentItem();
  215.  
  216. if (this.isTamed())
  217. {
  218. if (this.func_152114_e(p_70085_1_) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack))
  219. {
  220. this.aiSit.setSitting(!this.isSitting());
  221. }
  222. }
  223. else if (this.aiTempt.isRunning() && itemstack != null && itemstack.getItem() == Items.wheat_seeds && p_70085_1_.getDistanceSqToEntity(this) < 9.0D)
  224. {
  225. if (!p_70085_1_.capabilities.isCreativeMode)
  226. {
  227. --itemstack.stackSize;
  228. }
  229.  
  230. if (itemstack.stackSize <= 0)
  231. {
  232. p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
  233. }
  234.  
  235. if (!this.worldObj.isRemote)
  236. {
  237. if (this.rand.nextInt(3) == 0)
  238. {
  239. this.setTamed(true);
  240. this.setTameSkin(1 + this.worldObj.rand.nextInt(3));
  241. this.func_152115_b(p_70085_1_.getUniqueID().toString());
  242. this.playTameEffect(true);
  243. this.aiSit.setSitting(true);
  244. this.worldObj.setEntityState(this, (byte)7);
  245. }
  246. else
  247. {
  248. this.playTameEffect(false);
  249. this.worldObj.setEntityState(this, (byte)6);
  250. }
  251. }
  252.  
  253. return true;
  254. }
  255.  
  256. return super.interact(p_70085_1_);
  257. }
  258.  
  259. public EntityBeardedDragon createChild(EntityAgeable p_90011_1_)
  260. {
  261. EntityBeardedDragon entityocelot = new EntityBeardedDragon(this.worldObj);
  262.  
  263. if (this.isTamed())
  264. {
  265. entityocelot.func_152115_b(this.func_152113_b());
  266. entityocelot.setTamed(true);
  267. entityocelot.setTameSkin(this.getTameSkin());
  268. }
  269.  
  270. return entityocelot;
  271. }
  272.  
  273. /**
  274. * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
  275. * the animal type)
  276. */
  277. public boolean isBreedingItem(ItemStack p_70877_1_)
  278. {
  279. return p_70877_1_ != null && p_70877_1_.getItem() == Items.wheat_seeds;
  280. }
  281.  
  282. /**
  283. * Returns true if the mob is currently able to mate with the specified mob.
  284. */
  285. public boolean canMateWith(EntityAnimal p_70878_1_)
  286. {
  287. if (p_70878_1_ == this)
  288. {
  289. return false;
  290. }
  291. else if (!this.isTamed())
  292. {
  293. return false;
  294. }
  295. else if (!(p_70878_1_ instanceof EntityBeardedDragon))
  296. {
  297. return false;
  298. }
  299. else
  300. {
  301. EntityBeardedDragon entityocelot = (EntityBeardedDragon)p_70878_1_;
  302. return !entityocelot.isTamed() ? false : this.isInLove() && entityocelot.isInLove();
  303. }
  304. }
  305.  
  306. public int getTameSkin()
  307. {
  308. return this.dataWatcher.getWatchableObjectByte(18);
  309. }
  310.  
  311. public void setTameSkin(int p_70912_1_)
  312. {
  313. this.dataWatcher.updateObject(18, Byte.valueOf((byte)p_70912_1_));
  314. }
  315.  
  316. /**
  317. * Checks if the entity's current position is a valid location to spawn this entity.
  318. */
  319. public boolean getCanSpawnHere()
  320. {
  321. if (this.worldObj.rand.nextInt(3) == 0)
  322. {
  323. return false;
  324. }
  325. else
  326. {
  327. if (this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox))
  328. {
  329. int i = MathHelper.floor_double(this.posX);
  330. int j = MathHelper.floor_double(this.boundingBox.minY);
  331. int k = MathHelper.floor_double(this.posZ);
  332.  
  333. if (j < 63)
  334. {
  335. return false;
  336. }
  337.  
  338. Block block = this.worldObj.getBlock(i, j - 1, k);
  339.  
  340. if (block == Blocks.sand || block.isLeaves(worldObj, i, j - 1, k))
  341. {
  342. return true;
  343. }
  344. }
  345.  
  346. return false;
  347. }
  348. }
  349.  
  350. /**
  351. * Gets the name of this command sender (usually username, but possibly "Rcon")
  352. */
  353. public String getCommandSenderName()
  354. {
  355. return this.hasCustomNameTag() ? this.getCustomNameTag() : (this.isTamed() ? StatCollector.translateToLocal("entity.Cat.name") : super.getCommandSenderName());
  356. }
  357.  
  358. public IEntityLivingData onSpawnWithEgg(IEntityLivingData p_110161_1_)
  359. {
  360. p_110161_1_ = super.onSpawnWithEgg(p_110161_1_);
  361.  
  362. if (this.worldObj.rand.nextInt(7) == 0)
  363. {
  364. for (int i = 0; i < 2; ++i)
  365. {
  366. EntityBeardedDragon entitybeardeddragon = new EntityBeardedDragon(this.worldObj);
  367. entitybeardeddragon.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
  368. entitybeardeddragon.setGrowingAge(-24000);
  369. this.worldObj.spawnEntityInWorld(entitybeardeddragon);
  370. }
  371. }
  372.  
  373. return p_110161_1_;
  374. }
  375. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement