Skip to content

Commit 60e46ab

Browse files
authored
Fix NotePlayEvent (#5180)
1 parent dcca6cb commit 60e46ab

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

build-data/paper.at

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,6 @@ public net.minecraft.world.entity.item.ItemEntity health
295295

296296
# Fix riding distance statistics
297297
public net.minecraft.world.entity.player.Player checkRidingStatistics(DDD)V
298+
299+
# Fix NotePlayEvent
300+
public org.bukkit.craftbukkit.block.data.CraftBlockData toNMS(Ljava/lang/Enum;Ljava/lang/Class;)Ljava/lang/Enum;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Kieran Wallbanks <kieran.wallbanks@gmail.com>
3+
Date: Mon, 21 Jun 2021 12:33:45 +0100
4+
Subject: [PATCH] Fix NotePlayEvent
5+
6+
7+
diff --git a/src/main/java/org/bukkit/event/block/NotePlayEvent.java b/src/main/java/org/bukkit/event/block/NotePlayEvent.java
8+
index a3887067d1b65fb100ac1407a43c455f5d215510..676b31f6f38d4e85cd4bd16ccf42cbc39a5d8423 100644
9+
--- a/src/main/java/org/bukkit/event/block/NotePlayEvent.java
10+
+++ b/src/main/java/org/bukkit/event/block/NotePlayEvent.java
11+
@@ -58,9 +58,7 @@ public class NotePlayEvent extends BlockEvent implements Cancellable {
12+
* Overrides the {@link Instrument} to be used.
13+
*
14+
* @param instrument the Instrument. Has no effect if null.
15+
- * @deprecated no effect on newer Minecraft versions
16+
*/
17+
- @Deprecated
18+
public void setInstrument(@NotNull Instrument instrument) {
19+
if (instrument != null) {
20+
this.instrument = instrument;
21+
@@ -71,9 +69,7 @@ public class NotePlayEvent extends BlockEvent implements Cancellable {
22+
* Overrides the {@link Note} to be played.
23+
*
24+
* @param note the Note. Has no effect if null.
25+
- * @deprecated no effect on newer Minecraft versions
26+
*/
27+
- @Deprecated
28+
public void setNote(@NotNull Note note) {
29+
if (note != null) {
30+
this.note = note;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Kieran Wallbanks <kieran.wallbanks@gmail.com>
3+
Date: Mon, 21 Jun 2021 14:23:50 +0100
4+
Subject: [PATCH] Fix NotePlayEvent
5+
6+
7+
diff --git a/src/main/java/net/minecraft/world/level/block/NoteBlock.java b/src/main/java/net/minecraft/world/level/block/NoteBlock.java
8+
index 16e11e31077f160198e0b04abdfeabb97ed20c6f..0e106bcc1f882877a5e444a2621466c6e4696d42 100644
9+
--- a/src/main/java/net/minecraft/world/level/block/NoteBlock.java
10+
+++ b/src/main/java/net/minecraft/world/level/block/NoteBlock.java
11+
@@ -60,10 +60,9 @@ public class NoteBlock extends Block {
12+
private void playNote(Level world, BlockPos blockposition, BlockState data) { // CraftBukkit
13+
if (world.getBlockState(blockposition.above()).isAir()) {
14+
// CraftBukkit start
15+
- org.bukkit.event.block.NotePlayEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callNotePlayEvent(world, blockposition, data.getValue(NoteBlock.INSTRUMENT), data.getValue(NoteBlock.NOTE));
16+
- if (!event.isCancelled()) {
17+
+ // Paper start - move NotePlayEvent call to fix instrument/note changes
18+
world.blockEvent(blockposition, this, 0, 0);
19+
- }
20+
+ // Paper end
21+
// CraftBukkit end
22+
}
23+
24+
@@ -92,10 +91,14 @@ public class NoteBlock extends Block {
25+
26+
@Override
27+
public boolean triggerEvent(BlockState state, Level world, BlockPos pos, int type, int data) {
28+
- int k = (Integer) state.getValue(NoteBlock.NOTE);
29+
+ // Paper start - move NotePlayEvent call to fix instrument/note changes
30+
+ org.bukkit.event.block.NotePlayEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callNotePlayEvent(world, pos, state.getValue(INSTRUMENT), state.getValue(NOTE));
31+
+ if (event.isCancelled()) return false;
32+
+ int k = event.getNote().getId();
33+
float f = (float) Math.pow(2.0D, (double) (k - 12) / 12.0D);
34+
35+
- world.playSound((Player) null, pos, ((NoteBlockInstrument) state.getValue(NoteBlock.INSTRUMENT)).getSoundEvent(), SoundSource.RECORDS, 3.0F, f);
36+
+ world.playSound(null, pos, org.bukkit.craftbukkit.block.data.CraftBlockData.toNMS(event.getInstrument(), NoteBlockInstrument.class).getSoundEvent(), SoundSource.RECORDS, 3.0F, f);
37+
+ // Paper end
38+
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);
39+
return true;
40+
}

0 commit comments

Comments
 (0)