From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 9 Dec 2022 01:47:23 -0800 Subject: [PATCH] fix Instruments properly handle Player#playNote diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 4096145769065693c6d67f092ccedccb78ef4578..292054f546669fe607715e2d39e8ed558fc6fc0c 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -726,29 +726,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player { if (this.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; - }; - - float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D); - this.getHandle().connection.send(new ClientboundSoundPacket(CraftSound.bukkitToMinecraftHolder(instrumentSound), net.minecraft.sounds.SoundSource.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, this.getHandle().getRandom().nextLong())); + // Paper start - fix all this (modeled off of NoteBlock) + net.minecraft.world.level.block.state.properties.NoteBlockInstrument noteBlockInstrument = CraftBlockData.toNMS(instrument, net.minecraft.world.level.block.state.properties.NoteBlockInstrument.class); + float pitch; + if (noteBlockInstrument.isTunable()) { + pitch = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D); + } else { + pitch = 1.0f; + } + if (!noteBlockInstrument.hasCustomSound()) { + this.getHandle().connection.send(new ClientboundSoundPacket(noteBlockInstrument.getSoundEvent(), net.minecraft.sounds.SoundSource.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, pitch, this.getHandle().getRandom().nextLong())); + } + // Paper end } @Override