spigot/CraftBukkit-Patches/0049-Configurable-dragon-death-and-wither-spawn-sounds.patch
2023-09-22 02:40:00 +10:00

109 lines
6.9 KiB
Diff

From 6e0280382c6b9c1bb2c8f2d34ab2a646c67e2b9e Mon Sep 17 00:00:00 2001
From: drXor <mcyoungsota@gmail.com>
Date: Sat, 29 Mar 2014 13:44:25 -0400
Subject: [PATCH] Configurable dragon death and wither spawn sounds
diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java
index 4cf7e7c17c..70d0f295d2 100644
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java
@@ -678,7 +678,24 @@ public class EntityEnderDragon extends EntityInsentient implements IMonster {
}
if (this.dragonDeathTime == 1 && !this.isSilent()) {
- this.level().globalLevelEvent(1028, this.blockPosition(), 0);
+ // CraftBukkit start - Use relative location for far away sounds
+ // this.level().globalLevelEvent(1028, this.blockPosition(), 0);
+ int viewDistance = ((WorldServer) this.level()).getCraftServer().getViewDistance() * 16;
+ for (net.minecraft.server.level.EntityPlayer player : this.level().getServer().getPlayerList().players) {
+ 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
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
+ double relativeZ = player.getZ() + (deltaZ / deltaLength) * viewDistance;
+ player.connection.send(new net.minecraft.network.protocol.game.PacketPlayOutWorldEvent(1028, new BlockPosition((int) relativeX, (int) this.getY(), (int) relativeZ), 0, true));
+ } else {
+ player.connection.send(new net.minecraft.network.protocol.game.PacketPlayOutWorldEvent(1028, new BlockPosition((int) this.getX(), (int) this.getY(), (int) this.getZ()), 0, true));
+ }
+ }
+ // CraftBukkit end
}
}
diff --git a/src/main/java/net/minecraft/world/entity/boss/wither/EntityWither.java b/src/main/java/net/minecraft/world/entity/boss/wither/EntityWither.java
index ec06bde715..18eeb9e4f3 100644
--- a/src/main/java/net/minecraft/world/entity/boss/wither/EntityWither.java
+++ b/src/main/java/net/minecraft/world/entity/boss/wither/EntityWither.java
@@ -277,6 +277,7 @@ public class EntityWither extends EntityMonster implements PowerableMob, IRanged
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
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/ItemEnderEye.java b/src/main/java/net/minecraft/world/item/ItemEnderEye.java
index 33b8cfe0e1..3345f0fc1a 100644
--- a/src/main/java/net/minecraft/world/item/ItemEnderEye.java
+++ b/src/main/java/net/minecraft/world/item/ItemEnderEye.java
@@ -60,7 +60,25 @@ public class ItemEnderEye extends Item {
}
}
- world.globalLevelEvent(1038, blockposition1.offset(1, 0, 1), 0);
+ // CraftBukkit start - Use relative location for far away sounds
+ // world.b(1038, blockposition1.c(1, 0, 1), 0);
+ int viewDistance = world.getCraftServer().getViewDistance() * 16;
+ BlockPosition soundPos = blockposition1.offset(1, 0, 1);
+ for (EntityPlayer player : world.getServer().getPlayerList().players) {
+ 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
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
+ double relativeZ = player.getZ() + (deltaZ / deltaLength) * viewDistance;
+ player.connection.send(new net.minecraft.network.protocol.game.PacketPlayOutWorldEvent(1038, new BlockPosition((int) relativeX, (int) soundPos.getY(), (int) relativeZ), 0, true));
+ } else {
+ player.connection.send(new net.minecraft.network.protocol.game.PacketPlayOutWorldEvent(1038, soundPos, 0, true));
+ }
+ }
+ // CraftBukkit end
}
return EnumInteractionResult.CONSUME;
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index d4eb3ccdab..7f5f97defc 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -276,4 +276,22 @@ public class SpigotWorldConfig
enableZombiePigmenPortalSpawns = getBoolean( "enable-zombie-pigmen-portal-spawns", true );
log( "Allow Zombie Pigmen to spawn from portal blocks: " + enableZombiePigmenPortalSpawns );
}
+
+ public int dragonDeathSoundRadius;
+ private void keepDragonDeathPerWorld()
+ {
+ dragonDeathSoundRadius = getInt( "dragon-death-sound-radius", 0 );
+ }
+
+ public int witherSpawnSoundRadius;
+ private void witherSpawnSoundRadius()
+ {
+ witherSpawnSoundRadius = getInt( "wither-spawn-sound-radius", 0 );
+ }
+
+ public int endPortalSoundRadius;
+ private void endPortalSoundRadius()
+ {
+ endPortalSoundRadius = getInt( "end-portal-sound-radius", 0 );
+ }
}
--
2.42.0