use of org.spongepowered.api.data.type.NotePitch in project LanternServer by LanternPowered.
the class LanternNote method playNote.
@Override
public void playNote() {
final Location<World> location = getLocation();
final Location<World> downLocation = location.add(0, -1, 0);
// Get the instrument type based on the underlying block
final InstrumentType instrumentType = downLocation.getProperty(InstrumentProperty.class).map(InstrumentProperty::getValue).orElse(InstrumentTypes.HARP);
final NotePitch notePitch = get(Keys.NOTE_PITCH).get();
// Trigger the note play effect
((LanternWorld) location.getExtent()).addBlockAction(location.getBlockPosition(), getBlock().getType(), new NoteAction(instrumentType, notePitch));
// Calculate the pitch value based on the note pitch
double pitch = (double) ((LanternNotePitch) notePitch).getInternalId();
pitch = Math.pow(2.0, (pitch - 12.0) / 12.0);
location.getExtent().playSound(instrumentType.getSound(), SoundCategories.BLOCK, location.getPosition().add(0.5, 0.5, 0.5), 3.0, pitch);
}
use of org.spongepowered.api.data.type.NotePitch in project LanternServer by LanternPowered.
the class LanternNote method nextNote.
/**
* Cycles the current {@link NotePitch} to the next one.
*/
public void nextNote() {
final NotePitch notePitch = get(Keys.NOTE_PITCH).get();
offer(Keys.NOTE_PITCH, notePitch.cycleNext());
}
Aggregations