| 
									
										
										
										
											2021-03-16 09:00:00 +11:00
										 |  |  | --- a/net/minecraft/world/entity/EntityLightning.java
 | 
					
						
							|  |  |  | +++ b/net/minecraft/world/entity/EntityLightning.java
 | 
					
						
							|  |  |  | @@ -22,6 +22,11 @@
 | 
					
						
							|  |  |  |  import net.minecraft.world.level.block.state.IBlockData; | 
					
						
							|  |  |  |  import net.minecraft.world.phys.AxisAlignedBB; | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2021-03-16 09:00:00 +11:00
										 |  |  | +// CraftBukkit start
 | 
					
						
							|  |  |  | +import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect;
 | 
					
						
							|  |  |  | +import org.bukkit.craftbukkit.event.CraftEventFactory;
 | 
					
						
							|  |  |  | +// CraftBukkit end
 | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  | +
 | 
					
						
							| 
									
										
										
										
											2019-04-23 12:00:00 +10:00
										 |  |  |  public class EntityLightning extends Entity { | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  |   | 
					
						
							|  |  |  |      private int lifeTicks; | 
					
						
							| 
									
										
										
										
											2021-03-16 09:00:00 +11:00
										 |  |  | @@ -62,7 +67,24 @@
 | 
					
						
							| 
									
										
										
										
											2020-06-25 10:00:00 +10:00
										 |  |  |                  this.a(4); | 
					
						
							|  |  |  |              } | 
					
						
							| 
									
										
										
										
											2015-02-26 22:41:06 +00:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2019-12-11 09:00:00 +11:00
										 |  |  | -            this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, 10000.0F, 0.8F + this.random.nextFloat() * 0.2F);
 | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  | +            // CraftBukkit start - Use relative location for far away sounds
 | 
					
						
							| 
									
										
										
										
											2019-12-11 09:00:00 +11:00
										 |  |  | +            // this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, 10000.0F, 0.8F + this.random.nextFloat() * 0.2F);
 | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  | +            float pitch = 0.8F + this.random.nextFloat() * 0.2F;
 | 
					
						
							|  |  |  | +            int viewDistance = ((WorldServer) this.world).getServer().getViewDistance() * 16;
 | 
					
						
							| 
									
										
										
										
											2019-04-23 12:00:00 +10:00
										 |  |  | +            for (EntityPlayer player : (List<EntityPlayer>) (List) this.world.getPlayers()) {
 | 
					
						
							| 
									
										
										
										
											2019-12-11 09:00:00 +11:00
										 |  |  | +                double deltaX = this.locX() - player.locX();
 | 
					
						
							|  |  |  | +                double deltaZ = this.locZ() - player.locZ();
 | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  | +                double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
 | 
					
						
							|  |  |  | +                if (distanceSquared > viewDistance * viewDistance) {
 | 
					
						
							|  |  |  | +                    double deltaLength = Math.sqrt(distanceSquared);
 | 
					
						
							| 
									
										
										
										
											2019-12-11 09:00:00 +11:00
										 |  |  | +                    double relativeX = player.locX() + (deltaX / deltaLength) * viewDistance;
 | 
					
						
							|  |  |  | +                    double relativeZ = player.locZ() + (deltaZ / deltaLength) * viewDistance;
 | 
					
						
							|  |  |  | +                    player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, relativeX, this.locY(), relativeZ, 10000.0F, pitch));
 | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  | +                } else {
 | 
					
						
							| 
									
										
										
										
											2019-12-11 09:00:00 +11:00
										 |  |  | +                    player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, this.locX(), this.locY(), this.locZ(), 10000.0F, pitch));
 | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  | +                }
 | 
					
						
							|  |  |  | +            }
 | 
					
						
							|  |  |  | +            // CraftBukkit end
 | 
					
						
							| 
									
										
										
										
											2019-12-11 09:00:00 +11:00
										 |  |  |              this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, SoundCategory.WEATHER, 2.0F, 0.5F + this.random.nextFloat() * 0.2F); | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  |          } | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2021-03-16 09:00:00 +11:00
										 |  |  | @@ -78,7 +100,7 @@
 | 
					
						
							| 
									
										
										
										
											2014-11-26 08:32:16 +11:00
										 |  |  |              } | 
					
						
							|  |  |  |          } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | -        if (this.lifeTicks >= 0) {
 | 
					
						
							|  |  |  | +        if (this.lifeTicks >= 0 && !this.isEffect) { // CraftBukkit - add !this.isEffect
 | 
					
						
							| 
									
										
										
										
											2020-08-12 07:00:00 +10:00
										 |  |  |              if (!(this.world instanceof WorldServer)) { | 
					
						
							| 
									
										
										
										
											2019-04-23 12:00:00 +10:00
										 |  |  |                  this.world.c(2); | 
					
						
							| 
									
										
										
										
											2020-06-25 10:00:00 +10:00
										 |  |  |              } else if (!this.isEffect) { | 
					
						
							| 
									
										
										
										
											2021-03-16 09:00:00 +11:00
										 |  |  | @@ -106,7 +128,11 @@
 | 
					
						
							| 
									
										
										
										
											2020-06-25 10:00:00 +10:00
										 |  |  |              IBlockData iblockdata = BlockFireAbstract.a((IBlockAccess) this.world, blockposition); | 
					
						
							| 
									
										
										
										
											2018-07-15 10:00:00 +10:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2019-04-23 12:00:00 +10:00
										 |  |  |              if (this.world.getType(blockposition).isAir() && iblockdata.canPlace(this.world, blockposition)) { | 
					
						
							| 
									
										
										
										
											2018-07-15 10:00:00 +10:00
										 |  |  | -                this.world.setTypeUpdate(blockposition, iblockdata);
 | 
					
						
							|  |  |  | +                // CraftBukkit start - add "!isEffect"
 | 
					
						
							|  |  |  | +                if (!isEffect && !CraftEventFactory.callBlockIgniteEvent(world, blockposition, this).isCancelled()) {
 | 
					
						
							|  |  |  | +                    this.world.setTypeUpdate(blockposition, iblockdata);
 | 
					
						
							|  |  |  | +                }
 | 
					
						
							|  |  |  | +                // CraftBukkit end
 | 
					
						
							|  |  |  |              } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |              for (int j = 0; j < i; ++j) { | 
					
						
							| 
									
										
										
										
											2021-03-16 09:00:00 +11:00
										 |  |  | @@ -114,7 +140,11 @@
 | 
					
						
							| 
									
										
										
										
											2018-07-15 10:00:00 +10:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2020-06-25 10:00:00 +10:00
										 |  |  |                  iblockdata = BlockFireAbstract.a((IBlockAccess) this.world, blockposition1); | 
					
						
							| 
									
										
										
										
											2018-07-15 10:00:00 +10:00
										 |  |  |                  if (this.world.getType(blockposition1).isAir() && iblockdata.canPlace(this.world, blockposition1)) { | 
					
						
							|  |  |  | -                    this.world.setTypeUpdate(blockposition1, iblockdata);
 | 
					
						
							|  |  |  | +                    // CraftBukkit start - add "!isEffect"
 | 
					
						
							|  |  |  | +                    if (!isEffect && !CraftEventFactory.callBlockIgniteEvent(world, blockposition1, this).isCancelled()) {
 | 
					
						
							|  |  |  | +                        this.world.setTypeUpdate(blockposition1, iblockdata);
 | 
					
						
							|  |  |  | +                    }
 | 
					
						
							|  |  |  | +                    // CraftBukkit end
 | 
					
						
							|  |  |  |                  } | 
					
						
							|  |  |  |              } | 
					
						
							|  |  |  |   |