Search in sources :

Example 16 with LanternWorld

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));
}
Also used : LanternWorld(org.lanternpowered.server.world.LanternWorld) UUID(java.util.UUID)

Example 17 with LanternWorld

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);
}
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 18 with LanternWorld

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);
    }
}
Also used : LanternWorld(org.lanternpowered.server.world.LanternWorld) World(org.spongepowered.api.world.World) LanternWorld(org.lanternpowered.server.world.LanternWorld)

Example 19 with LanternWorld

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);
    }
}
Also used : LanternWorld(org.lanternpowered.server.world.LanternWorld) World(org.spongepowered.api.world.World) LanternWorld(org.lanternpowered.server.world.LanternWorld)

Example 20 with LanternWorld

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;
}
Also used : Cause(org.spongepowered.api.event.cause.Cause) LanternWorld(org.lanternpowered.server.world.LanternWorld) ChangeWorldGameRuleEvent(org.spongepowered.api.event.world.ChangeWorldGameRuleEvent)

Aggregations

LanternWorld (org.lanternpowered.server.world.LanternWorld)20 World (org.spongepowered.api.world.World)7 Vector3d (com.flowpowered.math.vector.Vector3d)6 MessagePlayOutPlayerPositionAndLook (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerPositionAndLook)3 Text (org.spongepowered.api.text.Text)3 ArrayList (java.util.ArrayList)2 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)2 CauseStack (org.lanternpowered.server.event.CauseStack)2 LanternWorldProperties (org.lanternpowered.server.world.LanternWorldProperties)2 Vector2i (com.flowpowered.math.vector.Vector2i)1 Vector3f (com.flowpowered.math.vector.Vector3f)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 Instant (java.time.Instant)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1