Advertisement
Guest User

Untitled

a guest
May 17th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.22 KB | None | 0 0
  1. package com.TheRPGAdventurer.server.entity;
  2.  
  3. import static net.minecraft.entity.SharedMonsterAttributes.ATTACK_DAMAGE;
  4. import static net.minecraft.entity.SharedMonsterAttributes.FOLLOW_RANGE;
  5. import static net.minecraft.entity.SharedMonsterAttributes.MAX_HEALTH;
  6. import static net.minecraft.entity.SharedMonsterAttributes.MOVEMENT_SPEED;
  7. import java.util.BitSet;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.UUID;
  12. import javax.annotation.Nullable;
  13. import org.apache.logging.log4j.LogManager;
  14. import org.apache.logging.log4j.Logger;
  15. import com.TheRPGAdventurer.RealmOfTheDragonsLootTables;
  16. import com.TheRPGAdventurer.client.init.ModItems;
  17. import com.TheRPGAdventurer.client.model.anim.DragonAnimator;
  18. import com.TheRPGAdventurer.server.entity.ai.path.PathNavigateFlying;
  19. import com.TheRPGAdventurer.server.entity.breeds.DragonBreed;
  20. import com.TheRPGAdventurer.server.entity.breeds.DragonBreedAmethyst;
  21. import com.TheRPGAdventurer.server.entity.breeds.DragonBreedGarnet;
  22. import com.TheRPGAdventurer.server.entity.breeds.DragonBreedJade;
  23. import com.TheRPGAdventurer.server.entity.breeds.DragonBreedRuby;
  24. import com.TheRPGAdventurer.server.entity.breeds.DragonBreedSapphire;
  25. import com.TheRPGAdventurer.server.entity.breeds.EnumDragonBreed;
  26. import com.TheRPGAdventurer.server.entity.helper.DragonBodyHelper;
  27. import com.TheRPGAdventurer.server.entity.helper.DragonBrain;
  28. import com.TheRPGAdventurer.server.entity.helper.DragonBreedHelper;
  29. import com.TheRPGAdventurer.server.entity.helper.DragonHelper;
  30. import com.TheRPGAdventurer.server.entity.helper.DragonInteractHelper;
  31. import com.TheRPGAdventurer.server.entity.helper.DragonLifeStageHelper;
  32. import com.TheRPGAdventurer.server.entity.helper.DragonMoveHelper;
  33. import com.TheRPGAdventurer.server.entity.helper.DragonParticleHelper;
  34. import com.TheRPGAdventurer.server.entity.helper.DragonReproductionHelper;
  35. import com.TheRPGAdventurer.server.entity.helper.DragonSoundManager;
  36. import com.TheRPGAdventurer.server.util.Vec3;
  37. import com.google.common.base.Optional;
  38. import com.google.common.collect.Maps;
  39.  
  40. import net.minecraft.block.Block;
  41. import net.minecraft.entity.Entity;
  42. import net.minecraft.entity.EntityAgeable;
  43. import net.minecraft.entity.EntityList;
  44. import net.minecraft.entity.EntityLiving;
  45. import net.minecraft.entity.EnumCreatureAttribute;
  46. import net.minecraft.entity.SharedMonsterAttributes;
  47. import net.minecraft.entity.ai.EntityAISit;
  48. import net.minecraft.entity.ai.attributes.IAttribute;
  49. import net.minecraft.entity.ai.attributes.RangedAttribute;
  50. import net.minecraft.entity.passive.EntityAnimal;
  51. import net.minecraft.entity.passive.EntitySheep;
  52. import net.minecraft.entity.passive.EntityTameable;
  53. import net.minecraft.entity.player.EntityPlayer;
  54. import net.minecraft.init.Items;
  55. import net.minecraft.item.EnumDyeColor;
  56. import net.minecraft.item.Item;
  57. import net.minecraft.item.ItemStack;
  58. import net.minecraft.nbt.NBTTagCompound;
  59. import net.minecraft.network.datasync.DataParameter;
  60. import net.minecraft.network.datasync.DataSerializers;
  61. import net.minecraft.network.datasync.EntityDataManager;
  62. import net.minecraft.network.play.server.SPacketAnimation;
  63. import net.minecraft.pathfinding.PathNavigateGround;
  64. import net.minecraft.util.DamageSource;
  65. import net.minecraft.util.EnumHand;
  66. import net.minecraft.util.ResourceLocation;
  67. import net.minecraft.util.SoundEvent;
  68. import net.minecraft.util.math.BlockPos;
  69. import net.minecraft.util.text.translation.I18n;
  70. import net.minecraft.world.IBlockAccess;
  71. import net.minecraft.world.World;
  72. import net.minecraft.world.WorldServer;
  73. import net.minecraft.world.storage.loot.LootTableList;
  74.  
  75. /**
  76. * Here be dragons.
  77. */
  78. public class EntityTameableDragon extends EntityTameable implements net.minecraftforge.common.IShearable{
  79.  
  80. private static final Logger L = LogManager.getLogger();
  81.  
  82.  
  83. public static final IAttribute MOVEMENT_SPEED_AIR = new RangedAttribute(null,
  84. "generic.movementSpeedAir", 1.5, 0.0, Double.MAX_VALUE)
  85. .setDescription("Movement Speed Air")
  86. .setShouldWatch(true);
  87.  
  88. // base attributes
  89. public static final double BASE_SPEED_GROUND = 0.3;
  90. public static final double BASE_ARMOR = 10.0D;
  91. public static final double BASE_SPEED_AIR = 0.4;
  92. public static final double BASE_DAMAGE = 15;
  93. public static final double BASE_HEALTH = 1;
  94. public static final float BASE_WIDTH = 2.0f;
  95. public static final float BASE_HEIGHT = 2.0f;
  96. public static final double BASE_FOLLOW_RANGE = 16;
  97. public static final double BASE_FOLLOW_RANGE_FLYING = BASE_FOLLOW_RANGE * 2;
  98. public static final int HOME_RADIUS = 64;
  99. public static final double ALTITUDE_FLYING_THRESHOLD = 2;
  100.  
  101. public Entity riddenByEntity;
  102. /** The entity we are currently riding */
  103. public Entity ridingEntity;
  104.  
  105. // data value IDs
  106. private static final DataParameter<Boolean> DATA_FLYING =
  107. EntityDataManager.<Boolean>createKey(EntityTameableDragon.class, DataSerializers.BOOLEAN);
  108. private static final DataParameter<Boolean> DATA_SADDLED =
  109. EntityDataManager.<Boolean>createKey(EntityTameableDragon.class, DataSerializers.BOOLEAN);
  110. private static final DataParameter<Optional<UUID>> DATA_BREEDER =
  111. EntityDataManager.<Optional<UUID>>createKey(EntityTameableDragon.class, DataSerializers.OPTIONAL_UNIQUE_ID);
  112. private static final DataParameter<String> DATA_BREED =
  113. EntityDataManager.<String>createKey(EntityTameableDragon.class, DataSerializers.STRING);
  114. private static final DataParameter<Integer> DATA_REPRO_COUNT =
  115. EntityDataManager.<Integer>createKey(EntityTameableDragon.class, DataSerializers.VARINT);
  116. private static final DataParameter<Integer> DATA_TICKS_SINCE_CREATION =
  117. EntityDataManager.<Integer>createKey(EntityTameableDragon.class, DataSerializers.VARINT);
  118.  
  119. // data NBT IDs
  120. private static final String NBT_SADDLED = "Saddle";
  121.  
  122. private static String NBT_FLYING = "Flying";
  123. private static String NBT_CAN_FLY = "CanFly";
  124.  
  125. private boolean boosting;
  126. private int boostTime;
  127. private int totalBoostTime;
  128.  
  129. private double airSpeedHorizonal = 1.5;
  130. private double airSpeedVertical = 0;
  131. private float yawAdd;
  132. private int yawSpeed = 30;
  133. private int inAirTicks;
  134.  
  135. // server/client delegates
  136. private final Map<Class, DragonHelper> helpers = new HashMap<>();
  137.  
  138. // client-only delegates
  139. private final DragonBodyHelper bodyHelper = new DragonBodyHelper(this);
  140.  
  141. // server-only flags
  142. private BitSet controlFlags;
  143.  
  144. public EntityTameableDragon(World world) {
  145. super(world);
  146.  
  147.  
  148.  
  149. // set base size
  150. setSize(BASE_WIDTH, BASE_HEIGHT);
  151.  
  152. // enables walking over blocks
  153. stepHeight = 1;
  154.  
  155. // create entity delegates
  156. addHelper(new DragonBreedHelper(this, DATA_BREED));
  157. addHelper(new DragonLifeStageHelper(this, DATA_TICKS_SINCE_CREATION));
  158. addHelper(new DragonReproductionHelper(this, DATA_BREEDER, DATA_REPRO_COUNT));
  159. addHelper(new DragonSoundManager(this));
  160. addHelper(new DragonInteractHelper(this));
  161.  
  162. if (isClient()) {
  163. addHelper(new DragonParticleHelper(this));
  164. addHelper(new DragonAnimator(this));
  165. } else {
  166. addHelper(new DragonBrain(this));
  167. }
  168.  
  169. moveHelper = new DragonMoveHelper(this);
  170. aiSit = new EntityAISit(this);
  171.  
  172. // init helpers
  173. helpers.values().forEach(DragonHelper::applyEntityAttributes);
  174. }
  175.  
  176. @Override
  177. public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
  178. return null;
  179. }
  180.  
  181. @Override
  182. protected float updateDistance(float p_110146_1_, float p_110146_2_) {
  183. // required to fixate body while sitting. also slows down rotation while
  184. // standing.
  185. bodyHelper.updateRenderAngles();
  186. return p_110146_2_;
  187. }
  188.  
  189. @Override
  190. protected void entityInit() {
  191. super.entityInit();
  192.  
  193. dataManager.register(DATA_FLYING, false);
  194. dataManager.register(DATA_SADDLED, false);
  195.  
  196. }
  197.  
  198. @Override
  199. protected void applyEntityAttributes() {
  200. super.applyEntityAttributes();
  201.  
  202. getAttributeMap().registerAttribute(ATTACK_DAMAGE);
  203. getAttributeMap().registerAttribute(MOVEMENT_SPEED_AIR);
  204. getEntityAttribute(MOVEMENT_SPEED).setBaseValue(BASE_SPEED_GROUND);
  205. getEntityAttribute(MOVEMENT_SPEED_AIR).setBaseValue(BASE_SPEED_AIR);
  206. getEntityAttribute(MAX_HEALTH).setBaseValue(BASE_HEALTH);
  207. getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(BASE_ARMOR);
  208. getEntityAttribute(ATTACK_DAMAGE).setBaseValue(BASE_DAMAGE);
  209. getEntityAttribute(FOLLOW_RANGE).setBaseValue(BASE_FOLLOW_RANGE);
  210. getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(10.0D);
  211. }
  212.  
  213.  
  214. /**
  215. * Returns true if the dragon is saddled.
  216. */
  217. public boolean isSaddled() {
  218. return dataManager.get(DATA_SADDLED);
  219. }
  220.  
  221. /**
  222. * Set or remove the saddle of the dragon.
  223. */
  224. public void setSaddled(boolean saddled) {
  225. L.trace("setSaddled({})", saddled);
  226. dataManager.set(DATA_SADDLED, saddled);
  227. }
  228.  
  229.  
  230. public boolean canFly() {
  231. // eggs and hatchlings can't fly
  232. return !isEgg() && !isHatchling();
  233. }
  234.  
  235. /**
  236. * Returns true if the entity is flying.
  237. */
  238. public boolean isFlying() {
  239. return dataManager.get(DATA_FLYING);
  240. }
  241.  
  242. /**
  243. * Set the flying flag of the entity.
  244. */
  245. public void setFlying(boolean flying) {
  246. L.trace("setFlying({})", flying);
  247. dataManager.set(DATA_FLYING, flying);
  248. }
  249.  
  250. /**
  251. * Returns the distance to the ground while the entity is flying.
  252. */
  253. public double getAltitude() {
  254. BlockPos groundPos = worldObj.getHeight(getPosition());
  255. return posY - groundPos.getY();
  256.  
  257. }
  258.  
  259.  
  260. /**
  261. * Causes this entity to lift off if it can fly.
  262. */
  263. public void liftOff() {
  264. L.trace("liftOff");
  265. if (canFly()) {
  266. jump();
  267. }
  268. }
  269.  
  270. @Override
  271. protected float getJumpUpwardsMotion() {
  272. // stronger jumps for easier lift-offs
  273. return canFly() ? 1 : super.getJumpUpwardsMotion();
  274. }
  275.  
  276. /**
  277. * Called when the mob is falling. Calculates and applies fall damage.
  278. */
  279. @Override
  280. public void fall(float distance, float damageMultiplier) {
  281. // ignore fall damage if the entity can fly
  282. if (!canFly()) {
  283. super.fall(distance, damageMultiplier);
  284. }
  285. }
  286.  
  287. /**
  288. * (abstract) Protected helper method to write subclass entity data to NBT.
  289. */
  290. @Override
  291. public void writeEntityToNBT(NBTTagCompound nbt) {
  292. super.writeEntityToNBT(nbt);
  293. nbt.setBoolean(NBT_SADDLED, isSaddled());
  294.  
  295. helpers.values().forEach(helper -> helper.writeToNBT(nbt));
  296. }
  297.  
  298. /**
  299. * (abstract) Protected helper method to read subclass entity data from NBT.
  300. */
  301. @Override
  302. public void readEntityFromNBT(NBTTagCompound nbt) {
  303. super.readEntityFromNBT(nbt);
  304. setSaddled(nbt.getBoolean(NBT_SADDLED));
  305.  
  306. helpers.values().forEach(helper -> helper.readFromNBT(nbt));
  307. }
  308.  
  309. @Override
  310. public void onLivingUpdate() {
  311. helpers.values().forEach(DragonHelper::onLivingUpdate);
  312.  
  313. if (isServer()) {
  314. // set home position near owner when tamed
  315. if (isTamed()) {
  316. Entity owner = getOwner();
  317. if (owner != null) {
  318. setHomePosAndDistance(owner.getPosition(), HOME_RADIUS);
  319. }
  320. }
  321.  
  322. // update flying state based on the distance to the ground
  323. boolean flying = canFly() && getAltitude() > ALTITUDE_FLYING_THRESHOLD;
  324. if (flying != isFlying()) {
  325. // notify client
  326. setFlying(flying);
  327.  
  328. // clear tasks (needs to be done before switching the navigator!)
  329. getBrain().clearTasks();
  330.  
  331. // update AI follow range (needs to be updated before creating
  332. // new PathNavigate!)
  333. getEntityAttribute(FOLLOW_RANGE).setBaseValue(
  334. flying ? BASE_FOLLOW_RANGE_FLYING : BASE_FOLLOW_RANGE);
  335.  
  336. // update pathfinding method
  337. if (flying) {
  338. navigator = new PathNavigateFlying(this, worldObj);
  339. } else {
  340. navigator = new PathNavigateGround(this, worldObj);
  341. }
  342.  
  343. // tasks need to be updated after switching modes
  344. getBrain().updateAITasks();
  345. }
  346. }
  347.  
  348. super.onLivingUpdate();
  349. }
  350.  
  351. @Override
  352. public void moveEntityWithHeading(float strafe, float forward) {
  353. // disable method while flying, the movement is done entirely by
  354. // moveEntity() and this one just makes the dragon to fall slowly when
  355. // hovering
  356. if (!isFlying()) {
  357. super.moveEntityWithHeading(strafe, forward);
  358. }
  359. }
  360.  
  361. /**
  362. * Handles entity death timer, experience orb and particle creation
  363. */
  364. @Override
  365. protected void onDeathUpdate() {
  366. helpers.values().forEach(DragonHelper::onDeathUpdate);
  367.  
  368. // unmount any riding entities
  369. removePassengers();
  370.  
  371. // freeze at place
  372. motionX = motionY = motionZ = 0;
  373. rotationYaw = prevRotationYaw;
  374. rotationYawHead = prevRotationYawHead;
  375.  
  376. if (isEgg()) {
  377. setDead();
  378. } else {
  379. // actually delete entity after the time is up
  380. if (deathTime >= getMaxDeathTime()) {
  381. setDead();
  382. }
  383. }
  384.  
  385. deathTime++;
  386. }
  387.  
  388. @Override
  389. public void setDead() {
  390. helpers.values().forEach(DragonHelper::onDeath);
  391. super.setDead();
  392. }
  393.  
  394. @Override
  395. public String getName() {
  396. // return custom name if set
  397. if (hasCustomName()) {
  398. return getCustomNameTag();
  399. }
  400.  
  401. // return default breed name otherwise
  402. String entName = EntityList.getEntityString(this);
  403. String breedName = getBreedType().getName().toLowerCase();
  404. return I18n.translateToLocal("entity." + entName + "." + breedName + ".name");
  405. }
  406.  
  407. /**
  408. * Returns the sound this mob makes while it's alive.
  409. */
  410. @Override
  411. protected SoundEvent getAmbientSound() {
  412. return getSoundManager().getLivingSound();
  413. }
  414.  
  415. /**
  416. * Returns the sound this mob makes when it is hurt.
  417. */
  418. @Override
  419. protected SoundEvent getHurtSound() {
  420. return getSoundManager().getHurtSound();
  421. }
  422.  
  423. /**
  424. * Returns the sound this mob makes on death.
  425. */
  426. @Override
  427. protected SoundEvent getDeathSound() {
  428. return getSoundManager().getDeathSound();
  429. }
  430.  
  431. /**
  432. * Plays living's sound at its position
  433. */
  434. @Override
  435. public void playLivingSound() {
  436. getSoundManager().playLivingSound();
  437. }
  438.  
  439. @Override
  440. public void playSound(SoundEvent soundIn, float volume, float pitch) {
  441. getSoundManager().playSound(soundIn, volume, pitch);
  442. }
  443.  
  444. /**
  445. * Plays step sound at given x, y, z for the entity
  446. */
  447. @Override
  448. protected void playStepSound(BlockPos entityPos, Block block) {
  449. getSoundManager().playStepSound(entityPos, block);
  450. }
  451.  
  452. /**
  453. * Returns the volume for the sounds this mob makes.
  454. */
  455. @Override
  456. protected float getSoundVolume() {
  457. // note: unused, managed in playSound()
  458. return 1;
  459. }
  460.  
  461. /**
  462. * Gets the pitch of living sounds in living entities.
  463. */
  464. @Override
  465. protected float getSoundPitch() {
  466. // note: unused, managed in playSound()
  467. return 1;
  468. }
  469.  
  470. /**
  471. * Get number of ticks, at least during which the living entity will be silent.
  472. */
  473. @Override
  474. public int getTalkInterval() {
  475. return getSoundManager().getTalkInterval();
  476. }
  477.  
  478. /**
  479. * Get this Entity's EnumCreatureAttribute
  480. */
  481. @Override
  482. public EnumCreatureAttribute getCreatureAttribute() {
  483. return getBreed().getCreatureAttribute();
  484. }
  485.  
  486. /**
  487. * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
  488. */
  489. @Override
  490. public boolean processInteract(EntityPlayer player, EnumHand hand, ItemStack item) {
  491. // don't interact with eggs!
  492. if (isEgg()) {
  493. return false;
  494. }
  495.  
  496. // inherited interaction
  497. if (super.processInteract(player, hand, item)) {
  498. return true;
  499. }
  500.  
  501. return getInteractHelper().interact(player, item);
  502. }
  503.  
  504. public void tamedFor(EntityPlayer player, boolean successful) {
  505. if (successful) {
  506. setTamed(true);
  507. navigator.clearPathEntity(); // replacement for setPathToEntity(null);
  508. setAttackTarget(null);
  509. setOwnerId(player.getUniqueID());
  510. playTameEffect(true);
  511. worldObj.setEntityState(this, (byte) 7);
  512. } else {
  513. playTameEffect(false);
  514. worldObj.setEntityState(this, (byte) 6);
  515. }
  516. }
  517.  
  518. public boolean isTamedFor(EntityPlayer player) {
  519. return isTamed() && isOwner(player);
  520. }
  521.  
  522. /**
  523. * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
  524. * the animal type)
  525. */
  526. @Override
  527. public boolean isBreedingItem(ItemStack item) {
  528. return getBreed().getBreedingItem() == item.getItem();
  529. }
  530.  
  531. /**
  532. * Returns the height of the eyes. Used for looking at other entities.
  533. */
  534. @Override
  535. public float getEyeHeight() {
  536. float eyeHeight = super.getEyeHeight();
  537.  
  538. if (isSitting()) {
  539. eyeHeight *= 0.8f;
  540. }
  541.  
  542. return eyeHeight;
  543. }
  544.  
  545. /**
  546. * Returns the Y offset from the entity's position for any entity riding this one.
  547. */
  548. @Override
  549. public double getMountedYOffset() {
  550. return (isSitting() ? 1.7f : 2.2f) * getScale();
  551. }
  552.  
  553. /**
  554. * Returns render size modifier
  555. */
  556. @Override
  557. public float getRenderSizeModifier() {
  558. return getScale();
  559. }
  560.  
  561. /**
  562. * Returns true if this entity should push and be pushed by other entities when colliding.
  563. */
  564. @Override
  565. public boolean canBePushed() {
  566. return super.canBePushed() && isEgg();
  567. }
  568.  
  569. /**
  570. * Determines if an entity can be despawned, used on idle far away entities
  571. */
  572. @Override
  573. protected boolean canDespawn() {
  574. return false;
  575. }
  576.  
  577. /**
  578. * returns true if this entity is by a ladder, false otherwise
  579. */
  580. @Override
  581. public boolean isOnLadder() {
  582. // this better doesn't happen...
  583. return false;
  584. }
  585. /**
  586. * @param breed
  587. * @param item
  588. * @return
  589. */
  590. @Nullable
  591. protected Item getDragonDropItem(EnumDragonBreed breed, Item item) {
  592. this.setBreedType(breed);
  593. return item;
  594. }
  595.  
  596. /**
  597. * Drop 0-2 items of this living's type.
  598. * @param par1 - Whether this entity has recently been hit by a player.
  599. * @param par2 - Level of Looting used to kill this mob.
  600. */
  601. // this one is fascinating. if the dragon is saddled, it drops the saddle
  602. @Override
  603. protected void dropFewItems(boolean par1, int par2) {
  604. super.dropFewItems(par1, par2);
  605.  
  606. // drop saddle if equipped
  607. if (isSaddled()) { //I used one of my custom items to see if there something wrong with my items, It is originally saddle
  608. dropItem(ModItems.JadeDragonScales, 64);
  609. }
  610. }
  611.  
  612. // I did what you said but it still won't drop anything,
  613. // Maybe it's the getBreedType that I used as a substitute to the get fleece color
  614. // when I ctrl clicked get dleece color, it puts me on enumdyecolor which is similar
  615. // to enumdragonbreed, this is where I started asking what dye damge means.
  616.  
  617. @Override
  618. protected ResourceLocation getLootTable() {
  619. if (this.getSheared()) {
  620. }
  621. else
  622. {
  623. switch (this.getBreedType())
  624. {
  625. case JADE:
  626. default:
  627. return RealmOfTheDragonsLootTables.ENTITIES_DRAGON_JADE;
  628. case GARNET:
  629. return RealmOfTheDragonsLootTables.ENTITIES_DRAGON_GARNET;
  630. case RUBY:
  631. return RealmOfTheDragonsLootTables.ENTITIES_DRAGON_RUBY;
  632. case SAPPHIRE:
  633. return RealmOfTheDragonsLootTables.ENTITIES_DRAGON_SAPPHIRE;
  634. case AMETHYST:
  635. return RealmOfTheDragonsLootTables.ENTITIES_DRAGON_AMETHYST;
  636. }
  637. }
  638. return null;
  639. }
  640.  
  641. private boolean getSheared() {
  642. return true;
  643. }
  644.  
  645. public boolean isShearable(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos){ return !this.getSheared() && !this.isChild();
  646.  
  647. }
  648.  
  649. public boolean attackEntityAsMob(Entity entityIn) {
  650. boolean attacked = entityIn.attackEntityFrom(
  651. DamageSource.causeMobDamage(this),
  652. (float) getEntityAttribute(ATTACK_DAMAGE).getAttributeValue()
  653. );
  654.  
  655. if (attacked) {
  656. applyEnchantments(this, entityIn);
  657. }
  658.  
  659. return attacked;
  660. }
  661.  
  662. @Override
  663. public void swingArm(EnumHand hand) {
  664. // play eating sound
  665. playSound(getSoundManager().getAttackSound(), 1, 0.7f);
  666.  
  667. // play attack animation
  668. if (worldObj instanceof WorldServer) {
  669. ((WorldServer) worldObj).getEntityTracker().sendToAllTrackingEntity(
  670. this, new SPacketAnimation(this, 0));
  671. }
  672. }
  673.  
  674. /**
  675. * Called when the entity is attacked.
  676. */
  677. @Override
  678. public boolean attackEntityFrom(DamageSource src, float par2) {
  679. if (isInvulnerableTo(src)) {
  680. return false;
  681. }
  682.  
  683. // don't just sit there!
  684. aiSit.setSitting(false);
  685.  
  686. return super.attackEntityFrom(src, par2);
  687. }
  688.  
  689. /**
  690. * Return whether this entity should be rendered as on fire.
  691. */
  692. @Override
  693. public boolean canRenderOnFire() {
  694. return super.canRenderOnFire() && !getBreed().isImmuneToDamage(DamageSource.inFire);
  695. }
  696.  
  697. /**
  698. * Returns true if the mob is currently able to mate with the specified mob.
  699. */
  700. @Override
  701. public boolean canMateWith(EntityAnimal mate) {
  702. return getReproductionHelper().canMateWith(mate);
  703. }
  704.  
  705. /**
  706. * This function is used when two same-species animals in 'love mode' breed to generate the new baby animal.
  707. */
  708. @Override
  709. public EntityAgeable createChild(EntityAgeable mate) {
  710. return getReproductionHelper().createChild(mate);
  711. }
  712.  
  713. private void addHelper(DragonHelper helper) {
  714. L.trace("addHelper({})", helper.getClass().getName());
  715. helpers.put(helper.getClass(), helper);
  716. }
  717.  
  718. private <T extends DragonHelper> T getHelper(Class<T> clazz) {
  719. return (T) helpers.get(clazz);
  720. }
  721.  
  722. public DragonBreedHelper getBreedHelper() {
  723. return getHelper(DragonBreedHelper.class);
  724. }
  725.  
  726. public DragonLifeStageHelper getLifeStageHelper() {
  727. return getHelper(DragonLifeStageHelper.class);
  728. }
  729.  
  730. public DragonReproductionHelper getReproductionHelper() {
  731. return getHelper(DragonReproductionHelper.class);
  732. }
  733.  
  734. public void setControlFlags(BitSet flags) {
  735. BitSet controlFlags = flags;
  736. }
  737.  
  738. public BitSet getControlFlags() {
  739. return controlFlags;
  740. }
  741.  
  742. // this one is dead I did not apply the // cuz it's increases my stress levels.
  743. @Nullable
  744. public void updateRiderPosition() {
  745. if (riddenByEntity != null) {
  746. double px = posX;
  747. double py = posY + getMountedYOffset() + riddenByEntity.getYOffset();
  748. double pz = posZ;
  749.  
  750. // dragon position is the middle of the model and the saddle is on
  751. // the shoulders, so move player forwards on Z axis relative to the
  752. // dragon's rotation to fix that
  753. Vec3 pos = new Vec3(0, 0, 0.8 * getScale());
  754. pos = pos.rotateYaw((float) Math.toRadians(-renderYawOffset)); // oops
  755. px += pos.xCoord;
  756. py += pos.yCoord;
  757. pz += pos.zCoord;
  758.  
  759. riddenByEntity.setPosition(px, py, pz);
  760.  
  761. // fix rider rotation
  762. if (riddenByEntity instanceof EntityLiving) {
  763. EntityLiving rider = ((EntityLiving) riddenByEntity);
  764. rider.prevRotationPitch = rider.rotationPitch;
  765. rider.prevRotationYaw = rider.rotationYaw;
  766. rider.renderYawOffset = renderYawOffset;
  767. }
  768. }
  769.  
  770. }
  771.  
  772. public DragonParticleHelper getParticleHelper() {
  773. return getHelper(DragonParticleHelper.class);
  774. }
  775.  
  776. public DragonAnimator getAnimator() {
  777. return getHelper(DragonAnimator.class);
  778. }
  779.  
  780. public DragonSoundManager getSoundManager() {
  781. return getHelper(DragonSoundManager.class);
  782. }
  783.  
  784. public DragonBrain getBrain() {
  785. return getHelper(DragonBrain.class);
  786. }
  787.  
  788. public DragonInteractHelper getInteractHelper() {
  789. return getHelper(DragonInteractHelper.class);
  790.  
  791. }
  792.  
  793. /**
  794. * Returns the breed for this dragon.
  795. *
  796. * @return breed
  797. */
  798. // just like enumdyecolor but I don't understand why it fails when I do the method just like the sheep
  799. public EnumDragonBreed getBreedType() {
  800. return getBreedHelper().getBreedType();
  801. }
  802.  
  803. /**
  804. * Sets the new breed for this dragon.
  805. *
  806. * @param type new breed
  807. */
  808. public void setBreedType(EnumDragonBreed type) {
  809. getBreedHelper().setBreedType(type);
  810. }
  811.  
  812. public DragonBreed getBreed() {
  813. return getBreedType().getBreed();
  814. }
  815.  
  816.  
  817. /**
  818. * For vehicles, the first passenger is generally considered the controller and "drives" the vehicle. For example,
  819. * Pigs, Horses, and Boats are generally "steered" by the controlling passenger.
  820. */
  821. @Override
  822. public Entity getControllingPassenger() {
  823. List<Entity> list = getPassengers();
  824. return list.isEmpty() ? null : list.get(0);
  825. }
  826.  
  827. @Override
  828. public boolean canPassengerSteer() {
  829. // must always return false or the vanilla movement code interferes
  830. // with DragonMoveHelper
  831. return false;
  832. }
  833.  
  834. public EntityPlayer getRidingPlayer() {
  835. Entity entity = getControllingPassenger();
  836. if (entity instanceof EntityPlayer) {
  837. return (EntityPlayer) entity;
  838. } else {
  839. return null;
  840. }
  841. }
  842.  
  843. public void setRidingPlayer(EntityPlayer player) {
  844. L.trace("setRidingPlayer({})", player.getName());
  845. player.rotationYaw = rotationYaw;
  846. player.rotationPitch = rotationPitch;
  847. player.startRiding(this);
  848. }
  849.  
  850. public boolean isInvulnerableTo(DamageSource src) {
  851. Entity srcEnt = src.getEntity();
  852. if (srcEnt != null) {
  853. // ignore own damage
  854. if (srcEnt == this) {
  855. return true;
  856. }
  857.  
  858. // ignore damage from riders
  859. if (isPassenger(srcEnt)) {
  860. return true;
  861. }
  862. }
  863.  
  864. // don't drown as egg
  865. if (src.damageType.equals("drown") && isEgg()) {
  866. return true;
  867. }
  868.  
  869. return getBreed().isImmuneToDamage(src);
  870. }
  871.  
  872. /**
  873. * Returns the entity's health relative to the maximum health.
  874. *
  875. * @return health normalized between 0 and 1
  876. */
  877. public double getHealthRelative() {
  878. return getHealth() / (double) getMaxHealth();
  879. }
  880.  
  881. public int getDeathTime() {
  882. return deathTime;
  883. }
  884.  
  885. public int getMaxDeathTime() {
  886. return 120;
  887. }
  888.  
  889. public void setImmuneToFire(boolean isImmuneToFire) {
  890. L.trace("setImmuneToFire({})", isImmuneToFire);
  891. this.isImmuneToFire = isImmuneToFire;
  892. }
  893.  
  894. public void setAttackDamage(double damage) {
  895. L.trace("setAttackDamage({})", damage);
  896. getEntityAttribute(ATTACK_DAMAGE).setBaseValue(damage);
  897. }
  898.  
  899. /**
  900. * Public wrapper for protected final setScale(), used by DragonLifeStageHelper.
  901. *
  902. * @param scale
  903. */
  904. public void setScalePublic(float scale) {
  905. double posXTmp = posX;
  906. double posYTmp = posY;
  907. double posZTmp = posZ;
  908. boolean onGroundTmp = onGround;
  909.  
  910. setScale(scale);
  911.  
  912. // workaround for a vanilla bug; the position is apparently not set correcty
  913. // after changing the entity size, causing asynchronous server/client positioning
  914. setPosition(posXTmp, posYTmp, posZTmp);
  915.  
  916. // otherwise, setScale stops the dragon from landing while it is growing
  917. onGround = onGroundTmp;
  918. }
  919.  
  920. /**
  921. * The age value may be negative or positive or zero. If it's negative, it get's incremented on each tick, if it's
  922. * positive, it get's decremented each tick. Don't confuse this with EntityLiving.getAge. With a negative value the
  923. * Entity is considered a child.
  924. */
  925. @Override
  926. public int getGrowingAge() {
  927. // adapter for vanilla code to enable breeding interaction
  928. return isAdult() ? 0 : -1;
  929. }
  930.  
  931. /**
  932. * The age value may be negative or positive or zero. If it's negative, it get's incremented on each tick, if it's
  933. * positive, it get's decremented each tick. With a negative value the Entity is considered a child.
  934. */
  935. @Override
  936. public void setGrowingAge(int age) {
  937. // managed by DragonLifeStageHelper, so this is a no-op
  938. }
  939.  
  940. /**
  941. * Sets the scale for an ageable entity according to the boolean parameter, which says if it's a child.
  942. */
  943. @Override
  944. public void setScaleForAge(boolean p_98054_1_) {
  945. // managed by DragonLifeStageHelper, so this is a no-op
  946. }
  947.  
  948. /**
  949. * Returns the size multiplier for the current age.
  950. *
  951. *
  952. * @return scale
  953. */
  954. // this dragon has multiple lifestages maybe it's the thing messing up
  955. public float getScale() {
  956. return getLifeStageHelper().getScale();
  957. }
  958.  
  959. public boolean isEgg() {
  960. return getLifeStageHelper().isEgg();
  961. }
  962.  
  963. public boolean isHatchling() {
  964. return getLifeStageHelper().isHatchling();
  965. }
  966.  
  967. public boolean isJuvenile() {
  968. return getLifeStageHelper().isJuvenile();
  969. }
  970.  
  971. public boolean isAdult() {
  972. return getLifeStageHelper().isAdult();
  973. }
  974.  
  975. @Override
  976. public boolean isChild() {
  977. return !isAdult();
  978. }
  979.  
  980. /**
  981. * Checks if this entity is running on a client.
  982. *
  983. * Required since MCP's isClientWorld returns the exact opposite...
  984. *
  985. * @return true if the entity runs on a client or false if it runs on a server
  986. */
  987. public final boolean isClient() {
  988. return worldObj.isRemote;
  989. }
  990.  
  991. /**
  992. * Checks if this entity is running on a server.
  993. *
  994. * @return true if the entity runs on a server or false if it runs on a client
  995. */
  996. public final boolean isServer() {
  997. return !worldObj.isRemote;
  998. }
  999.  
  1000.  
  1001. /**
  1002. * Sets new relative speed multiplier for the horizontal flying speed.
  1003. *
  1004. * @param airSpeedHorizonal new relative horizontal speed multiplier
  1005. */
  1006. public void setMoveSpeedAirHoriz(double airSpeedHorizonal) {
  1007. L.trace("setMoveSpeedAirHoriz({})", airSpeedHorizonal);
  1008. this.airSpeedHorizonal = airSpeedHorizonal;
  1009. }
  1010.  
  1011. /**
  1012. * Sets new relative speed multiplier for the vertical flying speed.
  1013. *
  1014. * @param airSpeedHorizonal new relative vertical speed multiplier
  1015. */
  1016. public void setMoveSpeedAirVert(double airSpeedVertical) {
  1017. L.trace("setMoveSpeedAirVert({})", airSpeedVertical);
  1018. this.airSpeedVertical = airSpeedVertical;
  1019. }
  1020.  
  1021. public boolean boost()
  1022. {
  1023. if (this.boosting)
  1024. {
  1025. return false;
  1026. }
  1027. else
  1028. {
  1029. this.boosting = true;
  1030. this.boostTime = 0;
  1031. this.totalBoostTime = this.getRNG().nextInt(841) + 140;
  1032. return true;
  1033. }
  1034. }
  1035.  
  1036. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement