Advertisement
Guest User

entityvenom

a guest
Jul 4th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.69 KB | None | 0 0
  1. package com.ChaoticSoul.MoreArmor.entity;
  2.  
  3. import java.util.List;
  4. import java.util.UUID;
  5.  
  6. import javax.annotation.Nullable;
  7.  
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.IProjectile;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.util.DamageSource;
  13. import net.minecraft.util.EnumParticleTypes;
  14. import net.minecraft.util.math.AxisAlignedBB;
  15. import net.minecraft.util.math.MathHelper;
  16. import net.minecraft.util.math.RayTraceResult;
  17. import net.minecraft.util.math.Vec3d;
  18. import net.minecraft.world.World;
  19. import net.minecraftforge.fml.relauncher.Side;
  20. import net.minecraftforge.fml.relauncher.SideOnly;
  21.  
  22. public class EntityVenom extends Entity implements IProjectile
  23. {
  24. public EntityCobra owner;
  25. private NBTTagCompound ownerNbt;
  26.  
  27. public EntityVenom(World worldIn)
  28. {
  29. super(worldIn);
  30. }
  31.  
  32. public EntityVenom(World worldIn, EntityCobra p_i47273_2_)
  33. {
  34. super(worldIn);
  35. this.owner = p_i47273_2_;
  36. this.setPosition(p_i47273_2_.posX - (double)(p_i47273_2_.width + 1.0F) * 0.5D * (double)MathHelper.sin(p_i47273_2_.renderYawOffset * 0.017453292F), p_i47273_2_.posY + (double)p_i47273_2_.getEyeHeight() - 0.10000000149011612D, p_i47273_2_.posZ + (double)(p_i47273_2_.width + 1.0F) * 0.5D * (double)MathHelper.cos(p_i47273_2_.renderYawOffset * 0.017453292F));
  37. this.setSize(0.25F, 0.25F);
  38. }
  39.  
  40. @SideOnly(Side.CLIENT)
  41. public EntityVenom(World worldIn, double x, double y, double z, double p_i47274_8_, double p_i47274_10_, double p_i47274_12_)
  42. {
  43. super(worldIn);
  44. this.setPosition(x, y, z);
  45.  
  46. for (int i = 0; i < 7; ++i)
  47. {
  48. double d0 = 0.4D + 0.1D * (double)i;
  49. worldIn.spawnParticle(EnumParticleTypes.SPIT, x, y, z, p_i47274_8_ * d0, p_i47274_10_, p_i47274_12_ * d0);
  50. }
  51.  
  52. this.motionX = p_i47274_8_;
  53. this.motionY = p_i47274_10_;
  54. this.motionZ = p_i47274_12_;
  55. }
  56.  
  57. /**
  58. * Called to update the entity's position/logic.
  59. */
  60. public void onUpdate()
  61. {
  62. super.onUpdate();
  63.  
  64. if (this.ownerNbt != null)
  65. {
  66. this.restoreOwnerFromSave();
  67. }
  68.  
  69. Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
  70. Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  71. RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1);
  72. vec3d = new Vec3d(this.posX, this.posY, this.posZ);
  73. vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  74.  
  75. if (raytraceresult != null)
  76. {
  77. vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
  78. }
  79.  
  80. Entity entity = this.getHitEntity(vec3d, vec3d1);
  81.  
  82. if (entity != null)
  83. {
  84. raytraceresult = new RayTraceResult(entity);
  85. }
  86.  
  87. if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult))
  88. {
  89. this.onHit(raytraceresult);
  90. }
  91.  
  92. this.posX += this.motionX;
  93. this.posY += this.motionY;
  94. this.posZ += this.motionZ;
  95. float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  96. this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
  97.  
  98. for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
  99. {
  100. ;
  101. }
  102.  
  103. while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
  104. {
  105. this.prevRotationPitch += 360.0F;
  106. }
  107.  
  108. while (this.rotationYaw - this.prevRotationYaw < -180.0F)
  109. {
  110. this.prevRotationYaw -= 360.0F;
  111. }
  112.  
  113. while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
  114. {
  115. this.prevRotationYaw += 360.0F;
  116. }
  117.  
  118. this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
  119. this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  120. float f1 = 0.99F;
  121. float f2 = 0.06F;
  122.  
  123. if (!this.world.isMaterialInBB(this.getEntityBoundingBox(), Material.AIR))
  124. {
  125. this.setDead();
  126. }
  127. else if (this.isInWater())
  128. {
  129. this.setDead();
  130. }
  131. else
  132. {
  133. this.motionX *= 0.9900000095367432D;
  134. this.motionY *= 0.9900000095367432D;
  135. this.motionZ *= 0.9900000095367432D;
  136.  
  137. if (!this.hasNoGravity())
  138. {
  139. this.motionY -= 0.05999999865889549D;
  140. }
  141.  
  142. this.setPosition(this.posX, this.posY, this.posZ);
  143. }
  144. }
  145.  
  146. /**
  147. * Updates the entity motion clientside, called by packets from the server
  148. */
  149. @SideOnly(Side.CLIENT)
  150. public void setVelocity(double x, double y, double z)
  151. {
  152. this.motionX = x;
  153. this.motionY = y;
  154. this.motionZ = z;
  155.  
  156. if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  157. {
  158. float f = MathHelper.sqrt(x * x + z * z);
  159. this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
  160. this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
  161. this.prevRotationPitch = this.rotationPitch;
  162. this.prevRotationYaw = this.rotationYaw;
  163. this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
  164. }
  165. }
  166.  
  167. @Nullable
  168. private Entity getHitEntity(Vec3d p_190538_1_, Vec3d p_190538_2_)
  169. {
  170. Entity entity = null;
  171. List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
  172. double d0 = 0.0D;
  173.  
  174. for (Entity entity1 : list)
  175. {
  176. if (entity1 != this.owner)
  177. {
  178. AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
  179. RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(p_190538_1_, p_190538_2_);
  180.  
  181. if (raytraceresult != null)
  182. {
  183. double d1 = p_190538_1_.squareDistanceTo(raytraceresult.hitVec);
  184.  
  185. if (d1 < d0 || d0 == 0.0D)
  186. {
  187. entity = entity1;
  188. d0 = d1;
  189. }
  190. }
  191. }
  192. }
  193.  
  194. return entity;
  195. }
  196.  
  197. /**
  198. * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
  199. */
  200. public void shoot(double x, double y, double z, float velocity, float inaccuracy)
  201. {
  202. float f = MathHelper.sqrt(x * x + y * y + z * z);
  203. x = x / (double)f;
  204. y = y / (double)f;
  205. z = z / (double)f;
  206. x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  207. y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  208. z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  209. x = x * (double)velocity;
  210. y = y * (double)velocity;
  211. z = z * (double)velocity;
  212. this.motionX = x;
  213. this.motionY = y;
  214. this.motionZ = z;
  215. float f1 = MathHelper.sqrt(x * x + z * z);
  216. this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
  217. this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
  218. this.prevRotationYaw = this.rotationYaw;
  219. this.prevRotationPitch = this.rotationPitch;
  220. }
  221.  
  222. public void onHit(RayTraceResult p_190536_1_)
  223. {
  224. if (p_190536_1_.entityHit != null && this.owner != null)
  225. {
  226. p_190536_1_.entityHit.attackEntityFrom(DamageSource.causeIndirectDamage(this, this.owner).setProjectile(), 4.0F);
  227.  
  228.  
  229.  
  230. }
  231.  
  232. if (!this.world.isRemote)
  233. {
  234. this.setDead();
  235. }
  236. }
  237.  
  238. protected void entityInit()
  239. {
  240. }
  241.  
  242. /**
  243. * (abstract) Protected helper method to read subclass entity data from NBT.
  244. */
  245. protected void readEntityFromNBT(NBTTagCompound compound)
  246. {
  247. if (compound.hasKey("Owner", 10))
  248. {
  249. this.ownerNbt = compound.getCompoundTag("Owner");
  250. }
  251. }
  252.  
  253. /**
  254. * (abstract) Protected helper method to write subclass entity data to NBT.
  255. */
  256. protected void writeEntityToNBT(NBTTagCompound compound)
  257. {
  258. if (this.owner != null)
  259. {
  260. NBTTagCompound nbttagcompound = new NBTTagCompound();
  261. UUID uuid = this.owner.getUniqueID();
  262. nbttagcompound.setUniqueId("OwnerUUID", uuid);
  263. compound.setTag("Owner", nbttagcompound);
  264. }
  265. }
  266.  
  267. private void restoreOwnerFromSave()
  268. {
  269. if (this.ownerNbt != null && this.ownerNbt.hasUniqueId("OwnerUUID"))
  270. {
  271. UUID uuid = this.ownerNbt.getUniqueId("OwnerUUID");
  272.  
  273. for (EntityCobra entitycobra : this.world.getEntitiesWithinAABB(EntityCobra.class, this.getEntityBoundingBox().grow(15.0D)))
  274. {
  275. if (entitycobra.getUniqueID().equals(uuid))
  276. {
  277. this.owner = entitycobra;
  278. break;
  279. }
  280. }
  281. }
  282.  
  283. this.ownerNbt = null;
  284. }
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement