aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0101-Fix-global-sound-handling.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0101-Fix-global-sound-handling.patch')
-rw-r--r--patches/server/0101-Fix-global-sound-handling.patch101
1 files changed, 101 insertions, 0 deletions
diff --git a/patches/server/0101-Fix-global-sound-handling.patch b/patches/server/0101-Fix-global-sound-handling.patch
new file mode 100644
index 0000000000..f1855116cb
--- /dev/null
+++ b/patches/server/0101-Fix-global-sound-handling.patch
@@ -0,0 +1,101 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jake Potrebic <[email protected]>
+Date: Tue, 31 May 2016 22:53:50 -0400
+Subject: [PATCH] Fix global sound handling
+
+* Only send global sounds to same world if limiting radius
+* respect global sound events gamerule
+
+Co-authored-by: Evan McCarthy <[email protected]>
+Co-authored-by: lexikiq <[email protected]>
+Co-authored-by: Aikar <[email protected]>
+
+diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
+index 223f8d9be5d73e296f5815db7123b95c3b345162..d728afbe1d6882f1ace4ead9d87f4b7d2af43ba2 100644
+--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
++++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
+@@ -1322,7 +1322,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
+
+ @Override
+ public void levelEvent(@Nullable Player player, int eventId, BlockPos pos, int data) {
+- this.server.getPlayerList().broadcast(player, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 64.0D, this.dimension(), new ClientboundLevelEventPacket(eventId, pos, data, false));
++ this.server.getPlayerList().broadcast(player, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 64.0D, this.dimension(), new ClientboundLevelEventPacket(eventId, pos, data, false)); // Paper - diff on change (the 64.0 distance is used as defaults for sound ranges in spigot config for ender dragon, end portal and wither)
+ }
+
+ public int getLogicalHeight() {
+diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+index 7432becf1c9a378a62e116153aebad4960c0c7bd..dba973ba5088d253aa67f5577663cccda7f4edd1 100644
+--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
++++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+@@ -696,11 +696,12 @@ public class EnderDragon extends Mob implements Enemy {
+ // CraftBukkit start - Use relative location for far away sounds
+ // this.level().globalLevelEvent(1028, this.blockPosition(), 0);
+ int viewDistance = ((ServerLevel) this.level()).getCraftServer().getViewDistance() * 16;
+- for (net.minecraft.server.level.ServerPlayer player : this.level().getServer().getPlayerList().players) {
++ for (net.minecraft.server.level.ServerPlayer player : this.level().getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+ double deltaX = this.getX() - player.getX();
+ double deltaZ = this.getZ() - player.getZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+- if ( this.level().spigotConfig.dragonDeathSoundRadius > 0 && distanceSquared > this.level().spigotConfig.dragonDeathSoundRadius * this.level().spigotConfig.dragonDeathSoundRadius ) continue; // Spigot
++ final double soundRadiusSquared = this.level().getGlobalSoundRangeSquared(config -> config.dragonDeathSoundRadius); // Paper - respect global sound events gamerule
++ if ( !this.level().getGameRules().getBoolean(GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared ) continue; // Spigot // Paper - respect global sound events gamerule
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
+diff --git a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
+index d288bc209a0b0fdf2d73197a8e7d179e8e8c31e7..3ee24382ef3614ff0c5d5cdc614a41286ba4af5e 100644
+--- a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
++++ b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
+@@ -278,11 +278,12 @@ public class WitherBoss extends Monster implements PowerableMob, RangedAttackMob
+ // CraftBukkit start - Use relative location for far away sounds
+ // this.level().globalLevelEvent(1023, new BlockPosition(this), 0);
+ int viewDistance = ((ServerLevel) this.level()).getCraftServer().getViewDistance() * 16;
+- for (ServerPlayer player : (List<ServerPlayer>) MinecraftServer.getServer().getPlayerList().players) {
++ for (ServerPlayer player : this.level().getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+ double deltaX = this.getX() - player.getX();
+ double deltaZ = this.getZ() - player.getZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+- if ( this.level().spigotConfig.witherSpawnSoundRadius > 0 && distanceSquared > this.level().spigotConfig.witherSpawnSoundRadius * this.level().spigotConfig.witherSpawnSoundRadius ) continue; // Spigot
++ final double soundRadiusSquared = this.level().getGlobalSoundRangeSquared(config -> config.witherSpawnSoundRadius); // Paper - respect global sound events gamerule
++ if ( !this.level().getGameRules().getBoolean(GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared ) continue; // Spigot // Paper - respect global sound events gamerule
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
+diff --git a/src/main/java/net/minecraft/world/item/EnderEyeItem.java b/src/main/java/net/minecraft/world/item/EnderEyeItem.java
+index 0224a0e901f9430ef06c30432a7988149a67037d..391579b515c5a07066f82b33c4f9ef8ee1d05530 100644
+--- a/src/main/java/net/minecraft/world/item/EnderEyeItem.java
++++ b/src/main/java/net/minecraft/world/item/EnderEyeItem.java
+@@ -67,11 +67,12 @@ public class EnderEyeItem extends Item {
+ // world.b(1038, blockposition1.c(1, 0, 1), 0);
+ int viewDistance = world.getCraftServer().getViewDistance() * 16;
+ BlockPos soundPos = blockposition1.offset(1, 0, 1);
+- for (ServerPlayer player : world.getServer().getPlayerList().players) {
++ for (ServerPlayer player : world.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+ double deltaX = soundPos.getX() - player.getX();
+ double deltaZ = soundPos.getZ() - player.getZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+- if (world.spigotConfig.endPortalSoundRadius > 0 && distanceSquared > world.spigotConfig.endPortalSoundRadius * world.spigotConfig.endPortalSoundRadius) continue; // Spigot
++ final double soundRadiusSquared = world.getGlobalSoundRangeSquared(config -> config.endPortalSoundRadius); // Paper - respect global sound events gamerule
++ if (!world.getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared) continue; // Spigot // Paper - respect global sound events gamerule
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
+diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
+index 4abb586f964e342425c7cf0384ab8bf8cdedaea3..008be3aad044d20be14da3a9e96933d265104587 100644
+--- a/src/main/java/net/minecraft/world/level/Level.java
++++ b/src/main/java/net/minecraft/world/level/Level.java
+@@ -1277,4 +1277,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
+ return this.id;
+ }
+ }
++ // Paper start - respect global sound events gamerule
++ public List<net.minecraft.server.level.ServerPlayer> getPlayersForGlobalSoundGamerule() {
++ return this.getGameRules().getBoolean(GameRules.RULE_GLOBAL_SOUND_EVENTS) ? ((ServerLevel) this).getServer().getPlayerList().players : ((ServerLevel) this).players();
++ }
++
++ public double getGlobalSoundRangeSquared(java.util.function.Function<org.spigotmc.SpigotWorldConfig, Integer> rangeFunction) {
++ final double range = rangeFunction.apply(this.spigotConfig);
++ return range <= 0 ? 64.0 * 64.0 : range * range; // 64 is taken from default in ServerLevel#levelEvent
++ }
++ // Paper end - respect global sound events gamerule
+ }