SparkyFox95

EntitySMGRounds

Feb 26th, 2017
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. [ENTITY SMG]
  2. package mod.sparkyfox.servermod.entity;
  3.  
  4. import javax.annotation.Nonnull;
  5.  
  6. import mod.sparkyfox.servermod.init.ModItems;
  7. import mod.sparkyfox.servermod.init.ModSoundEvent;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.block.state.IBlockState;
  11. import net.minecraft.entity.Entity;
  12. import net.minecraft.entity.EntityLivingBase;
  13. import net.minecraft.entity.monster.EntityEnderman;
  14. import net.minecraft.entity.player.EntityPlayer;
  15. import net.minecraft.entity.projectile.EntityArrow;
  16. import net.minecraft.init.SoundEvents;
  17. import net.minecraft.item.ItemStack;
  18. import net.minecraft.network.datasync.DataParameter;
  19. import net.minecraft.network.datasync.DataSerializers;
  20. import net.minecraft.network.datasync.EntityDataManager;
  21. import net.minecraft.util.EnumParticleTypes;
  22. import net.minecraft.util.math.AxisAlignedBB;
  23. import net.minecraft.util.math.BlockPos;
  24. import net.minecraft.util.math.MathHelper;
  25. import net.minecraft.util.math.RayTraceResult;
  26. import net.minecraft.util.math.Vec3d;
  27. import net.minecraft.world.World;
  28.  
  29. public class EntitySMGRounds extends EntityArrow {
  30.  
  31. private EnumParticleTypes particle;
  32. //added by me\\
  33. private static final DataParameter<Byte> CRITICAL = EntityDataManager.<Byte>createKey(EntityArrow.class, DataSerializers.BYTE);
  34. private int xTile;
  35. private int yTile;
  36. private int zTile;
  37. private Block inTile;
  38. private int inData;
  39. protected boolean inGround;
  40. protected int timeInGround;
  41. /** 1 if the player can pick up the arrow */
  42. public EntityArrow.PickupStatus pickupStatus;
  43. /** Seems to be some sort of timer for animating an arrow. */
  44. public int arrowShake;
  45. /** The owner of this arrow. */
  46. public Entity shootingEntity;
  47. private int ticksInGround;
  48. private int ticksInAir;
  49. private double damage;
  50. /** The amount of knockback an arrow applies when it hits a mob. */
  51. private int knockbackStrength;
  52. //added by me\\
  53.  
  54. public EntitySMGRounds(World worldIn) {
  55. super(worldIn);
  56. this.pickupStatus = EntitySMGRounds.PickupStatus.DISALLOWED;
  57. this.setSize(0.5F, 0.5F);
  58. }
  59. //
  60. public EntitySMGRounds(World worldIn, EntityLivingBase shooter) {
  61. super(worldIn, shooter);
  62. //
  63. {
  64. this.shootingEntity = shooter;
  65.  
  66. if (shooter instanceof EntityPlayer)
  67. {
  68. this.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
  69. }
  70. }
  71. //
  72. }
  73.  
  74. public EntitySMGRounds(World worldIn, double x, double y, double z) {
  75. super(worldIn, x, y, z);
  76.  
  77. }
  78.  
  79. @Override
  80. public void setDamage(double damageIn) {
  81. super.setDamage(4.5D);
  82. }
  83.  
  84. @Override
  85. public void onUpdate() {
  86. super.onUpdate();
  87. if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  88. {
  89. float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  90. this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
  91. this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI));
  92. this.prevRotationYaw = this.rotationYaw;
  93. this.prevRotationPitch = this.rotationPitch;
  94. }
  95.  
  96. BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
  97. IBlockState iblockstate = this.world.getBlockState(blockpos);
  98. Block block = iblockstate.getBlock();
  99.  
  100. if (iblockstate.getMaterial() != Material.AIR)
  101. {
  102. AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
  103.  
  104. if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).isVecInside(new Vec3d(this.posX, this.posY, this.posZ)))
  105. {
  106. this.inGround = true;
  107. }
  108. }
  109.  
  110. if (this.arrowShake > 0)
  111. {
  112. --this.arrowShake;
  113. }
  114.  
  115. if (this.inGround)
  116. {
  117. int j = block.getMetaFromState(iblockstate);
  118.  
  119. if ((block != this.inTile || j != this.inData) && !this.world.collidesWithAnyBlock(this.getEntityBoundingBox().expandXyz(0.05D)))
  120. {
  121. this.inGround = false;
  122. this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
  123. this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
  124. this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
  125. this.ticksInGround = 0;
  126. this.ticksInAir = 0;
  127. }
  128. else
  129. {
  130. ++this.ticksInGround;
  131.  
  132. if (this.ticksInGround >= 1200)
  133. {
  134. this.setDead();
  135. }
  136. }
  137.  
  138. ++this.timeInGround;
  139.  
  140. }
  141. }
  142.  
  143.  
  144.  
  145.  
  146. /**
  147. * Called when the arrow hits a block or an entity
  148. */
  149. protected void onHit(RayTraceResult raytraceResultIn) {
  150. super.onHit(raytraceResultIn);
  151. this.playSound(ModSoundEvent.impact, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  152.  
  153. Entity entity = raytraceResultIn.entityHit;
  154.  
  155. if (entity != null)
  156. {
  157. float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  158. int i = MathHelper.ceil((double)f * this.damage);
  159.  
  160. if (this.getIsCritical())
  161. {
  162. i += this.rand.nextInt(i / 2 + 2);
  163. }
  164. }
  165. }
  166.  
  167.  
  168.  
  169. @Override
  170. @Nonnull
  171. public ItemStack getArrowStack() {
  172. return new ItemStack(ModItems.SMGRounds);
  173. }
  174.  
  175. @Override
  176. public void arrowHit(EntityLivingBase living) {
  177. super.arrowHit(living);
  178. this.playSound(ModSoundEvent.impact, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));//
  179.  
  180.  
  181.  
  182. //added by me\\
  183.  
  184. }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment