Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.14 KB | None | 0 0
  1. package com.turtledove.necropolisofnostalgia.server.entity.Spiral_Draco;
  2.  
  3. import com.turtledove.necropolisofnostalgia.server.entity.NecropolisEntity;
  4. import javax.annotation.Nullable;
  5. import net.minecraft.entity.*;
  6. import net.minecraft.entity.item.EntityXPOrb;
  7. import net.minecraft.entity.monster.IMob;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.init.SoundEvents;
  10. import net.minecraft.nbt.NBTTagCompound;
  11. import net.minecraft.network.datasync.DataParameter;
  12. import net.minecraft.potion.PotionEffect;
  13. import net.minecraft.util.*;
  14. import net.minecraft.util.math.MathHelper;
  15. import net.minecraft.util.math.Vec3d;
  16. import net.minecraft.world.EnumDifficulty;
  17. import net.minecraft.world.World;
  18.  
  19. import net.minecraft.world.storage.loot.LootTableList;
  20. import net.minecraftforge.fml.relauncher.Side;
  21. import net.minecraftforge.fml.relauncher.SideOnly;
  22. import org.apache.logging.log4j.LogManager;
  23. import org.apache.logging.log4j.Logger;
  24.  
  25. import java.util.List;
  26.  
  27.  
  28. public class EntitySpiral_Draco extends NecropolisEntity implements IEntityMultiPart, IMob
  29. {
  30. private static final Logger LOGGER = LogManager.getLogger();
  31. /** An array containing all body parts */
  32. public MultiPartEntityPart[] spiral_dracoPartArray;
  33.  
  34. /** The head bounding box of the draco */
  35. //public MultiPartEntityPart spiral_dracoPartLHead = new MultiPartEntityPart(this, "Lhead", 6.0F, 6.0F);
  36. public MultiPartEntityPart spiral_dracoPartRLeg = new MultiPartEntityPart(this, "Chead", 6.0F, 6.0F);
  37. //public MultiPartEntityPart spiral_dracoPartRHead = new MultiPartEntityPart(this, "Rhead", 6.0F, 6.0F);
  38. private Vec3d targetLocation;
  39. public EntitySpiral_Draco(World worldIn)
  40. {
  41. super(worldIn);
  42. this.spiral_dracoPartArray = new MultiPartEntityPart[] {this.spiral_dracoPartRLeg};
  43. this.setHealth(this.getMaxHealth());
  44. this.setSize(16.0F, 14.0F);
  45. this.noClip = true;
  46. this.isImmuneToFire = true;
  47. this.targetLocation = null;
  48. this.setLocationAndAngles(this.posX,this.posY,this.posZ,0,0);
  49. this.ignoreFrustumCheck = true;
  50. }
  51.  
  52. protected void applyEntityAttributes()
  53. {
  54. super.applyEntityAttributes();
  55. this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(200.0D);
  56. }
  57.  
  58. protected void entityInit()
  59. {
  60. super.entityInit();
  61. }
  62.  
  63. public void onUpdate()
  64. {
  65. super.onUpdate();
  66.  
  67. if (this.world.isRemote)
  68. {
  69. this.setHealth(this.getHealth());
  70. }
  71. if (this.getHealth() <= 0.0F)
  72. {
  73. float f12 = (this.rand.nextFloat() - 0.5F) * 8.0F;
  74. float f13 = (this.rand.nextFloat() - 0.5F) * 4.0F;
  75. float f15 = (this.rand.nextFloat() - 0.5F) * 8.0F;
  76. this.world.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.posX + (double)f12, this.posY + 2.0D + (double)f13, this.posZ + (double)f15, 0.0D, 0.0D, 0.0D);
  77. }
  78. else
  79. {
  80. //this.spiral_dracoPartLHead.width = 1.0F;
  81. //this.spiral_dracoPartLHead.height = 1.0F;
  82. this.spiral_dracoPartRLeg.width = 1.0F;
  83. this.spiral_dracoPartRLeg.height = 4.0F;
  84. //this.spiral_dracoPartRHead.height = 1.0F;
  85. //this.spiral_dracoPartRHead.width = 1.0F;
  86. Vec3d[] avec3d = new Vec3d[this.spiral_dracoPartArray.length];
  87.  
  88. for (int j = 0; j < this.spiral_dracoPartArray.length; ++j)
  89. {
  90. avec3d[j] = new Vec3d(this.spiral_dracoPartArray[j].posX, this.spiral_dracoPartArray[j].posY, this.spiral_dracoPartArray[j].posZ);
  91. }
  92.  
  93. if (!this.world.isRemote && this.hurtTime == 0)
  94. {
  95. this.collideWithEntities(this.world.getEntitiesWithinAABBExcludingEntity(this, this.spiral_dracoPartRLeg.getEntityBoundingBox().grow(1.0D)));
  96. }
  97.  
  98. this.spiral_dracoPartRLeg.onUpdate();
  99. this.spiral_dracoPartRLeg.setLocationAndAngles(this.posX + (double)(6.5F), this.posY + (double)(6.5F), this.posZ - (double)(6.5F), 0.0F, 0.0F);
  100.  
  101. for (int k = 1; k < 2; ++k)
  102. {
  103. MultiPartEntityPart multipartentitypart = null;
  104.  
  105. if (k == 0)
  106. {
  107. //multipartentitypart = this.spiral_dracoPartLHead;
  108. }
  109.  
  110. if (k == 1)
  111. {
  112. multipartentitypart = this.spiral_dracoPartRLeg;
  113. }
  114.  
  115. if (k == 2)
  116. {
  117. //multipartentitypart = this.spiral_dracoPartRHead;
  118. }
  119.  
  120. multipartentitypart.onUpdate();
  121. multipartentitypart.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
  122. }
  123.  
  124. for (int l = 0; l < this.spiral_dracoPartArray.length; ++l)
  125. {
  126. this.spiral_dracoPartArray[l].prevPosX = avec3d[l].x;
  127. this.spiral_dracoPartArray[l].prevPosY = avec3d[l].y;
  128. this.spiral_dracoPartArray[l].prevPosZ = avec3d[l].z;
  129. }
  130. }
  131. }
  132.  
  133. /**
  134. * Pushes all entities inside the list away from the enderdragon.
  135. */
  136. private void collideWithEntities(List<Entity> p_70970_1_)
  137. {
  138. double d0 = (this.spiral_dracoPartRLeg.getEntityBoundingBox().minX + this.spiral_dracoPartRLeg.getEntityBoundingBox().maxX) / 2.0D;
  139. double d1 = (this.spiral_dracoPartRLeg.getEntityBoundingBox().minZ + this.spiral_dracoPartRLeg.getEntityBoundingBox().maxZ) / 2.0D;
  140.  
  141. for (Entity entity : p_70970_1_)
  142. {
  143. if (entity instanceof EntityLivingBase)
  144. {
  145. System.out.print("Collided!");
  146. double d2 = entity.posX - d0;
  147. double d3 = entity.posZ - d1;
  148. double d4 = d2 * d2 + d3 * d3;
  149. entity.addVelocity(d2 / d4 * 4.0D, 0.20000000298023224D, d3 / d4 * 4.0D);
  150. entity.attackEntityFrom(DamageSource.causeMobDamage(this), 5.0F);
  151. }
  152. }
  153. }
  154.  
  155. public boolean attackEntityFromPart(MultiPartEntityPart dragonPart, DamageSource source, float damage)
  156. {
  157. if (dragonPart != this.spiral_dracoPartRLeg)
  158. {
  159. damage = damage / 4.0F + Math.min(damage, 1.0F);
  160. }
  161.  
  162. if (damage < 0.01F)
  163. {
  164. return false;
  165. }
  166. else
  167. {
  168. if (source.getTrueSource() instanceof EntityPlayer || source.isExplosion())
  169. {
  170. float f = this.getHealth();
  171. this.attackDragonFrom(source, damage);
  172. }
  173. return true;
  174. }
  175. }
  176.  
  177. /**
  178. * Called when the entity is attacked.
  179. */
  180. public boolean attackEntityFrom(DamageSource source, float amount)
  181. {
  182. if (source instanceof EntityDamageSource && ((EntityDamageSource)source).getIsThornsDamage())
  183. {
  184. this.attackEntityFromPart(this.spiral_dracoPartRLeg, source, amount);
  185. }
  186.  
  187. return false;
  188. }
  189.  
  190. /**
  191. * Provides a way to cause damage to an ender dragon.
  192. */
  193. protected boolean attackDragonFrom(DamageSource source, float amount)
  194. {
  195. return super.attackEntityFrom(source, amount);
  196. }
  197.  
  198. /**
  199. * Called by the /kill command.
  200. */
  201. public void onKillCommand()
  202. {
  203. this.setDead();
  204. }
  205.  
  206. private void dropExperience(int p_184668_1_)
  207. {
  208. while (p_184668_1_ > 0)
  209. {
  210. int i = EntityXPOrb.getXPSplit(p_184668_1_);
  211. p_184668_1_ -= i;
  212. this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY, this.posZ, i));
  213. }
  214. }
  215.  
  216.  
  217. /**
  218. * (abstract) Protected helper method to write subclass entity data to NBT.
  219. */
  220. public void writeEntityToNBT(NBTTagCompound compound)
  221. {
  222. super.writeEntityToNBT(compound);
  223. }
  224.  
  225. /**
  226. * (abstract) Protected helper method to read subclass entity data from NBT.
  227. */
  228. public void readEntityFromNBT(NBTTagCompound compound)
  229. {
  230. super.readEntityFromNBT(compound);
  231. }
  232.  
  233. /**
  234. * Makes the entity despawn if requirements are reached
  235. */
  236. protected void despawnEntity()
  237. {
  238. }
  239.  
  240. /**
  241. * Return the Entity parts making up this Entity (currently only for dragons)
  242. */
  243. public Entity[] getParts()
  244. {
  245. return this.spiral_dracoPartArray;
  246. }
  247.  
  248. /**
  249. * Returns true if other Entities should be prevented from moving through this Entity.
  250. */
  251. public boolean canBeCollidedWith()
  252. {
  253. return true;
  254. }
  255.  
  256. public World getWorld()
  257. {
  258. return this.world;
  259. }
  260.  
  261. public SoundCategory getSoundCategory()
  262. {
  263. return SoundCategory.HOSTILE;
  264. }
  265.  
  266. protected SoundEvent getAmbientSound()
  267. {
  268. return SoundEvents.ENTITY_ENDERDRAGON_AMBIENT;
  269. }
  270.  
  271. protected SoundEvent getHurtSound(DamageSource damageSourceIn)
  272. {
  273. return SoundEvents.ENTITY_ENDERDRAGON_HURT;
  274. }
  275.  
  276. /**
  277. * Returns the volume for the sounds this mob makes.
  278. */
  279. protected float getSoundVolume()
  280. {
  281. return 5.0F;
  282. }
  283.  
  284. @Nullable
  285. protected ResourceLocation getLootTable()
  286. {
  287. return LootTableList.ENTITIES_ENDER_DRAGON;
  288. }
  289.  
  290. @SideOnly(Side.CLIENT)
  291. public float getHeadPartYOffset(int p_184667_1_, double[] p_184667_2_, double[] p_184667_3_)
  292. {
  293. double d0;
  294.  
  295. if (p_184667_1_ == 6)
  296. {
  297. d0 = 0.0D;
  298. }
  299. else
  300. {
  301. d0 = p_184667_3_[1] - p_184667_2_[1];
  302. }
  303.  
  304. return (float)d0;
  305. }
  306.  
  307.  
  308. public void notifyDataManagerChange(DataParameter<?> key)
  309. {
  310. super.notifyDataManagerChange(key);
  311. }
  312.  
  313. /**
  314. * adds a PotionEffect to the entity
  315. */
  316. public void addPotionEffect(PotionEffect potioneffectIn)
  317. {
  318. }
  319.  
  320. protected boolean canBeRidden(Entity entityIn)
  321. {
  322. return false;
  323. }
  324.  
  325. /**
  326. * Returns false if this Entity is a boss, true otherwise.
  327. */
  328. public boolean isNonBoss()
  329. {
  330. return false;
  331. }
  332. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement