#1134: Add custom sound parameter option for playSound with entity as source
This commit is contained in:
parent
ab8ace6857
commit
b1059a82ea
@ -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) {
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user