spigot/CraftBukkit-Patches/0050-Configurable-dragon-death-and-wither-spawn-sounds.patch

109 lines
6.8 KiB
Diff

From 7a31f5b95355e34e092d35c6b18c0888417bf692 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 97a7e7e5c..36ee5ad6a 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
@@ -651,7 +651,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.world.b(1028, this.getChunkCoordinates(), 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 ( 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.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 86cc37ed8..d3352870a 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
@@ -278,6 +278,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 ( 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.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 e3c6fda40..f97c94517 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 89acf67f4..33d74abad 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -274,4 +274,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.34.1