use of org.spongepowered.api.data.type.InstrumentType in project SpongeCommon by SpongePowered.
the class InstrumentTestPlugin method onUseItem.
@Listener
public void onUseItem(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
if (!enabled || !player.get(Keys.IS_SNEAKING).get()) {
return;
}
final BlockSnapshot snapshot = event.getTargetBlock();
if (snapshot.getState().getType().equals(BlockTypes.NOTEBLOCK)) {
final InstrumentProperty instrumentProperty = player.getWorld().getBlock(snapshot.getPosition().sub(0, 1, 0)).getProperty(InstrumentProperty.class).orElse(null);
if (instrumentProperty != null) {
final InstrumentType instrument = instrumentProperty.getValue();
player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a note block with instrument: ", TextColors.GREEN, instrument.getName()));
} else {
player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a note block that strangely did not have any instrument type."));
}
} else {
final InstrumentProperty instrumentProperty = snapshot.getProperty(InstrumentProperty.class).orElse(null);
if (instrumentProperty != null) {
final InstrumentType instrument = instrumentProperty.getValue();
player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a block with instrument type: ", TextColors.GREEN, instrument.getName()));
} else {
player.sendMessage(Text.of(TextColors.DARK_GREEN, "Clicked on a block which had no instrument type."));
}
}
}
use of org.spongepowered.api.data.type.InstrumentType 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);
}
Aggregations