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());
}
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());
}
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;
}
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;
}
Aggregations