diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index c71f276ccc..ec441ab6c2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -75,8 +75,10 @@ import org.bukkit.Effect; import org.bukkit.FeatureFlag; import org.bukkit.FluidCollisionMode; import org.bukkit.GameRule; +import org.bukkit.Instrument; import org.bukkit.Location; import org.bukkit.NamespacedKey; +import org.bukkit.Note; import org.bukkit.Particle; import org.bukkit.Raid; import org.bukkit.Registry; @@ -1538,6 +1540,11 @@ public class CraftWorld extends CraftRegionAccessor implements World { spawnCategoryLimit.put(spawnCategory, limit); } + @Override + public void playNote(@NotNull Location loc, @NotNull Instrument instrument, @NotNull Note note) { + playSound(loc, instrument.getSound(), org.bukkit.SoundCategory.RECORDS, 3f, note.getPitch()); + } + @Override public void playSound(Location loc, Sound sound, float volume, float pitch) { playSound(loc, sound, org.bukkit.SoundCategory.MASTER, volume, pitch); @@ -1550,24 +1557,34 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { - if (loc == null || sound == null || category == null) return; - - double x = loc.getX(); - double y = loc.getY(); - double z = loc.getZ(); - - getHandle().playSound(null, x, y, z, CraftSound.bukkitToMinecraft(sound), SoundCategory.valueOf(category.name()), volume, pitch); + playSound(loc, sound, category, volume, pitch, getHandle().random.nextLong());; } @Override public void playSound(Location loc, String sound, org.bukkit.SoundCategory category, float volume, float pitch) { + playSound(loc, sound, category, volume, pitch, getHandle().random.nextLong()); + } + + @Override + public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { if (loc == null || sound == null || category == null) return; double x = loc.getX(); double y = loc.getY(); double z = loc.getZ(); - PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), SoundCategory.valueOf(category.name()), x, y, z, volume, pitch, getHandle().getRandom().nextLong()); + getHandle().playSeededSound(null, x, y, z, CraftSound.bukkitToMinecraft(sound), SoundCategory.valueOf(category.name()), volume, pitch, seed); + } + + @Override + public void playSound(Location loc, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { + if (loc == null || sound == null || category == null) return; + + double x = loc.getX(); + double y = loc.getY(); + double z = loc.getZ(); + + PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), SoundCategory.valueOf(category.name()), x, y, z, volume, pitch, seed); world.getServer().getPlayerList().broadcast(null, x, y, z, volume > 1.0F ? 16.0F * volume : 16.0D, this.world.dimension(), packet); } @@ -1583,9 +1600,19 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { + playSound(entity, sound, category, volume, pitch, getHandle().random.nextLong()); + } + + @Override + public void playSound(Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch) { + playSound(entity, sound, category, volume, pitch, getHandle().random.nextLong()); + } + + @Override + public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return; - PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong()); + PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed); PlayerChunkMap.EntityTracker entityTracker = getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId()); if (entityTracker != null) { entityTracker.broadcastAndSend(packet); @@ -1593,10 +1620,10 @@ public class CraftWorld extends CraftRegionAccessor implements World { } @Override - public void playSound(Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch) { + public void playSound(Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { 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()); + PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed); PlayerChunkMap.EntityTracker entityTracker = getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId()); if (entityTracker != null) { entityTracker.broadcastAndSend(packet); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index bece7b86be..baf840c372 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -436,29 +436,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player { if (getHandle().connection == null) return; - Sound instrumentSound = switch (instrument.ordinal()) { - case 0 -> Sound.BLOCK_NOTE_BLOCK_HARP; - case 1 -> Sound.BLOCK_NOTE_BLOCK_BASEDRUM; - case 2 -> Sound.BLOCK_NOTE_BLOCK_SNARE; - case 3 -> Sound.BLOCK_NOTE_BLOCK_HAT; - case 4 -> Sound.BLOCK_NOTE_BLOCK_BASS; - case 5 -> Sound.BLOCK_NOTE_BLOCK_FLUTE; - case 6 -> Sound.BLOCK_NOTE_BLOCK_BELL; - case 7 -> Sound.BLOCK_NOTE_BLOCK_GUITAR; - case 8 -> Sound.BLOCK_NOTE_BLOCK_CHIME; - case 9 -> Sound.BLOCK_NOTE_BLOCK_XYLOPHONE; - case 10 -> Sound.BLOCK_NOTE_BLOCK_IRON_XYLOPHONE; - case 11 -> Sound.BLOCK_NOTE_BLOCK_COW_BELL; - case 12 -> Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO; - case 13 -> Sound.BLOCK_NOTE_BLOCK_BIT; - case 14 -> Sound.BLOCK_NOTE_BLOCK_BANJO; - case 15 -> Sound.BLOCK_NOTE_BLOCK_PLING; - case 16 -> Sound.BLOCK_NOTE_BLOCK_XYLOPHONE; - default -> null; - }; + Sound instrumentSound = instrument.getSound(); + if (instrumentSound == null) return; - float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D); - getHandle().connection.send(new PacketPlayOutNamedSoundEffect(CraftSound.bukkitToMinecraftHolder(instrumentSound), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, getHandle().getRandom().nextLong())); + float pitch = note.getPitch(); + getHandle().connection.send(new PacketPlayOutNamedSoundEffect(CraftSound.bukkitToMinecraftHolder(instrumentSound), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, pitch, getHandle().getRandom().nextLong())); } @Override @@ -473,24 +455,34 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) { - if (loc == null || sound == null || category == null || getHandle().connection == null) return; - - playSound0(loc, CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch); + playSound(loc, sound, category, volume, pitch, getHandle().random.nextLong()); } @Override public void playSound(Location loc, String sound, org.bukkit.SoundCategory category, float volume, float pitch) { - if (loc == null || sound == null || category == null || getHandle().connection == null) return; - - playSound0(loc, Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch); + playSound(loc, sound, category, volume, pitch, getHandle().random.nextLong()); } - private void playSound0(Location loc, Holder soundEffectHolder, net.minecraft.sounds.SoundCategory categoryNMS, float volume, float pitch) { + @Override + public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { + if (loc == null || sound == null || category == null || getHandle().connection == null) return; + + playSound0(loc, CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch, seed); + } + + @Override + public void playSound(Location loc, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { + if (loc == null || sound == null || category == null || getHandle().connection == null) return; + + playSound0(loc, Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch, seed); + } + + private void playSound0(Location loc, Holder soundEffectHolder, net.minecraft.sounds.SoundCategory categoryNMS, float volume, float pitch, long seed) { Preconditions.checkArgument(loc != null, "Location cannot be null"); if (getHandle().connection == null) return; - PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(soundEffectHolder, categoryNMS, loc.getX(), loc.getY(), loc.getZ(), volume, pitch, getHandle().getRandom().nextLong()); + PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(soundEffectHolder, categoryNMS, loc.getX(), loc.getY(), loc.getZ(), volume, pitch, seed); getHandle().connection.send(packet); } @@ -506,19 +498,29 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override 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; - - playSound0(entity, CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch); + playSound(entity, sound, category, volume, pitch, getHandle().random.nextLong()); } @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; - - playSound0(entity, Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch); + playSound(entity, sound, category, volume, pitch, getHandle().random.nextLong()); } - private void playSound0(org.bukkit.entity.Entity entity, Holder soundEffectHolder, net.minecraft.sounds.SoundCategory categoryNMS, float volume, float pitch) { + @Override + public void playSound(org.bukkit.entity.Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { + if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return; + + playSound0(entity, CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch, seed); + } + + @Override + public void playSound(org.bukkit.entity.Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { + if (!(entity instanceof CraftEntity craftEntity) || sound == null || category == null || getHandle().connection == null) return; + + playSound0(entity, Holder.direct(SoundEffect.createVariableRangeEvent(new MinecraftKey(sound))), net.minecraft.sounds.SoundCategory.valueOf(category.name()), volume, pitch, seed); + } + + private void playSound0(org.bukkit.entity.Entity entity, Holder soundEffectHolder, net.minecraft.sounds.SoundCategory categoryNMS, float volume, float pitch, long seed) { Preconditions.checkArgument(entity != null, "Entity cannot be null"); Preconditions.checkArgument(soundEffectHolder != null, "Holder of SoundEffect cannot be null"); Preconditions.checkArgument(categoryNMS != null, "SoundCategory cannot be null"); @@ -526,7 +528,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { if (getHandle().connection == null) return; if (!(entity instanceof CraftEntity craftEntity)) return; - PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(soundEffectHolder, categoryNMS, craftEntity.getHandle(), volume, pitch, getHandle().getRandom().nextLong()); + PacketPlayOutEntitySound packet = new PacketPlayOutEntitySound(soundEffectHolder, categoryNMS, craftEntity.getHandle(), volume, pitch, seed); getHandle().connection.send(packet); }