From 20515a30aed143711bb4ceae48f121e63ca401ed Mon Sep 17 00:00:00 2001 From: Trigary Date: Fri, 14 Sep 2018 17:49:25 +0200 Subject: [PATCH] Limit lightning strike effect distance Resolves GH-1436 --- ...6-Ability-to-apply-mending-to-XP-API.patch | 6 +- .../0077-PreCreatureSpawnEvent.patch | 4 +- ...mit-lightning-strike-effect-distance.patch | 84 +++++++++++++++++++ 3 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 Spigot-Server-Patches/0393-Limit-lightning-strike-effect-distance.patch diff --git a/Spigot-API-Patches/0076-Ability-to-apply-mending-to-XP-API.patch b/Spigot-API-Patches/0076-Ability-to-apply-mending-to-XP-API.patch index 81c48b95e..1681f6c1e 100644 --- a/Spigot-API-Patches/0076-Ability-to-apply-mending-to-XP-API.patch +++ b/Spigot-API-Patches/0076-Ability-to-apply-mending-to-XP-API.patch @@ -1,4 +1,4 @@ -From 94d01f18abd3ce6e565c4165501d4f870372a909 Mon Sep 17 00:00:00 2001 +From 2b5c8b0903e0f3215a5e5e1aa3aa29fff18e5cf4 Mon Sep 17 00:00:00 2001 From: Aikar Date: Wed, 20 Dec 2017 17:38:07 -0500 Subject: [PATCH] Ability to apply mending to XP API @@ -10,7 +10,7 @@ of giving the player experience points. Both an API To standalone mend, and apply mending logic to .giveExp has been added. diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java -index 2e71054d6..fd359fe0b 100644 +index 2e71054d..fd359fe0 100644 --- a/src/main/java/org/bukkit/entity/Player.java +++ b/src/main/java/org/bukkit/entity/Player.java @@ -953,12 +953,33 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline @@ -49,5 +49,5 @@ index 2e71054d6..fd359fe0b 100644 /** * Gives the player the amount of experience levels specified. Levels can -- -2.18.0 +2.16.1.windows.4 diff --git a/Spigot-API-Patches/0077-PreCreatureSpawnEvent.patch b/Spigot-API-Patches/0077-PreCreatureSpawnEvent.patch index 2c1a5b489..591fa11db 100644 --- a/Spigot-API-Patches/0077-PreCreatureSpawnEvent.patch +++ b/Spigot-API-Patches/0077-PreCreatureSpawnEvent.patch @@ -1,4 +1,4 @@ -From ed685ade98b7c91a16ea129ed517a8739cdb63d5 Mon Sep 17 00:00:00 2001 +From b6f0cd76a70adc45822cfe0588077b30e999c2d2 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 14 Jan 2018 16:59:43 -0500 Subject: [PATCH] PreCreatureSpawnEvent @@ -119,5 +119,5 @@ index 00000000..bac1cef3 + } +} -- -2.18.0 +2.16.1.windows.4 diff --git a/Spigot-Server-Patches/0393-Limit-lightning-strike-effect-distance.patch b/Spigot-Server-Patches/0393-Limit-lightning-strike-effect-distance.patch new file mode 100644 index 000000000..665f8f93e --- /dev/null +++ b/Spigot-Server-Patches/0393-Limit-lightning-strike-effect-distance.patch @@ -0,0 +1,84 @@ +From 9562e7d3f00411e9426c18af31edd06e519a1ed3 Mon Sep 17 00:00:00 2001 +From: Trigary +Date: Fri, 14 Sep 2018 17:42:08 +0200 +Subject: [PATCH] Limit lightning strike effect distance + + +diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +index 93bf8c6d3..25246eac5 100644 +--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java ++++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +@@ -237,6 +237,30 @@ public class PaperWorldConfig { + skeleHorseSpawnChance = 0.01D; // Vanilla value + } + } ++ ++ public double sqrMaxLightningSoundDistance; ++ public double sqrMaxLightningImpactSoundDistance; ++ public double maxLightningFlashDistance; ++ private void lightningStrikeDistanceLimit() { ++ sqrMaxLightningSoundDistance = getInt("lightning-strike-distance-limit.sound", -1); ++ if (sqrMaxLightningSoundDistance < 0) { ++ sqrMaxLightningSoundDistance = Double.MAX_VALUE; ++ } else { ++ sqrMaxLightningSoundDistance *= sqrMaxLightningSoundDistance; ++ } ++ ++ sqrMaxLightningImpactSoundDistance = getInt("lightning-strike-distance-limit.impact-sound", -1); ++ if (sqrMaxLightningImpactSoundDistance < 0) { ++ sqrMaxLightningImpactSoundDistance = 32 * 32; //Vanilla value ++ } else { ++ sqrMaxLightningImpactSoundDistance *= sqrMaxLightningImpactSoundDistance; ++ } ++ ++ maxLightningFlashDistance = getInt("lightning-strike-distance-limit.flash", -1); ++ if (maxLightningFlashDistance < 0) { ++ maxLightningFlashDistance = 512; // Vanilla value ++ } ++ } + + public boolean firePhysicsEventForRedstone = false; + private void firePhysicsEventForRedstone() { +diff --git a/src/main/java/net/minecraft/server/EntityLightning.java b/src/main/java/net/minecraft/server/EntityLightning.java +index afbe43dd3..b7e88d346 100644 +--- a/src/main/java/net/minecraft/server/EntityLightning.java ++++ b/src/main/java/net/minecraft/server/EntityLightning.java +@@ -60,6 +60,13 @@ public class EntityLightning extends EntityWeather { + double deltaX = this.locX - player.locX; + double deltaZ = this.locZ - player.locZ; + double distanceSquared = deltaX * deltaX + deltaZ * deltaZ; ++ // Paper start - Limit lightning strike effect distance ++ if (distanceSquared < this.world.paperConfig.sqrMaxLightningImpactSoundDistance) { ++ player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, ++ SoundCategory.WEATHER, this.locX, this.locY, this.locZ, 2.0f, 0.5F + this.random.nextFloat() * 0.2F)); ++ } ++ if (distanceSquared > this.world.paperConfig.sqrMaxLightningSoundDistance) continue; ++ // Paper end + if (distanceSquared > viewDistance * viewDistance) { + double deltaLength = Math.sqrt(distanceSquared); + double relativeX = player.locX + (deltaX / deltaLength) * viewDistance; +@@ -70,7 +77,7 @@ public class EntityLightning extends EntityWeather { + } + } + // CraftBukkit end +- this.world.a((EntityHuman) null, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, SoundCategory.WEATHER, 2.0F, 0.5F + this.random.nextFloat() * 0.2F); ++ //this.world.a((EntityHuman) null, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, SoundCategory.WEATHER, 2.0f, 0.5F + this.random.nextFloat() * 0.2F); // Paper - Limit lightning strike effect distance (the packet is now sent from inside the loop) + } + + --this.lifeTicks; +diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java +index 0a7648263..b41dc3a73 100644 +--- a/src/main/java/net/minecraft/server/WorldServer.java ++++ b/src/main/java/net/minecraft/server/WorldServer.java +@@ -1087,7 +1087,7 @@ public class WorldServer extends World implements IAsyncTaskHandler { + } + // CraftBukkit end + if (super.strikeLightning(entity)) { +- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entity.locX, entity.locY, entity.locZ, 512.0D, this, new PacketPlayOutSpawnEntityWeather(entity)); // CraftBukkit - Use dimension, // Paper - use world instead of dimension ++ this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entity.locX, entity.locY, entity.locZ, this.paperConfig.maxLightningFlashDistance, this, new PacketPlayOutSpawnEntityWeather(entity)); // CraftBukkit - Use dimension, // Paper - use world instead of dimension, limit lightning strike effect distance + return true; + } else { + return false; +-- +2.19.0 +