Advertisement
Guest User

Fire Explosion

a guest
May 13th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.53 KB | None | 0 0
  1. public class AvatarFireExplosion extends Explosion {
  2. /** whether or not the explosion sets fire to blocks around it */
  3. private final boolean causesFire;
  4. /** whether or not this explosion spawns smoke particles */
  5. private final boolean damagesTerrain;
  6. private final Random random;
  7. private final World world;
  8. private final double x;
  9. private final double y;
  10. private final double z;
  11. private final Entity exploder;
  12. private final float size;
  13. /** A list of ChunkPositions of blocks affected by this explosion */
  14. private final List<BlockPos> affectedBlockPositions;
  15. /** Maps players to the knockback vector applied by the explosion, to send to the client */
  16. private final Map<EntityPlayer, Vec3d> playerKnockbackMap;
  17. private final Vec3d position;
  18.  
  19. public AvatarFireExplosion(World worldIn, Entity entityIn, double x, double y, double z, float size, boolean flaming, boolean damagesTerrain) {
  20. super(worldIn, entityIn, x, y, z, size, true, false);
  21. this.random = new Random();
  22. this.affectedBlockPositions = Lists.newArrayList();
  23. this.playerKnockbackMap = Maps.newHashMap();
  24. this.world = worldIn;
  25. this.exploder = entityIn;
  26. this.size = size;
  27. this.x = x;
  28. this.y = y;
  29. this.z = z;
  30. this.causesFire = flaming;
  31. this.damagesTerrain = damagesTerrain;
  32. this.position = new Vec3d(this.x, this.y, this.z);
  33. }
  34.  
  35. @Override
  36. public void doExplosionB(boolean spawnParticles)
  37. {
  38. this.world.playSound(null, this.x, this.y, this.z, SoundEvents.ENTITY_BLAZE_DEATH, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.world.rand.nextFloat() - this.world.rand.nextFloat()) * 0.2F) * 0.7F);
  39.  
  40. if (this.size >= 2.0F && this.damagesTerrain) {
  41. this.world.spawnParticle(EnumParticleTypes.FLAME, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
  42. }
  43. else
  44. {
  45. this.world.spawnParticle(EnumParticleTypes.FLAME, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
  46. }
  47.  
  48. if (this.damagesTerrain)
  49. {
  50. for (BlockPos blockpos : this.affectedBlockPositions)
  51. {
  52. IBlockState iblockstate = this.world.getBlockState(blockpos);
  53. Block block = iblockstate.getBlock();
  54.  
  55. if (spawnParticles)
  56. {
  57. double d0 = (double)((float)blockpos.getX() + this.world.rand.nextFloat());
  58. double d1 = (double)((float)blockpos.getY() + this.world.rand.nextFloat());
  59. double d2 = (double)((float)blockpos.getZ() + this.world.rand.nextFloat());
  60. double d3 = d0 - this.x;
  61. double d4 = d1 - this.y;
  62. double d5 = d2 - this.z;
  63. double d6 = (double)MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
  64. d3 = d3 / d6;
  65. d4 = d4 / d6;
  66. d5 = d5 / d6;
  67. double d7 = 0.5D / (d6 / (double)this.size + 0.1D);
  68. d7 = d7 * (double)(this.world.rand.nextFloat() * this.world.rand.nextFloat() + 0.3F);
  69. d3 = d3 * d7;
  70. d4 = d4 * d7;
  71. d5 = d5 * d7;
  72. this.world.spawnParticle(EnumParticleTypes.LAVA, (d0 + this.x) / 2.0D, (d1 + this.y) / 2.0D, (d2 + this.z) / 2.0D, d3, d4, d5);
  73. this.world.spawnParticle(EnumParticleTypes.FLAME, d0, d1, d2, d3, d4, d5);
  74. }
  75.  
  76. if (iblockstate.getMaterial() != Material.AIR)
  77. {
  78. if (block.canDropFromExplosion(this))
  79. {
  80. block.dropBlockAsItemWithChance(this.world, blockpos, this.world.getBlockState(blockpos), 1.0F / this.size, 0);
  81. }
  82.  
  83. block.onBlockExploded(this.world, blockpos, this);
  84. }
  85. }
  86. }
  87.  
  88. if (this.causesFire)
  89. {
  90. for (BlockPos blockpos1 : this.affectedBlockPositions)
  91. {
  92. if (this.world.getBlockState(blockpos1).getMaterial() == Material.AIR && this.world.getBlockState(blockpos1.down()).isFullBlock() && this.random.nextInt(3) == 0)
  93. {
  94. this.world.setBlockState(blockpos1, Blocks.FIRE.getDefaultState());
  95. }
  96. }
  97. }
  98. }
  99.  
  100. @Override
  101. public void doExplosionA() {
  102. Set<BlockPos> set = Sets.newHashSet();
  103. int i = 16;
  104.  
  105. for (int j = 0; j < 16; ++j) {
  106. for (int k = 0; k < 16; ++k) {
  107. for (int l = 0; l < 16; ++l) {
  108. if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
  109. double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
  110. double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
  111. double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
  112. double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
  113. d0 = d0 / d3;
  114. d1 = d1 / d3;
  115. d2 = d2 / d3;
  116. float f = this.size * (0.7F + this.world.rand.nextFloat() * 0.6F);
  117. double d4 = this.x;
  118. double d6 = this.y;
  119. double d8 = this.z;
  120.  
  121. for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
  122. BlockPos blockpos = new BlockPos(d4, d6, d8);
  123. IBlockState iblockstate = this.world.getBlockState(blockpos);
  124.  
  125. if (iblockstate.getMaterial() != Material.AIR) {
  126. float f2 = this.exploder != null ? this.exploder.getExplosionResistance(this, this.world, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(world, blockpos, null, this);
  127. f -= (f2 + 0.3F) * 0.3F;
  128. }
  129.  
  130. if (f > 0.0F && (this.exploder == null || this.exploder.canExplosionDestroyBlock(this, this.world, blockpos, iblockstate, f))) {
  131. set.add(blockpos);
  132. }
  133.  
  134. d4 += d0 * 0.30000001192092896D;
  135. d6 += d1 * 0.30000001192092896D;
  136. d8 += d2 * 0.30000001192092896D;
  137. }
  138. }
  139. }
  140. }
  141. }
  142.  
  143. this.affectedBlockPositions.addAll(set);
  144. float f3 = this.size * 2.0F;
  145. int k1 = MathHelper.floor(this.x - (double) f3 - 1.0D);
  146. int l1 = MathHelper.floor(this.x + (double) f3 + 1.0D);
  147. int i2 = MathHelper.floor(this.y - (double) f3 - 1.0D);
  148. int i1 = MathHelper.floor(this.y + (double) f3 + 1.0D);
  149. int j2 = MathHelper.floor(this.z - (double) f3 - 1.0D);
  150. int j1 = MathHelper.floor(this.z + (double) f3 + 1.0D);
  151. List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
  152. net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.world, this, list, f3);
  153. Vec3d vec3d = new Vec3d(this.x, this.y, this.z);
  154.  
  155. for (Entity entity : list) {
  156. if (!entity.isImmuneToExplosions()) {
  157. double d12 = entity.getDistance(this.x, this.y, this.z) / (double) f3;
  158.  
  159. if (d12 <= 1.0D) {
  160. double d5 = entity.posX - this.x;
  161. double d7 = entity.posY + (double) entity.getEyeHeight() - this.y;
  162. double d9 = entity.posZ - this.z;
  163. double d13 = (double) MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
  164.  
  165. if (d13 != 0.0D) {
  166. d5 = d5 / d13;
  167. d7 = d7 / d13;
  168. d9 = d9 / d13;
  169. double d14 = (double) this.world.getBlockDensity(vec3d, entity.getEntityBoundingBox());
  170. double d10 = (1.0D - d12) * d14;
  171. entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), 4F);
  172. double d11 = d10;
  173.  
  174. if (entity instanceof EntityLivingBase) {
  175. d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase) entity, d10);
  176. }
  177.  
  178. entity.motionX += d5 * d11;
  179. entity.motionY += d7 * d11;
  180. entity.motionZ += d9 * d11;
  181.  
  182. if (entity instanceof EntityPlayer) {
  183. EntityPlayer entityplayer = (EntityPlayer) entity;
  184.  
  185. if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.capabilities.isFlying)) {
  186. this.playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194.  
  195. @Override
  196. public void clearAffectedBlockPositions()
  197. {
  198. this.affectedBlockPositions.clear();
  199. }
  200.  
  201. @Override
  202. public List<BlockPos> getAffectedBlockPositions()
  203. {
  204. return this.affectedBlockPositions;
  205. }
  206.  
  207. @Override
  208. public Vec3d getPosition(){ return this.position; }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement