Search in sources :

Example 6 with NotePitch

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);
}
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)

Example 7 with NotePitch

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());
}
Also used : NotePitch(org.spongepowered.api.data.type.NotePitch) LanternNotePitch(org.lanternpowered.server.data.type.LanternNotePitch)

Aggregations

NotePitch (org.spongepowered.api.data.type.NotePitch)7 Vector3d (com.flowpowered.math.vector.Vector3d)4 BlockState (org.spongepowered.api.block.BlockState)4 Color (org.spongepowered.api.util.Color)4 LanternNotePitch (org.lanternpowered.server.data.type.LanternNotePitch)3 ItemType (org.spongepowered.api.item.ItemType)3 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)3 Direction (org.spongepowered.api.util.Direction)3 Vector3f (com.flowpowered.math.vector.Vector3f)2 Optional (java.util.Optional)2 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)2 FireworkEffect (org.spongepowered.api.item.FireworkEffect)2 World (org.spongepowered.api.world.World)2 SpongeNotePitch (org.spongepowered.common.data.type.SpongeNotePitch)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 TypeToken (com.google.common.reflect.TypeToken)1 Field (java.lang.reflect.Field)1 Instant (java.time.Instant)1 List (java.util.List)1 OptionalInt (java.util.OptionalInt)1