#1134: Add custom sound parameter option for playSound with entity as source

This commit is contained in:
Gero 2023-01-28 11:39:20 +11:00 committed by md_5
parent ab8ace6857
commit b1059a82ea
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 29 additions and 0 deletions

View File

@ -1571,6 +1571,11 @@ public class CraftWorld extends CraftRegionAccessor implements World {
playSound(entity, sound, org.bukkit.SoundCategory.MASTER, volume, pitch); playSound(entity, sound, org.bukkit.SoundCategory.MASTER, volume, pitch);
} }
@Override
public void playSound(Entity entity, String sound, float volume, float pitch) {
playSound(entity, sound, org.bukkit.SoundCategory.MASTER, volume, pitch);
}
@Override @Override
public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return; if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return;
@ -1582,6 +1587,17 @@ public class CraftWorld extends CraftRegionAccessor implements World {
} }
} }
@Override
public void playSound(Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch) {
if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return;
PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong());
PlayerChunkMap.EntityTracker entityTracker = getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
if (entityTracker != null) {
entityTracker.broadcastAndSend(packet);
}
}
private static Map<String, GameRules.GameRuleKey<?>> gamerules; private static Map<String, GameRules.GameRuleKey<?>> gamerules;
public static synchronized Map<String, GameRules.GameRuleKey<?>> getGameRulesNMS() { public static synchronized Map<String, GameRules.GameRuleKey<?>> getGameRulesNMS() {
if (gamerules != null) { if (gamerules != null) {

View File

@ -532,6 +532,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
playSound(entity, sound, org.bukkit.SoundCategory.MASTER, volume, pitch); playSound(entity, sound, org.bukkit.SoundCategory.MASTER, volume, pitch);
} }
@Override
public void playSound(org.bukkit.entity.Entity entity, String sound, float volume, float pitch) {
playSound(entity, sound, org.bukkit.SoundCategory.MASTER, volume, pitch);
}
@Override @Override
public void playSound(org.bukkit.entity.Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { public void playSound(org.bukkit.entity.Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return; if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return;
@ -540,6 +545,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
getHandle().connection.send(packet); getHandle().connection.send(packet);
} }
@Override
public void playSound(org.bukkit.entity.Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch) {
if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return;
PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong());
getHandle().connection.send(packet);
}
@Override @Override
public void stopSound(Sound sound) { public void stopSound(Sound sound) {
stopSound(sound, null); stopSound(sound, null);