2023-12-28 01:33:05 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
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 <evanmccarthy@outlook.com>
Co-authored-by: lexikiq <noellekiq@gmail.com>
Co-authored-by: Aikar <aikar@aikar.co>
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
2024-10-22 22:00:33 +02:00
index 8dc2b2d8ba32aefc11eb23054b902650fac76adf..21c3d771a3dd921767c2cba1e11583d015879ca9 100644
2023-12-28 01:33:05 +01:00
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
2024-10-22 22:00:33 +02:00
@@ -1335,7 +1335,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
2023-12-28 01:33:05 +01:00
@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() {
2024-10-22 22:00:33 +02:00
@@ -2152,6 +2152,17 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
return this.serverLevelData.getGameRules();
}
+ // 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
+
@Override
public CrashReportCategory fillReportDetails(CrashReport report) {
CrashReportCategory crashreportsystemdetails = super.fillReportDetails(report);
2023-12-28 01:33:05 +01:00
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
2024-10-22 22:00:33 +02:00
index 2bb62325d30ac509583de50407ea21f562f6e74f..95d69e3ca1a9095dfb340e9be0ec322ab6c5eb5e 100644
2023-12-28 01:33:05 +01:00
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
2024-10-22 22:00:33 +02:00
@@ -666,11 +666,12 @@ public class EnderDragon extends Mob implements Enemy {
2023-12-28 01:33:05 +01:00
// CraftBukkit start - Use relative location for far away sounds
2024-10-22 22:00:33 +02:00
// worldserver.globalLevelEvent(1028, this.blockPosition(), 0);
int viewDistance = worldserver.getCraftServer().getViewDistance() * 16;
- for (net.minecraft.server.level.ServerPlayer player : worldserver.getServer().getPlayerList().players) {
+ for (net.minecraft.server.level.ServerPlayer player : worldserver.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
2023-12-28 01:33:05 +01:00
double deltaX = this.getX() - player.getX();
double deltaZ = this.getZ() - player.getZ();
double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
2024-10-22 22:00:33 +02:00
- if ( worldserver.spigotConfig.dragonDeathSoundRadius > 0 && distanceSquared > worldserver.spigotConfig.dragonDeathSoundRadius * worldserver.spigotConfig.dragonDeathSoundRadius ) continue; // Spigot
+ final double soundRadiusSquared = worldserver.getGlobalSoundRangeSquared(config -> config.dragonDeathSoundRadius); // Paper - respect global sound events gamerule
+ if ( !worldserver.getGameRules().getBoolean(GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared ) continue; // Spigot // Paper - respect global sound events gamerule
2023-12-28 01:33:05 +01:00
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
2024-10-22 22:00:33 +02:00
index 4c284ccd5b2eb05f487aba18e1daa0b59c3e8129..10c79cbc25383c0b65fb22a7347513134b7dee1d 100644
2023-12-28 01:33:05 +01:00
--- a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
+++ b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
2024-10-22 22:00:33 +02:00
@@ -276,11 +276,12 @@ public class WitherBoss extends Monster implements RangedAttackMob {
2023-12-28 01:33:05 +01:00
// CraftBukkit start - Use relative location for far away sounds
2024-10-22 22:00:33 +02:00
// worldserver.globalLevelEvent(1023, new BlockPosition(this), 0);
int viewDistance = world.getCraftServer().getViewDistance() * 16;
2023-12-28 01:33:05 +01:00
- for (ServerPlayer player : (List<ServerPlayer>) MinecraftServer.getServer().getPlayerList().players) {
2024-10-22 22:00:33 +02:00
+ for (ServerPlayer player : world.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
2023-12-28 01:33:05 +01:00
double deltaX = this.getX() - player.getX();
double deltaZ = this.getZ() - player.getZ();
double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
2024-10-22 22:00:33 +02:00
- if ( world.spigotConfig.witherSpawnSoundRadius > 0 && distanceSquared > world.spigotConfig.witherSpawnSoundRadius * world.spigotConfig.witherSpawnSoundRadius ) continue; // Spigot
+ final double soundRadiusSquared = world.getGlobalSoundRangeSquared(config -> config.witherSpawnSoundRadius); // Paper - respect global sound events gamerule
+ if ( !world.getGameRules().getBoolean(GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared ) continue; // Spigot // Paper - respect global sound events gamerule
2023-12-28 01:33:05 +01:00
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
2024-10-25 14:55:49 +02:00
index 04fce5cc4350df81c7ea103b74b845313dd6cc37..08cbf02bba3633a84cce90c202d13f2beb5b88a2 100644
2023-12-28 01:33:05 +01:00
--- a/src/main/java/net/minecraft/world/item/EnderEyeItem.java
+++ b/src/main/java/net/minecraft/world/item/EnderEyeItem.java
2024-10-25 14:55:49 +02:00
@@ -66,11 +66,13 @@ public class EnderEyeItem extends Item {
2024-10-22 22:00:33 +02:00
// world.globalLevelEvent(1038, blockposition1.offset(1, 0, 1), 0);
2023-12-28 01:33:05 +01:00
int viewDistance = world.getCraftServer().getViewDistance() * 16;
BlockPos soundPos = blockposition1.offset(1, 0, 1);
- for (ServerPlayer player : world.getServer().getPlayerList().players) {
2024-10-25 14:55:49 +02:00
+ final net.minecraft.server.level.ServerLevel serverLevel = (net.minecraft.server.level.ServerLevel) world; // Paper - respect global sound events gamerule - ensured by isClientSide check above
+ for (ServerPlayer player : serverLevel.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
2023-12-28 01:33:05 +01:00
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
2024-10-25 14:55:49 +02:00
+ final double soundRadiusSquared = serverLevel.getGlobalSoundRangeSquared(config -> config.endPortalSoundRadius); // Paper - respect global sound events gamerule
+ if (!serverLevel.getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared) continue; // Spigot // Paper - respect global sound events gamerule
2023-12-28 01:33:05 +01:00
if (distanceSquared > viewDistance * viewDistance) {
double deltaLength = Math.sqrt(distanceSquared);
double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;