PageRenderTime 26ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/valentin4311/candycraftmod/entity/EntityGummyBall.java

https://gitlab.com/valentin4311/CandyCraft
Java | 261 lines | 233 code | 28 blank | 0 comment | 53 complexity | 27565420ab966acec13457d85c3f7472 MD5 | raw file
  1. package com.valentin4311.candycraftmod.entity;
  2. import com.valentin4311.candycraftmod.client.entity.EntityBreakingParticleFX;
  3. import com.valentin4311.candycraftmod.entity.boss.EntityBossBeetle;
  4. import com.valentin4311.candycraftmod.items.CCItems;
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.particle.ParticleBreaking;
  7. import net.minecraft.entity.EntityLivingBase;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.entity.projectile.EntityThrowable;
  10. import net.minecraft.init.MobEffects;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.potion.PotionEffect;
  13. import net.minecraft.util.DamageSource;
  14. import net.minecraft.util.EnumParticleTypes;
  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. public class EntityGummyBall extends EntityThrowable
  22. {
  23. public int airState = 0;
  24. public EntityPlayer target = null;
  25. public EntityBossBeetle beetle = null;
  26. public EntityGummyBall(World par1World)
  27. {
  28. super(par1World);
  29. setSize(0.45F, 0.45F);
  30. }
  31. public EntityGummyBall(World par1World, double par2, double par4, double par6)
  32. {
  33. super(par1World, par2, par4, par6);
  34. }
  35. public EntityGummyBall(World par1World, EntityLivingBase par2EntityLivingBase, int power)
  36. {
  37. super(par1World, par2EntityLivingBase);
  38. setLocationAndAngles(par2EntityLivingBase.posX, par2EntityLivingBase.posY + par2EntityLivingBase.getEyeHeight(), par2EntityLivingBase.posZ, par2EntityLivingBase.rotationYaw, par2EntityLivingBase.rotationPitch);
  39. setPowerful(power);
  40. float r = rand.nextFloat() / 20 - 0.05F;
  41. float r2 = rand.nextFloat() / 20 - 0.05F;
  42. if (getPowerful() == 0 || getPowerful() == 3)
  43. {
  44. r = 0;
  45. r2 = 0;
  46. }
  47. setSize(0.25F, 0.25F);
  48. setLocationAndAngles(par2EntityLivingBase.posX, par2EntityLivingBase.posY + par2EntityLivingBase.getEyeHeight(), par2EntityLivingBase.posZ, par2EntityLivingBase.rotationYaw, par2EntityLivingBase.rotationPitch);
  49. posX -= MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * 0.16F;
  50. posY -= 0.10000000149011612D;
  51. posZ -= MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * 0.16F;
  52. setPosition(posX, posY, posZ);
  53. float f = getPowerful() == 3 ? 0.002F : 0.4F;
  54. motionX = -MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f;
  55. motionZ = MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f;
  56. motionY = -MathHelper.sin((rotationPitch + this.getInaccuracy()) / 180.0F * (float) Math.PI) * f;
  57. setThrowableHeading(motionX + r, motionY, motionZ + r2, getVelocity(), 1.0F);
  58. }
  59. public void setPowerful(int i)
  60. {
  61. dataWatcher.updateObject(16, i);
  62. }
  63. public int getPowerful()
  64. {
  65. return dataWatcher.getWatchableObjectInt(16);
  66. }
  67. @Override
  68. public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
  69. {
  70. super.writeEntityToNBT(par1NBTTagCompound);
  71. par1NBTTagCompound.setInteger("power", getPowerful());
  72. par1NBTTagCompound.setInteger("airState", airState);
  73. }
  74. @Override
  75. public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
  76. {
  77. super.readEntityFromNBT(par1NBTTagCompound);
  78. setPowerful(par1NBTTagCompound.getInteger("power"));
  79. airState = par1NBTTagCompound.getInteger("airState");
  80. }
  81. @Override
  82. protected float getVelocity()
  83. {
  84. return getPowerful() == 3 || airState == 3 ? 0.8F : 1.5F;
  85. }
  86. @Override
  87. public boolean canBeCollidedWith()
  88. {
  89. return true;
  90. }
  91. @Override
  92. public float getCollisionBorderSize()
  93. {
  94. return 1.0F;
  95. }
  96. @Override
  97. public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_)
  98. {
  99. if (getPowerful() != 3)
  100. {
  101. return false;
  102. }
  103. else
  104. {
  105. setBeenAttacked();
  106. if (p_70097_1_.getEntity() != null)
  107. {
  108. Vec3d vec3 = p_70097_1_.getEntity().getLookVec();
  109. if (vec3 != null)
  110. {
  111. motionX = vec3.xCoord;
  112. motionY = vec3.yCoord;
  113. motionZ = vec3.zCoord;
  114. }
  115. return true;
  116. }
  117. else
  118. {
  119. return false;
  120. }
  121. }
  122. }
  123. @Override
  124. protected float getGravityVelocity()
  125. {
  126. return airState == 1 ? 0.05F : (getPowerful() == 2 || getPowerful() == 3) && !inWater ? 0.03F : 0.03F;
  127. }
  128. @Override
  129. public void entityInit()
  130. {
  131. dataWatcher.addObject(16, Integer.valueOf(0));
  132. }
  133. @Override
  134. public void onUpdate()
  135. {
  136. super.onUpdate();
  137. if (worldObj.isRemote && getPowerful() == 1)
  138. {
  139. spawnParticle();
  140. }
  141. if (worldObj.isRemote && getPowerful() == 2)
  142. {
  143. spawnParticle2();
  144. }
  145. if (worldObj.isRemote && getPowerful() == 3)
  146. {
  147. spawnParticle3();
  148. }
  149. }
  150. @Override
  151. public void setThrowableHeading(double par1, double par3, double par5, float par7, float par8)
  152. {
  153. float f2 = MathHelper.sqrt_double(par1 * par1 + par3 * par3 + par5 * par5);
  154. par1 /= f2;
  155. par3 /= f2;
  156. par5 /= f2;
  157. if (getPowerful() > 0 && getPowerful() != 3)
  158. {
  159. par1 += rand.nextGaussian() * 0.007499999832361937D * par8;
  160. par3 += rand.nextGaussian() * 0.007499999832361937D * par8;
  161. par5 += rand.nextGaussian() * 0.007499999832361937D * par8;
  162. }
  163. par1 *= par7;
  164. par3 *= par7;
  165. par5 *= par7;
  166. motionX = par1;
  167. motionY = par3;
  168. motionZ = par5;
  169. float f3 = MathHelper.sqrt_double(par1 * par1 + par5 * par5);
  170. prevRotationYaw = rotationYaw = (float) (Math.atan2(par1, par5) * 180.0D / Math.PI);
  171. prevRotationPitch = rotationPitch = (float) (Math.atan2(par3, f3) * 180.0D / Math.PI);
  172. }
  173. @Override
  174. protected void onImpact(RayTraceResult par1MovingObjectPosition)
  175. {
  176. if (par1MovingObjectPosition.entityHit != null && par1MovingObjectPosition.entityHit instanceof EntityLivingBase)
  177. {
  178. float b0 = getPowerful() == 1 ? 6 : getPowerful() == 2 ? 4 : 0.1F;
  179. par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, getThrower()), b0);
  180. if (par1MovingObjectPosition.entityHit instanceof EntityLivingBase && getPowerful() < 2)
  181. {
  182. ((EntityLivingBase) par1MovingObjectPosition.entityHit).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 5 * 20, 2));
  183. }
  184. else if (getPowerful() == 2)
  185. {
  186. ((EntityLivingBase) par1MovingObjectPosition.entityHit).setFire(7);
  187. }
  188. else if (!(par1MovingObjectPosition.entityHit instanceof EntityBossBeetle))
  189. {
  190. float f4 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  191. par1MovingObjectPosition.entityHit.addVelocity(motionX * 1 * 0.6000000238418579D / f4, 0.1D, motionZ * 1 * 0.6000000238418579D / f4);
  192. }
  193. setDead();
  194. }
  195. for (int i = 0; i < 8; ++i)
  196. {
  197. if (worldObj.isRemote && getPowerful() < 2)
  198. {
  199. spawnParticle();
  200. }
  201. if (worldObj.isRemote && getPowerful() == 2)
  202. {
  203. spawnParticle2();
  204. }
  205. if (worldObj.isRemote && getPowerful() == 3)
  206. {
  207. spawnParticle3();
  208. }
  209. }
  210. if (!worldObj.isRemote)
  211. {
  212. setDead();
  213. }
  214. }
  215. @SideOnly(Side.CLIENT)
  216. public void spawnParticle()
  217. {
  218. ParticleBreaking fx = new EntityBreakingParticleFX(worldObj, posX, posY, posZ, CCItems.gummyBall);
  219. Minecraft.getMinecraft().effectRenderer.addEffect(fx);
  220. }
  221. @SideOnly(Side.CLIENT)
  222. public void spawnParticle2()
  223. {
  224. worldObj.spawnParticle(EnumParticleTypes.FLAME, posX - 0.5F + rand.nextDouble(), posY - 0.5F + rand.nextDouble(), posZ - 0.5F + rand.nextDouble(), 0.0F, 0.0F, 0.0F);
  225. }
  226. @SideOnly(Side.CLIENT)
  227. public void spawnParticle3()
  228. {
  229. ParticleBreaking fx = new EntityBreakingParticleFX(worldObj, posX, posY, posZ, CCItems.gummyBall);
  230. fx.setParticleTexture(Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getParticleIcon(CCItems.gummyBall, 2));
  231. Minecraft.getMinecraft().effectRenderer.addEffect(fx);
  232. }
  233. }