2018-12-17 05:18:06 +00:00
From 19a846af322a5b7aef506f0d614829c62219f055 Mon Sep 17 00:00:00 2001
2018-09-14 15:49:25 +00:00
From: Trigary <trigary0@gmail.com>
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
2018-12-15 01:17:27 +00:00
index 94c544714..48920b045 100644
2018-09-14 15:49:25 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2018-11-23 07:23:50 +00:00
@@ -237,6 +237,28 @@ public class PaperWorldConfig {
2018-09-14 15:49:25 +00:00
skeleHorseSpawnChance = 0.01D; // Vanilla value
}
}
+
2018-11-23 07:23:50 +00:00
+ public double sqrMaxThunderDistance;
2018-09-14 15:49:25 +00:00
+ public double sqrMaxLightningImpactSoundDistance;
+ public double maxLightningFlashDistance;
+ private void lightningStrikeDistanceLimit() {
2018-11-23 07:23:50 +00:00
+ sqrMaxThunderDistance = getInt("lightning-strike-distance-limit.sound", -1);
+ if (sqrMaxThunderDistance > 0) {
+ sqrMaxThunderDistance *= sqrMaxThunderDistance;
2018-09-14 15:49:25 +00:00
+ }
+
+ 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
2018-12-02 23:31:09 +00:00
index afbe43dd3..d732be52e 100644
2018-09-14 15:49:25 +00:00
--- a/src/main/java/net/minecraft/server/EntityLightning.java
+++ b/src/main/java/net/minecraft/server/EntityLightning.java
2018-11-23 07:23:50 +00:00
@@ -60,6 +60,17 @@ public class EntityLightning extends EntityWeather {
2018-09-14 15:49:25 +00:00
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
2018-10-17 01:40:32 +00:00
+ if (distanceSquared <= this.world.paperConfig.sqrMaxLightningImpactSoundDistance) {
2018-09-14 15:49:25 +00:00
+ 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));
2018-11-23 07:23:50 +00:00
+ }
+
+ if (world.paperConfig.sqrMaxThunderDistance != -1 && distanceSquared >= world.paperConfig.sqrMaxThunderDistance) {
2018-10-17 01:40:32 +00:00
+ continue;
2018-09-14 15:49:25 +00:00
+ }
2018-11-23 07:23:50 +00:00
+
2018-09-14 15:49:25 +00:00
+ // Paper end
if (distanceSquared > viewDistance * viewDistance) {
double deltaLength = Math.sqrt(distanceSquared);
double relativeX = player.locX + (deltaX / deltaLength) * viewDistance;
2018-11-23 07:23:50 +00:00
@@ -70,7 +81,7 @@ public class EntityLightning extends EntityWeather {
2018-09-14 15:49:25 +00:00
}
}
// 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
2018-12-17 05:18:06 +00:00
index 27c8a97be..63c802d02 100644
2018-09-14 15:49:25 +00:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2018-12-17 05:18:06 +00:00
@@ -1088,7 +1088,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
2018-09-14 15:49:25 +00:00
}
// 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;
--
2018-12-15 01:17:27 +00:00
2.20.0
2018-09-14 15:49:25 +00:00