NoteInstrument - Lemonszz/LKLib GitHub Wiki

NoteInstruments are a way to create custom Note Block Instruments.

Simply create a NoteInstrument instance, as your instrument will work!

NoteInstument

NoteInstument is an abstract class that can be implemented to provide a sound for a given blockstate. Usually you will only need to implement isValidState, though see the implementation classes below to see if your usecase is already covered.

isValidState

This method will determine if a given blockstate is a valid instrument. This has no default implementation.

play

This the method that will be called to play the sound, if you wish to do custom logic when playing your sound, this is the place to do it.
The default implementation is identical to vanilla.

getPitch

Get pitch will determine the pitch the sound plays at.
The default implementation is identical to vanilla.

doParticle

This method will add the noteblock particle.
The default implementation is identical to vanilla.

Implementations

BlockNoteInstrument

This will accept a single block. This is the most generic of the implementations.

BlockStateNoteInstrument

This will accept a single blockstate. If you wish to have a specific BlockState trigger your instrument, this is for you.

TagNoteInstrument

This will accept a Tag<Block>. Any block that matches the tag will trigger the instrument. If you wish to have a group of blocks trigger your instrument, this is probably the one for you.

PredicateNoteInstrument

This accepts a Predicate<BlockState> to determine if the instrument matches. This is useful if you have complex logic related to the BlockState.

Creating your own implementation is easy, simple extend NoteInstrument

Usage

Creating the NoteInstrument instance is enough to register your instrument. I would recommend creating the NoteInstrument instance after blocks have been initialized.

It's not necessary to keep the reference to your NoteInstrument. It will be stored in NoteInstrument.INSTRUMENTS if you need to access it later.
NoteInstrument.INSTRUMENTS is a modifiable list if you wish to remove your instruments from it or add to it later on, though be careful of other mod's instruments.

public class MyMod implements ModInitializer
{
        public static NoteInstrument RANDOM_SCREAMING_NOTE;        

	@Override
	public void onInitialize()
	{
             ModBlocks.init();
             RANDOM_SCREAMING_NOTE = new BlockNoteInstument(ModBlocks.SCREAMING_SKULL, ModSounds.NOTE_SCREAMING);
        }
}
⚠️ **GitHub.com Fallback** ⚠️