use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.
the class UserStore method serialize.
@Override
public void serialize(T entity, DataView dataView) {
super.serialize(entity, dataView);
dataView.remove(HEAD_ROTATION);
final LanternWorld world = entity.getWorld();
final UUID uniqueId = world != null ? world.getUniqueId() : entity.getUserWorld() != null ? entity.getUserWorld().getUniqueId() : null;
dataView.set(DIMENSION, uniqueId == null ? 0 : Lantern.getWorldManager().getWorldDimensionId(uniqueId).orElse(0));
}
use of org.lanternpowered.server.world.LanternWorld 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.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.
the class LanternContainerTileBase method onViewerAdded.
@Override
public void onViewerAdded(Viewer viewer, LanternContainer container, Callback callback) {
if (this.viewers.add(viewer) && this.viewers.size() == 1) {
this.soundDelay = getOpenSoundDelay();
final Location<World> location = getLocation();
final LanternWorld world = (LanternWorld) location.getExtent();
world.addBlockAction(location.getBlockPosition(), getBlock().getType(), ContainerAnimationAction.OPEN);
}
}
use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.
the class LanternContainerTileBase method onViewerRemoved.
@Override
public void onViewerRemoved(Viewer viewer, LanternContainer container, Callback callback) {
if (this.viewers.remove(viewer) && this.viewers.size() == 0) {
this.soundDelay = getCloseSoundDelay();
final Location<World> location = getLocation();
final LanternWorld world = (LanternWorld) location.getExtent();
world.addBlockAction(location.getBlockPosition(), getBlock().getType(), ContainerAnimationAction.CLOSE);
}
}
use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.
the class Rule method setValue0.
private void setValue0(T newValue, @Nullable String newRawValue) {
final Optional<LanternWorld> optWorld = this.rules.getWorld();
if (optWorld.isPresent() && !newValue.equals(this.value)) {
final LanternWorld world = optWorld.get();
if (newRawValue == null) {
newRawValue = this.ruleType.getDataType().serialize(newValue);
}
final Cause cause = CauseStack.current().getCurrentCause();
final ChangeWorldGameRuleEvent event = SpongeEventFactory.createChangeWorldGameRuleEvent(cause, getRawValue(), newRawValue, this.ruleType.getName(), world);
if (Sponge.getEventManager().post(event)) {
return;
}
}
this.value = newValue;
}
Aggregations