Search in sources :

Example 1 with LanternScheduledBlockUpdate

use of org.lanternpowered.server.block.LanternScheduledBlockUpdate in project LanternServer by LanternPowered.

the class LanternChunk method pulse.

public void pulse() {
    // The update entry
    LanternScheduledBlockUpdate update;
    while ((update = this.scheduledBlockUpdateQueue.peek()) != null && update.getTicks() <= 0) {
        // Remove the entry from the queue
        this.scheduledBlockUpdateQueue.poll();
    // TODO: Update
    }
    final CauseStack causeStack = CauseStack.current();
    // Add the chunk that is being pulsed
    causeStack.pushCause(this);
    getTileEntities().forEach(tileEntity -> {
        // Add the tile entity to the cause
        causeStack.pushCause(tileEntity);
        try {
            ((LanternTileEntity) tileEntity).pulse();
        } catch (Throwable t) {
            final Vector3i pos = tileEntity.getLocation().getBlockPosition();
            Lantern.getLogger().error("Failed to pulse TileEntity at ({};{};{})", pos.getX(), pos.getY(), pos.getZ(), t);
        } finally {
            // Pop the tile entity
            causeStack.popCause();
        }
    });
    // Pop the chunk
    causeStack.popCause();
}
Also used : CauseStack(org.lanternpowered.server.event.CauseStack) LanternScheduledBlockUpdate(org.lanternpowered.server.block.LanternScheduledBlockUpdate) Vector3i(com.flowpowered.math.vector.Vector3i) LanternTileEntity(org.lanternpowered.server.block.tile.LanternTileEntity)

Example 2 with LanternScheduledBlockUpdate

use of org.lanternpowered.server.block.LanternScheduledBlockUpdate in project LanternServer by LanternPowered.

the class LanternChunk method addScheduledUpdate.

@Override
public ScheduledBlockUpdate addScheduledUpdate(int x, int y, int z, int priority, int ticks) {
    checkVolumeBounds(x, y, z);
    final int entryId = this.scheduledBlockUpdateCounter.getAndIncrement();
    final Location<World> location = new Location<>(this.world, new Vector3i(x, y, z));
    final LanternScheduledBlockUpdate update = new LanternScheduledBlockUpdate(entryId, location, ticks, priority);
    this.scheduledBlockUpdateQueue.add(update);
    return update;
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) LanternScheduledBlockUpdate(org.lanternpowered.server.block.LanternScheduledBlockUpdate) World(org.spongepowered.api.world.World) LanternWorld(org.lanternpowered.server.world.LanternWorld) Location(org.spongepowered.api.world.Location)

Aggregations

Vector3i (com.flowpowered.math.vector.Vector3i)2 LanternScheduledBlockUpdate (org.lanternpowered.server.block.LanternScheduledBlockUpdate)2 LanternTileEntity (org.lanternpowered.server.block.tile.LanternTileEntity)1 CauseStack (org.lanternpowered.server.event.CauseStack)1 LanternWorld (org.lanternpowered.server.world.LanternWorld)1 Location (org.spongepowered.api.world.Location)1 World (org.spongepowered.api.world.World)1