Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. package fr.elias.eliasgun.common;
  2.  
  3. import net.minecraft.entity.EntityLiving;
  4. import net.minecraft.entity.EntityLivingBase;
  5. import net.minecraft.entity.item.EntityItem;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.entity.projectile.EntityThrowable;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.nbt.NBTTagCompound;
  10. import net.minecraft.util.DamageSource;
  11. import net.minecraft.util.EnumParticleTypes;
  12. import net.minecraft.util.MathHelper;
  13. import net.minecraft.util.MovingObjectPosition;
  14. import net.minecraft.world.Explosion;
  15. import net.minecraft.world.World;
  16.  
  17. public class EntityGrenade extends EntityThrowable implements IGrenade
  18. {
  19. protected String bounceSound;
  20. protected double bounceFactor;
  21. protected double bounceSlowFactor;
  22. protected int fuse;
  23. protected boolean exploded;
  24. protected double initialVelocity;
  25. protected static final int FUSE_LENGTH = 50;
  26. protected static final double MIN_BOUNCE_SOUND_VELOCITY = 0.1D;
  27. public float explosionStrength;
  28.  
  29. public EntityGrenade(World world)
  30. {
  31. super(world);
  32. bounceSound = "eliasguns:grenade.bounce";
  33. bounceFactor = 0.15D;
  34. bounceSlowFactor = 0.8D;
  35. initialVelocity = 1.0D;
  36. setSize(0.25F, 0.25F);
  37. exploded = false;
  38. fuse = 50;
  39. explosionStrength = 3F;
  40. }
  41.  
  42. public EntityGrenade(World world, double d, double d1, double d2)
  43. {
  44. this(world);
  45. setPosition(d, d1, d2);
  46. }
  47.  
  48. public EntityGrenade(World world, EntityLivingBase entityliving)
  49. {
  50. this(world);
  51. //setAngles(entityliving.rotationYaw, 0.0F);
  52. double d = -MathHelper.sin((entityliving.rotationYaw * (float)Math.PI) / 180F);
  53. double d1 = MathHelper.cos((entityliving.rotationYaw * (float)Math.PI) / 180F);
  54. motionX = initialVelocity * d * (double)MathHelper.cos((entityliving.rotationPitch / 180F) * (float)Math.PI);
  55. motionY = -initialVelocity * (double)MathHelper.sin((entityliving.rotationPitch / 180F) * (float)Math.PI);
  56. motionZ = initialVelocity * d1 * (double)MathHelper.cos((entityliving.rotationPitch / 180F) * (float)Math.PI);
  57.  
  58. if (entityliving.ridingEntity != null && (entityliving.ridingEntity instanceof EntityLiving))
  59. {
  60. entityliving = (EntityLiving)entityliving.ridingEntity;
  61. }
  62.  
  63. motionX += entityliving.motionX;
  64. motionY += entityliving.onGround ? 0.0D : entityliving.motionY;
  65. motionZ += entityliving.motionZ;
  66. setPosition(entityliving.posX + d * 0.8D, entityliving.posY + (double)entityliving.getEyeHeight(), entityliving.posZ + d1 * 0.8D);
  67. prevPosX = posX;
  68. prevPosY = posY;
  69. prevPosZ = posZ;
  70. }
  71. public boolean isInRangeToRenderDist(double d)
  72. {
  73. return true;
  74. }
  75. public void onUpdate()
  76. {
  77. double d = motionX;
  78. double d1 = motionY;
  79. double d2 = motionZ;
  80. prevPosX = posX;
  81. prevPosY = posY;
  82. prevPosZ = posZ;
  83. moveEntity(motionX, motionY, motionZ);
  84. boolean flag = false;
  85.  
  86. if (motionX == 0.0D && d != 0.0D)
  87. {
  88. motionX = -bounceFactor * d;
  89. motionY = bounceSlowFactor * d1;
  90. motionZ = bounceSlowFactor * d2;
  91.  
  92. if (Math.abs(d) > 0.1D)
  93. {
  94. flag = true;
  95. }
  96. }
  97.  
  98. if (motionY == 0.0D && d1 != 0.0D)
  99. {
  100. motionX = bounceSlowFactor * d;
  101. motionY = -bounceFactor * d1;
  102. motionZ = bounceSlowFactor * d2;
  103.  
  104. if (Math.abs(d1) > 0.1D)
  105. {
  106. flag = true;
  107. }
  108. }
  109.  
  110. if (motionZ == 0.0D && d2 != 0.0D)
  111. {
  112. motionX = bounceSlowFactor * d;
  113. motionY = bounceSlowFactor * d1;
  114. motionZ = -bounceFactor * d2;
  115.  
  116. if (Math.abs(d2) > 0.1D)
  117. {
  118. flag = true;
  119. }
  120. }
  121.  
  122. if (flag)
  123. {
  124. handleBounce();
  125. }
  126.  
  127. motionY -= 0.04D;
  128. motionX *= 0.99D;
  129. motionY *= 0.99D;
  130. motionZ *= 0.99D;
  131. handleExplode();
  132. }
  133.  
  134. protected void handleBounce()
  135. {
  136. worldObj.playSoundAtEntity(this, bounceSound, 0.25F, 1.0F / (rand.nextFloat() * 0.1F + 0.95F));
  137. }
  138.  
  139. protected void handleExplode()
  140. {
  141. if (fuse-- <= 0)
  142. {
  143. explode();
  144. }
  145. }
  146. protected void explode()
  147. {
  148. if (!exploded)
  149. {
  150. exploded = true;
  151. if(!worldObj.isRemote)
  152. worldObj.createExplosion(this, posX, posY, posZ, explosionStrength, true);
  153.  
  154. for (int i = 0; i < 32; i++)
  155. {
  156. worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, posX, posY, posZ, worldObj.rand.nextDouble() - 0.5D, worldObj.rand.nextDouble() - 0.5D, worldObj.rand.nextDouble() - 0.5D, new int[0]);
  157. worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, posX, posY, posZ, worldObj.rand.nextDouble() - 0.5D, worldObj.rand.nextDouble() - 0.5D, worldObj.rand.nextDouble() - 0.5D, new int[0]);
  158. }
  159.  
  160. isDead = true;
  161. }
  162. }
  163. public boolean canBeCollidedWith()
  164. {
  165. return true;
  166. }
  167.  
  168. public boolean attackEntityFrom(DamageSource damagesource, float i)
  169. {
  170. return false;
  171. }
  172.  
  173. public void writeEntityToNBT(NBTTagCompound nbttagcompound)
  174. {
  175. super.writeEntityToNBT(nbttagcompound);
  176. nbttagcompound.setByte("Fuse", (byte)fuse);
  177. }
  178.  
  179. /**
  180. * (abstract) Protected helper method to read subclass entity data from NBT.
  181. */
  182. public void readEntityFromNBT(NBTTagCompound nbttagcompound)
  183. {
  184. super.readEntityFromNBT(nbttagcompound);
  185. fuse = nbttagcompound.getByte("Fuse");
  186. }
  187.  
  188. public void onCollideWithPlayer(EntityPlayer entityplayer)
  189. {
  190. }
  191.  
  192. public float getEyeHeight()
  193. {
  194. return height;
  195. }
  196.  
  197. @Override
  198. protected void onImpact(MovingObjectPosition p_70184_1_) {
  199. // TODO Auto-generated method stub
  200.  
  201. }
  202.  
  203. @Override
  204. public EnumGrenadeType getGrenadeType() {
  205. // TODO Auto-generated method stub
  206. return EnumGrenadeType.FRAG;
  207. }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement