Search in sources :

Example 1 with NoteAction

use of org.lanternpowered.server.block.action.vanilla.NoteAction 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);
}
Also used : NoteAction(org.lanternpowered.server.block.action.vanilla.NoteAction) InstrumentType(org.spongepowered.api.data.type.InstrumentType) LanternWorld(org.lanternpowered.server.world.LanternWorld) World(org.spongepowered.api.world.World) LanternWorld(org.lanternpowered.server.world.LanternWorld) NotePitch(org.spongepowered.api.data.type.NotePitch) LanternNotePitch(org.lanternpowered.server.data.type.LanternNotePitch)

Aggregations

NoteAction (org.lanternpowered.server.block.action.vanilla.NoteAction)1 LanternNotePitch (org.lanternpowered.server.data.type.LanternNotePitch)1 LanternWorld (org.lanternpowered.server.world.LanternWorld)1 InstrumentType (org.spongepowered.api.data.type.InstrumentType)1 NotePitch (org.spongepowered.api.data.type.NotePitch)1 World (org.spongepowered.api.world.World)1