diff --git a/plugin/src/main/java/com/denizenscript/denizen/nms/interfaces/BlockHelper.java b/plugin/src/main/java/com/denizenscript/denizen/nms/interfaces/BlockHelper.java index 2154b9ab79..1a404ca1a3 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/nms/interfaces/BlockHelper.java +++ b/plugin/src/main/java/com/denizenscript/denizen/nms/interfaces/BlockHelper.java @@ -2,6 +2,7 @@ import com.denizenscript.denizen.nms.util.PlayerProfile; import com.denizenscript.denizen.nms.util.jnbt.CompoundTag; +import org.bukkit.Instrument; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -78,4 +79,8 @@ default void makeBlockStateRaw(BlockState state) { default void doRandomTick(Location location) { throw new UnsupportedOperationException(); } + + default Instrument getInstrumentFor(Material mat) { + throw new UnsupportedOperationException(); + } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/MaterialTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/MaterialTag.java index 983d97537c..9169b21e55 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/MaterialTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/MaterialTag.java @@ -591,6 +591,18 @@ public static void registerTags() { } return new ListTag(tags); }); + + // <--[tag] + // @attribute + // @returns ElementTag + // @description + // Returns the name of the instrument that would be used by a note block placed above a block of this material. + // See list at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Instrument.html>. + // For the current instrument of a note block material refer to <@link tag MaterialTag.instrument>. + // --> + registerTag("produced_instrument", (attribute, object) -> { + return new ElementTag(NMSHandler.getBlockHelper().getInstrumentFor(object.getMaterial()).name()); + }); } public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialInstrument.java b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialInstrument.java index eae9429d10..58dbb1593a 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialInstrument.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/properties/material/MaterialInstrument.java @@ -46,6 +46,7 @@ public static void registerTags() { // @description // Returns the name of the instrument played from this note block, // see list at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Instrument.html>. + // For the instrument that a material *would* produce if below a noteblock <@link tag MaterialTag.produced_instrument>. // --> PropertyParser.registerTag("instrument", (attribute, material) -> { return new ElementTag(material.getNoteBlock().getInstrument().name()); diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/helpers/BlockHelperImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/helpers/BlockHelperImpl.java index 5760a9fdfd..2e086c49cb 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/helpers/BlockHelperImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/helpers/BlockHelperImpl.java @@ -20,8 +20,10 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.material.PushReaction; +import org.bukkit.Instrument; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -270,4 +272,11 @@ public void doRandomTick(Location location) { Debug.echoError(ex); } } + + @Override + public Instrument getInstrumentFor(Material mat) { + net.minecraft.world.level.block.Block blockType = getBlockFrom(mat); + NoteBlockInstrument nmsInstrument = NoteBlockInstrument.byState(blockType.defaultBlockState()); + return Instrument.values()[(nmsInstrument.ordinal())]; + } }