Search in sources :

Example 1 with LanternBlockSnapshot

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

the class LanternBlockState method snapshotFor.

@Override
public BlockSnapshot snapshotFor(Location<World> location) {
    final World world = location.getExtent();
    final Vector3i pos = location.getBlockPosition();
    // TODO: Tile entity data
    return new LanternBlockSnapshot(location, this, this, world.getCreator(pos), world.getNotifier(pos), ImmutableMap.of());
}
Also used : LanternBlockSnapshot(org.lanternpowered.server.block.LanternBlockSnapshot) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World)

Example 2 with LanternBlockSnapshot

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

the class LanternChunk method createSnapshot.

@Override
public BlockSnapshot createSnapshot(int x, int y, int z) {
    final BlockState state = getBlock(x, y, z);
    final Location<World> loc = new Location<>(this.world, x, y, z);
    // TODO: Tile entity data
    return new LanternBlockSnapshot(loc, state, ((LanternBlockType) state.getType()).getExtendedBlockStateProvider().get(state, loc, null), getCreator(x, y, z), getNotifier(x, y, z), ImmutableMap.of());
}
Also used : LanternBlockSnapshot(org.lanternpowered.server.block.LanternBlockSnapshot) BlockState(org.spongepowered.api.block.BlockState) World(org.spongepowered.api.world.World) LanternWorld(org.lanternpowered.server.world.LanternWorld) LanternBlockType(org.lanternpowered.server.block.LanternBlockType) Location(org.spongepowered.api.world.Location)

Example 3 with LanternBlockSnapshot

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

the class BehaviorContextImpl method transformBlockChanges.

@Override
public void transformBlockChanges(BiConsumer<BlockSnapshot, BlockSnapshotBuilder> snapshotTransformer) {
    checkNotNull(snapshotTransformer, "snapshotTransformer");
    final Set<BlockSnapshot> newPositionlessBlockSnapshots = new HashSet<>();
    final Map<Location<World>, BlockSnapshot> newBlockSnapshots = new HashMap<>();
    final BlockSnapshotBuilder builder = BlockSnapshotBuilder.createPositionless();
    for (BlockSnapshot blockSnapshot : Iterables.concat(this.positionlessBlockSnapshots, this.blockSnapshots.values())) {
        builder.from(blockSnapshot);
        snapshotTransformer.accept(blockSnapshot, builder);
        final BlockSnapshot result = builder.build();
        if (((LanternBlockSnapshot) result).isPositionless()) {
            newPositionlessBlockSnapshots.add(result);
        } else {
            final Location<World> loc = blockSnapshot.getLocation().orElseThrow(() -> new IllegalArgumentException("Unable to retrieve the location of the block snapshot, is the world loaded?"));
            checkArgument(newBlockSnapshots.putIfAbsent(loc, result) == null, "There is already a block snapshot present for the location: %s", loc);
        }
    }
    this.positionlessBlockSnapshots = newPositionlessBlockSnapshots;
    this.blockSnapshots = newBlockSnapshots;
}
Also used : LanternBlockSnapshot(org.lanternpowered.server.block.LanternBlockSnapshot) HashMap(java.util.HashMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) LanternBlockSnapshot(org.lanternpowered.server.block.LanternBlockSnapshot) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) HashSet(java.util.HashSet) Location(org.spongepowered.api.world.Location) BlockSnapshotBuilder(org.lanternpowered.server.block.BlockSnapshotBuilder)

Example 4 with LanternBlockSnapshot

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

the class BehaviorContextImpl method transformBlockChangesWithFunction.

@Override
public void transformBlockChangesWithFunction(Function<BlockSnapshot, BlockSnapshot> snapshotTransformer) {
    checkNotNull(snapshotTransformer, "snapshotTransformer");
    final Set<BlockSnapshot> newPositionlessBlockSnapshots = new HashSet<>();
    final Map<Location<World>, BlockSnapshot> newBlockSnapshots = new HashMap<>();
    final BlockSnapshotBuilder builder = BlockSnapshotBuilder.createPositionless();
    for (BlockSnapshot blockSnapshot : Iterables.concat(this.positionlessBlockSnapshots, this.blockSnapshots.values())) {
        final BlockSnapshot newSnapshot = snapshotTransformer.apply(blockSnapshot);
        if (newSnapshot == null) {
            continue;
        }
        final BlockSnapshot result = builder.build();
        if (((LanternBlockSnapshot) result).isPositionless()) {
            newPositionlessBlockSnapshots.add(result);
        } else {
            final Location<World> loc = blockSnapshot.getLocation().orElseThrow(() -> new IllegalArgumentException("Unable to retrieve the location of the block snapshot, is the world loaded?"));
            checkArgument(newBlockSnapshots.putIfAbsent(loc, blockSnapshot) == null, "There is already a block snapshot present for the location: %s", loc);
        }
    }
    this.positionlessBlockSnapshots = newPositionlessBlockSnapshots;
    this.blockSnapshots = newBlockSnapshots;
}
Also used : LanternBlockSnapshot(org.lanternpowered.server.block.LanternBlockSnapshot) HashMap(java.util.HashMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) LanternBlockSnapshot(org.lanternpowered.server.block.LanternBlockSnapshot) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) HashSet(java.util.HashSet) Location(org.spongepowered.api.world.Location) BlockSnapshotBuilder(org.lanternpowered.server.block.BlockSnapshotBuilder)

Aggregations

LanternBlockSnapshot (org.lanternpowered.server.block.LanternBlockSnapshot)4 World (org.spongepowered.api.world.World)4 Location (org.spongepowered.api.world.Location)3 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 BlockSnapshotBuilder (org.lanternpowered.server.block.BlockSnapshotBuilder)2 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 LanternBlockType (org.lanternpowered.server.block.LanternBlockType)1 LanternWorld (org.lanternpowered.server.world.LanternWorld)1 BlockState (org.spongepowered.api.block.BlockState)1