Guest User

Lightning

a guest
May 7th, 2016
169
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.minecraft.entity.effect;
  2.  
  3. import java.util.List;
  4. import net.minecraft.block.material.Material;
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.init.Blocks;
  8. import net.minecraft.nbt.NBTTagCompound;
  9. import net.minecraft.util.AxisAlignedBB;
  10. import net.minecraft.util.BlockPos;
  11. import net.minecraft.util.ChatComponentText;
  12. import net.minecraft.world.EnumDifficulty;
  13. import net.minecraft.world.World;
  14.  
  15. public class EntityLightningBolt extends EntityWeatherEffect
  16. {
  17. /**
  18. * Declares which state the lightning bolt is in. Whether it's in the air, hit the ground, etc.
  19. */
  20. private int lightningState;
  21.  
  22. /**
  23. * A random long that is used to change the vertex of the lightning rendered in RenderLightningBolt
  24. */
  25. public long boltVertex;
  26.  
  27. /**
  28. * Determines the time before the EntityLightningBolt is destroyed. It is a random integer decremented over time.
  29. */
  30. private int boltLivingTime;
  31. private static final String __OBFID = "CL_00001666";
  32.  
  33. public static void addMessage(String msg) {
  34. Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(msg));
  35. }
  36.  
  37. public EntityLightningBolt(World worldIn, double p_i1703_2_, double p_i1703_4_, double p_i1703_6_)
  38. {
  39. super(worldIn);
  40. this.setLocationAndAngles(p_i1703_2_, p_i1703_4_, p_i1703_6_, 0.0F, 0.0F);
  41. this.lightningState = 2;
  42. this.boltVertex = this.rand.nextLong();
  43. this.boltLivingTime = this.rand.nextInt(3) + 1;
  44.  
  45. if (!worldIn.isRemote && worldIn.getGameRules().getGameRuleBooleanValue("doFireTick") && (worldIn.getDifficulty() == EnumDifficulty.NORMAL || worldIn.getDifficulty() == EnumDifficulty.HARD) && worldIn.isAreaLoaded(new BlockPos(this), 10))
  46. {
  47. BlockPos var8 = new BlockPos(this);
  48.  
  49. if (worldIn.getBlockState(var8).getBlock().getMaterial() == Material.air && Blocks.fire.canPlaceBlockAt(worldIn, var8))
  50. {
  51. worldIn.setBlockState(var8, Blocks.fire.getDefaultState());
  52. }
  53.  
  54. for (int var9 = 0; var9 < 4; ++var9)
  55. {
  56. BlockPos var10 = var8.add(this.rand.nextInt(3) - 1, this.rand.nextInt(3) - 1, this.rand.nextInt(3) - 1);
  57.  
  58. if (worldIn.getBlockState(var10).getBlock().getMaterial() == Material.air && Blocks.fire.canPlaceBlockAt(worldIn, var10))
  59. {
  60. worldIn.setBlockState(var10, Blocks.fire.getDefaultState());
  61. }
  62. }
  63. }
  64. }
  65.  
  66. /**
  67. * Called to update the entity's position/logic.
  68. */
  69. public void onUpdate()
  70. {
  71. super.onUpdate();
  72.  
  73. if (this.lightningState == 2)
  74. {
  75. this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "ambient.weather.thunder", 10000.0F, 0.8F + this.rand.nextFloat() * 0.2F);
  76. this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "random.explode", 2.0F, 0.5F + this.rand.nextFloat() * 0.2F);
  77.  
  78. addMessage("\2477Lightning Struck ]-"+" \2477X: \247c"+this.posX+" \2477Y: \247c"+this.posY+" \2477Z: \247c"+this.posZ);
  79. }
  80.  
  81. --this.lightningState;
  82.  
  83. if (this.lightningState < 0)
  84. {
  85. if (this.boltLivingTime == 0)
  86. {
  87. this.setDead();
  88. }
  89. else if (this.lightningState < -this.rand.nextInt(10))
  90. {
  91. --this.boltLivingTime;
  92. this.lightningState = 1;
  93. this.boltVertex = this.rand.nextLong();
  94. BlockPos var1 = new BlockPos(this);
  95.  
  96. if (!this.worldObj.isRemote && this.worldObj.getGameRules().getGameRuleBooleanValue("doFireTick") && this.worldObj.isAreaLoaded(var1, 10) && this.worldObj.getBlockState(var1).getBlock().getMaterial() == Material.air && Blocks.fire.canPlaceBlockAt(this.worldObj, var1))
  97. {
  98. this.worldObj.setBlockState(var1, Blocks.fire.getDefaultState());
  99. }
  100. }
  101. }
  102.  
  103. if (this.lightningState >= 0)
  104. {
  105. if (this.worldObj.isRemote)
  106. {
  107. this.worldObj.setLastLightningBolt(2);
  108. }
  109. else
  110. {
  111. double var6 = 3.0D;
  112. List var3 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, new AxisAlignedBB(this.posX - var6, this.posY - var6, this.posZ - var6, this.posX + var6, this.posY + 6.0D + var6, this.posZ + var6));
  113.  
  114. for (int var4 = 0; var4 < var3.size(); ++var4)
  115. {
  116. Entity var5 = (Entity)var3.get(var4);
  117. var5.onStruckByLightning(this);
  118. }
  119. }
  120. }
  121. }
  122.  
  123. protected void entityInit() {}
  124.  
  125. /**
  126. * (abstract) Protected helper method to read subclass entity data from NBT.
  127. */
  128. protected void readEntityFromNBT(NBTTagCompound tagCompund) {}
  129.  
  130. /**
  131. * (abstract) Protected helper method to write subclass entity data to NBT.
  132. */
  133. protected void writeEntityToNBT(NBTTagCompound tagCompound) {}
  134. }
RAW Paste Data