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

84 lines
4.9 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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
index 487b0d5cd608e84a793eba5fdbd50a9f3d95c79b..b8789c8ecc5a6e4117bb7ce0d5487a6e5774b67f 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -242,6 +242,28 @@ public class PaperWorldConfig {
}
}
+ 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
+ }
+ }
+
public int fixedInhabitedTime;
private void fixedInhabitedTime() {
if (PaperConfig.version < 16) {
diff --git a/src/main/java/net/minecraft/server/EntityLightning.java b/src/main/java/net/minecraft/server/EntityLightning.java
index 7c518983a9c21a9b221e1fa1b0baa3d5c9ccadbf..bdb534deb47a945d5cbfad688eeab5e3388a4df5 100644
--- a/src/main/java/net/minecraft/server/EntityLightning.java
+++ b/src/main/java/net/minecraft/server/EntityLightning.java
2019-05-05 10:33:44 +02:00
@@ -64,6 +64,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
2018-10-17 03:40:32 +02:00
+ if (distanceSquared <= this.world.paperConfig.sqrMaxLightningImpactSoundDistance) {
+ player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT,
2019-12-12 19:45:00 +01:00
+ 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) {
2018-10-17 03:40:32 +02:00
+ continue;
+ }
+
+ // Paper end
if (distanceSquared > viewDistance * viewDistance) {
double deltaLength = Math.sqrt(distanceSquared);
double relativeX = player.locX() + (deltaX / deltaLength) * viewDistance;
2019-05-05 10:33:44 +02:00
@@ -74,7 +85,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 - 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 ad779650ed73176a88e5f4232df4ffcaf8f2797c..a75034079b0f5a06509f9762593c5e805e35881c 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -1288,7 +1288,7 @@ public class WorldServer extends World {
}
// CraftBukkit end
2019-05-05 10:33:44 +02:00
this.globalEntityList.add(entitylightning);
- 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 10:33:44 +02:00
}
@Override