Skip to content

Commit

Permalink
materialtag.produced_instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 1, 2021
1 parent f8f8c22 commit 9de6b7e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Up @@ -591,6 +591,18 @@ public static void registerTags() {
}
return new ListTag(tags);
});

// <--[tag]
// @attribute <MaterialTag.produced_instrument>
// @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<MaterialTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down
Expand Up @@ -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.<MaterialInstrument>registerTag("instrument", (attribute, material) -> {
return new ElementTag(material.getNoteBlock().getInstrument().name());
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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())];
}
}

0 comments on commit 9de6b7e

Please sign in to comment.