mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Fix global sound event gamerule not being respected (#8727)
This commit is contained in:
parent
396b05ada6
commit
4d050226c3
3 changed files with 105 additions and 49 deletions
|
@ -2038,9 +2038,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/net/minecraft/world/level/Level.java
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
||||||
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
||||||
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||||||
return ret;
|
return range <= 0 ? 64.0 * 64.0 : range * range; // 64 is taken from default in ServerLevel#levelEvent
|
||||||
}
|
}
|
||||||
// Paper end
|
// Paper end - respect global sound events gamerule
|
||||||
|
+
|
||||||
+ // Paper start - optimize redstone (Alternate Current)
|
+ // Paper start - optimize redstone (Alternate Current)
|
||||||
+ public alternate.current.wire.WireHandler getWireHandler() {
|
+ public alternate.current.wire.WireHandler getWireHandler() {
|
||||||
+ // This method is overridden in ServerLevel.
|
+ // This method is overridden in ServerLevel.
|
||||||
|
|
102
patches/server/Fix-global-sound-handling.patch
Normal file
102
patches/server/Fix-global-sound-handling.patch
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
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
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||||
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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
|
||||||
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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
|
||||||
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/item/EnderEyeItem.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/item/EnderEyeItem.java
|
||||||
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
||||||
|
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
// Paper end
|
||||||
|
+
|
||||||
|
+ // 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
|
||||||
|
}
|
|
@ -1,47 +0,0 @@
|
||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Aikar <aikar@aikar.co>
|
|
||||||
Date: Tue, 31 May 2016 22:53:50 -0400
|
|
||||||
Subject: [PATCH] Only send global sounds to same world if limiting radius
|
|
||||||
|
|
||||||
Co-authored-by: Evan McCarthy <evanmccarthy@outlook.com>
|
|
||||||
Co-authored-by: lexikiq <noellekiq@gmail.com>
|
|
||||||
|
|
||||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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
|
|
||||||
@@ -0,0 +0,0 @@ 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().spigotConfig.dragonDeathSoundRadius > 0 ? ((ServerLevel) this.level()).players() : this.level().getServer().getPlayerList().players) { // Paper
|
|
||||||
double deltaX = this.getX() - player.getX();
|
|
||||||
double deltaZ = this.getZ() - player.getZ();
|
|
||||||
double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
|
|
||||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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
|
|
||||||
@@ -0,0 +0,0 @@ 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().spigotConfig.witherSpawnSoundRadius > 0 ? ((ServerLevel) this.level()).players() : this.level().getServer().getPlayerList().players) { // Paper
|
|
||||||
double deltaX = this.getX() - player.getX();
|
|
||||||
double deltaZ = this.getZ() - player.getZ();
|
|
||||||
double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
|
|
||||||
diff --git a/src/main/java/net/minecraft/world/item/EnderEyeItem.java b/src/main/java/net/minecraft/world/item/EnderEyeItem.java
|
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
||||||
--- a/src/main/java/net/minecraft/world/item/EnderEyeItem.java
|
|
||||||
+++ b/src/main/java/net/minecraft/world/item/EnderEyeItem.java
|
|
||||||
@@ -0,0 +0,0 @@ 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.spigotConfig.endPortalSoundRadius > 0 ? ((ServerLevel) world).players() : world.getServer().getPlayerList().players) { // Paper
|
|
||||||
double deltaX = soundPos.getX() - player.getX();
|
|
||||||
double deltaZ = soundPos.getZ() - player.getZ();
|
|
||||||
double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
|
|
Loading…
Reference in a new issue