2019-12-16 02:58:10 +00:00
From c430c8018281f7ebbfab4a4d44b8a1a5808987f5 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
2019-12-16 02:58:10 +00:00
index 50ac7afa36..7dda0803c4 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
2019-12-12 16:20:43 +00:00
@@ -240,6 +240,28 @@ public class PaperWorldConfig {
2018-09-14 15:49:25 +00:00
}
}
2019-12-12 16:20:43 +00:00
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
+ }
+ }
2019-12-12 16:20:43 +00:00
+
2019-07-03 20:44:07 +00:00
public int fixedInhabitedTime;
private void fixedInhabitedTime() {
2019-12-12 16:20:43 +00:00
if (PaperConfig.version < 16) {
2018-09-14 15:49:25 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityLightning.java b/src/main/java/net/minecraft/server/EntityLightning.java
2019-12-16 02:58:10 +00:00
index 7c518983a9..bdb534deb4 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
2019-05-05 08:33:44 +00:00
@@ -64,6 +64,17 @@ public class EntityLightning extends Entity {
2019-12-12 16:20:43 +00:00
double deltaX = this.locX() - player.locX();
double deltaZ = this.locZ() - player.locZ();
2018-09-14 15:49:25 +00:00
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,
2019-12-12 18:45:00 +00:00
+ 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);
2019-12-12 16:20:43 +00:00
double relativeX = player.locX() + (deltaX / deltaLength) * viewDistance;
2019-05-05 08:33:44 +00:00
@@ -74,7 +85,7 @@ public class EntityLightning extends Entity {
2018-09-14 15:49:25 +00:00
}
}
// CraftBukkit end
2019-12-12 16:20:43 +00: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);
+ //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); // Paper - Limit lightning strike effect distance (the packet is now sent from inside the loop)
2018-09-14 15:49:25 +00:00
}
--this.lifeTicks;
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2019-12-16 02:58:10 +00:00
index a0c7141294..ecfcecfdc2 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
2019-12-12 16:20:43 +00:00
@@ -1250,7 +1250,7 @@ public class WorldServer extends World {
2018-09-14 15:49:25 +00:00
}
// CraftBukkit end
2019-05-05 08:33:44 +00:00
this.globalEntityList.add(entitylightning);
2019-12-12 16:20:43 +00:00
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entitylightning.locX(), entitylightning.locY(), entitylightning.locZ(), 512.0D, this, new PacketPlayOutSpawnEntityWeather(entitylightning)); // Paper - use world instead of dimension
+ this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entitylightning.locX(), entitylightning.locY(), entitylightning.locZ(), paperConfig.maxLightningFlashDistance, this, new PacketPlayOutSpawnEntityWeather(entitylightning)); // Paper - use world instead of dimension, limit lightning strike effect distance
2019-05-05 08:33:44 +00:00
}
@Override
2018-09-14 15:49:25 +00:00
--
2019-12-13 20:41:01 +00:00
2.24.1
2018-09-14 15:49:25 +00:00