From be21be402958b6e36f9e14ca2fef723ceb19ac60 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Mon, 15 May 2023 19:32:26 +0200 Subject: [PATCH] Fix note block sound property on player heads (#9158) --- patches/api/Add-more-advancement-API.patch | 17 +++++++---------- patches/api/Fix-NotePlayEvent.patch | 6 ++++++ patches/server/Fix-NotePlayEvent.patch | 17 ++++++++--------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/patches/api/Add-more-advancement-API.patch b/patches/api/Add-more-advancement-API.patch index 1b5b1a95c0..7de1fbedb7 100644 --- a/patches/api/Add-more-advancement-API.patch +++ b/patches/api/Add-more-advancement-API.patch @@ -194,14 +194,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * recipes. * - * This includes it's name, description and other visible tags. -+ * This includes its name, description and other visible tags. - * -- * @return a AdvancementDisplay object, or null if not set. + * @return the display info - */ -- @Nullable -- AdvancementDisplay getDisplay(); -+ @org.jetbrains.annotations.Nullable ++ */ ++ @Nullable + io.papermc.paper.advancement.AdvancementDisplay getDisplay(); + + /** @@ -210,7 +205,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * completes the advancement. Will return the same as + * {@link io.papermc.paper.advancement.AdvancementDisplay#displayName()} when an + * {@link io.papermc.paper.advancement.AdvancementDisplay} is present. -+ * + * +- * @return a AdvancementDisplay object, or null if not set. + * @return the display name + * @see io.papermc.paper.advancement.AdvancementDisplay#displayName() + */ @@ -220,8 +216,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * Gets the parent advancement, if any. + * + * @return the parent advancement -+ */ -+ @org.jetbrains.annotations.Nullable + */ + @Nullable +- AdvancementDisplay getDisplay(); + Advancement getParent(); + + /** diff --git a/patches/api/Fix-NotePlayEvent.patch b/patches/api/Fix-NotePlayEvent.patch index 7a6761f7de..ca823c4ce0 100644 --- a/patches/api/Fix-NotePlayEvent.patch +++ b/patches/api/Fix-NotePlayEvent.patch @@ -9,7 +9,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/event/block/NotePlayEvent.java +++ b/src/main/java/org/bukkit/event/block/NotePlayEvent.java @@ -0,0 +0,0 @@ public class NotePlayEvent extends BlockEvent implements Cancellable { + + /** * Overrides the {@link Instrument} to be used. ++ *
++ * Only works when the note block isn't under a player head. ++ * For this specific case the 'note_block_sound' property of the ++ * player head state takes the priority. * * @param instrument the Instrument. Has no effect if null. - * @deprecated no effect on newer Minecraft versions diff --git a/patches/server/Fix-NotePlayEvent.patch b/patches/server/Fix-NotePlayEvent.patch index c34df48663..dc93a9774a 100644 --- a/patches/server/Fix-NotePlayEvent.patch +++ b/patches/server/Fix-NotePlayEvent.patch @@ -28,14 +28,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 world.gameEvent(entity, GameEvent.NOTE_BLOCK_PLAY, pos); } @@ -0,0 +0,0 @@ public class NoteBlock extends Block { - @Override public boolean triggerEvent(BlockState state, Level world, BlockPos pos, int type, int data) { + NoteBlockInstrument blockpropertyinstrument = (NoteBlockInstrument) state.getValue(NoteBlock.INSTRUMENT); + // Paper start - move NotePlayEvent call to fix instrument/note changes -+ org.bukkit.event.block.NotePlayEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callNotePlayEvent(world, pos, state.getValue(INSTRUMENT), state.getValue(NOTE)); ++ org.bukkit.event.block.NotePlayEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callNotePlayEvent(world, pos, blockpropertyinstrument, state.getValue(NOTE)); + if (event.isCancelled()) return false; + // Paper end - NoteBlockInstrument blockpropertyinstrument = (NoteBlockInstrument) state.getValue(NoteBlock.INSTRUMENT); float f; if (blockpropertyinstrument.isTunable()) { @@ -45,11 +44,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 f = (float) Math.pow(2.0D, (double) (k - 12) / 12.0D); world.addParticle(ParticleTypes.NOTE, (double) pos.getX() + 0.5D, (double) pos.getY() + 1.2D, (double) pos.getZ() + 0.5D, (double) k / 24.0D, 0.0D, 0.0D); @@ -0,0 +0,0 @@ public class NoteBlock extends Block { - holder = blockpropertyinstrument.getSoundEvent(); + + holder = Holder.direct(SoundEvent.createVariableRangeEvent(minecraftkey)); + } else { +- holder = blockpropertyinstrument.getSoundEvent(); ++ holder = org.bukkit.craftbukkit.block.data.CraftBlockData.toNMS(event.getInstrument(), NoteBlockInstrument.class).getSoundEvent(); // Paper } -- world.playSeededSound((Player) null, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, holder, SoundSource.RECORDS, 3.0F, f, world.random.nextLong()); -+ world.playSeededSound((Player) null, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, org.bukkit.craftbukkit.block.data.CraftBlockData.toNMS(event.getInstrument(), NoteBlockInstrument.class).getSoundEvent(), SoundSource.RECORDS, 3.0F, f, world.random.nextLong()); // Paper - return true; - } - + world.playSeededSound((Player) null, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, holder, SoundSource.RECORDS, 3.0F, f, world.random.nextLong());