aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0916-fix-Instruments.patch
blob: 3495ef15b0b54d30813c16f937b65387c88c9229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
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 151788d379000ee4d3f5d1d51c014da8e8cd21a5..3fa3e0bd52bf2f3135f189629a4bd43ad6248fe2 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -744,62 +744,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
     public void playNote(Location loc, Instrument instrument, Note note) {
         if (this.getHandle().connection == null) return;
 
-        String instrumentName = null;
-        switch (instrument.ordinal()) {
-            case 0:
-                instrumentName = "harp";
-                break;
-            case 1:
-                instrumentName = "basedrum";
-                break;
-            case 2:
-                instrumentName = "snare";
-                break;
-            case 3:
-                instrumentName = "hat";
-                break;
-            case 4:
-                instrumentName = "bass";
-                break;
-            case 5:
-                instrumentName = "flute";
-                break;
-            case 6:
-                instrumentName = "bell";
-                break;
-            case 7:
-                instrumentName = "guitar";
-                break;
-            case 8:
-                instrumentName = "chime";
-                break;
-            case 9:
-                instrumentName = "xylophone";
-                break;
-            case 10:
-                instrumentName = "iron_xylophone";
-                break;
-            case 11:
-                instrumentName = "cow_bell";
-                break;
-            case 12:
-                instrumentName = "didgeridoo";
-                break;
-            case 13:
-                instrumentName = "bit";
-                break;
-            case 14:
-                instrumentName = "banjo";
-                break;
-            case 15:
-                instrumentName = "pling";
-                break;
-            case 16:
-                instrumentName = "xylophone";
-                break;
+        // Paper start - fix all this (modeled off of NoteBlock)
+        net.minecraft.world.level.block.state.properties.NoteBlockInstrument nms = CraftBlockData.toNMS(instrument, net.minecraft.world.level.block.state.properties.NoteBlockInstrument.class);
+        float f;
+        if (nms.isTunable()) {
+            f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D);
+        } else {
+            f = 1.0f;
         }
-        float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D);
-        this.getHandle().connection.send(new ClientboundSoundPacket(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(CraftSound.getSoundEffect("block.note_block." + instrumentName)), net.minecraft.sounds.SoundSource.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, this.getHandle().getRandom().nextLong()));
+        if (!nms.hasCustomSound()) {
+            this.getHandle().connection.send(new ClientboundSoundPacket(nms.getSoundEvent(), net.minecraft.sounds.SoundSource.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f, this.getHandle().getRandom().nextLong()));
+        }
+        // Paper end
     }
 
     @Override