spigot/CraftBukkit-Patches/0053-Configurable-dragon-death-and-wither-spawn-sounds.patch
2021-06-11 15:00:00 +10:00

109 lines
6.8 KiB
Diff

From d313d3832f1017a38d4a062481974aad42c2f612 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 efeae33cc..0a503c878 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
@@ -638,7 +638,24 @@ public class EntityEnderDragon extends EntityInsentient implements IMonster {
}
if (this.dragonDeathTime == 1 && !this.isSilent()) {
- this.level.b(1028, this.getChunkCoordinates(), 0);
+ // CraftBukkit start - Use relative location for far away sounds
+ // this.world.b(1028, this.getChunkCoordinates(), 0);
+ int viewDistance = ((WorldServer) this.level).getServer().getViewDistance() * 16;
+ for (net.minecraft.server.level.EntityPlayer player : this.level.getMinecraftServer().getPlayerList().players) {
+ double deltaX = this.locX() - player.locX();
+ double deltaZ = this.locZ() - player.locZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+ if ( level.spigotConfig.dragonDeathSoundRadius > 0 && distanceSquared > level.spigotConfig.dragonDeathSoundRadius * level.spigotConfig.dragonDeathSoundRadius ) continue; // Spigot
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.locX() + (deltaX / deltaLength) * viewDistance;
+ double relativeZ = player.locZ() + (deltaZ / deltaLength) * viewDistance;
+ player.connection.sendPacket(new net.minecraft.network.protocol.game.PacketPlayOutWorldEvent(1028, new BlockPosition((int) relativeX, (int) this.locY(), (int) relativeZ), 0, true));
+ } else {
+ player.connection.sendPacket(new net.minecraft.network.protocol.game.PacketPlayOutWorldEvent(1028, new BlockPosition((int) this.locX(), (int) this.locY(), (int) this.locZ()), 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 a4429ce85..11609922f 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
@@ -267,6 +267,7 @@ public class EntityWither extends EntityMonster implements PowerableMob, IRanged
double deltaX = this.locX() - player.locX();
double deltaZ = this.locZ() - player.locZ();
double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+ if ( level.spigotConfig.witherSpawnSoundRadius > 0 && distanceSquared > level.spigotConfig.witherSpawnSoundRadius * level.spigotConfig.witherSpawnSoundRadius ) continue; // Spigot
if (distanceSquared > viewDistance * viewDistance) {
double deltaLength = Math.sqrt(distanceSquared);
double relativeX = player.locX() + (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 9ac3882d6..60cc2683c 100644
--- a/src/main/java/net/minecraft/world/item/ItemEnderEye.java
+++ b/src/main/java/net/minecraft/world/item/ItemEnderEye.java
@@ -58,7 +58,25 @@ public class ItemEnderEye extends Item {
}
}
- world.b(1038, blockposition1.c(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.getServer().getViewDistance() * 16;
+ BlockPosition soundPos = blockposition1.c(1, 0, 1);
+ for (EntityPlayer player : world.getServer().getServer().getPlayerList().players) {
+ double deltaX = soundPos.getX() - player.locX();
+ double deltaZ = soundPos.getZ() - player.locZ();
+ 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.locX() + (deltaX / deltaLength) * viewDistance;
+ double relativeZ = player.locZ() + (deltaZ / deltaLength) * viewDistance;
+ player.connection.sendPacket(new net.minecraft.network.protocol.game.PacketPlayOutWorldEvent(1038, new BlockPosition((int) relativeX, (int) soundPos.getY(), (int) relativeZ), 0, true));
+ } else {
+ player.connection.sendPacket(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 6226369bd..b99aa36b6 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -251,4 +251,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.25.1