Paper/Spigot-Server-Patches/0521-Limit-lightning-strike-effect-distance.patch

94 Zeilen
4.4 KiB
Diff

2020-06-27 20:35:52 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: kickash32 <kickash32@gmail.com>
Date: Sat, 27 Jun 2020 12:37:58 -0400
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 0f4fca90fd6c3788a5762c96c344899cb1665466..4a59d42b778e681e93f1243ecd16c5cf46160b97 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -1,11 +1,5 @@
package com.destroystokyo.paper;
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray.EngineMode;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@@ -13,6 +7,12 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.spigotmc.SpigotWorldConfig;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import static com.destroystokyo.paper.PaperConfig.log;
import static com.destroystokyo.paper.PaperConfig.logError;
@@ -648,4 +648,26 @@ public class PaperWorldConfig {
delayChunkUnloadsBy *= 20;
}
}
+
+ public double sqrMaxThunderDistance;
+ public double sqrMaxLightningImpactSoundDistance;
+ public double maxLightningFlashDistance;
+ private void lightningStrikeDistanceLimit() {
+ sqrMaxThunderDistance = getInt("lightning-strike-distance-limit.sound", -1);
+ if (sqrMaxThunderDistance > 0) {
+ sqrMaxThunderDistance *= sqrMaxThunderDistance;
+ }
+
+ 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
+ }
+ }
}
diff --git a/src/main/java/net/minecraft/server/EntityLightning.java b/src/main/java/net/minecraft/server/EntityLightning.java
index 6f979e5f1f1567b140e9689298aff85de34f7413..ebcb9f48f47d1ab1e972bed1bc7cb0ee305a29f2 100644
--- a/src/main/java/net/minecraft/server/EntityLightning.java
+++ b/src/main/java/net/minecraft/server/EntityLightning.java
@@ -56,6 +56,17 @@ public class EntityLightning extends Entity {
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 (world.paperConfig.sqrMaxThunderDistance != -1 && distanceSquared >= world.paperConfig.sqrMaxThunderDistance) {
+ continue;
+ }
+
+ // Paper end
if (distanceSquared > viewDistance * viewDistance) {
double deltaLength = Math.sqrt(distanceSquared);
double relativeX = player.locX() + (deltaX / deltaLength) * viewDistance;
@@ -66,7 +77,7 @@ public class EntityLightning extends Entity {
}
}
// CraftBukkit end
- 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
}
--this.lifeTicks;