Search in sources :

Example 1 with UnmodifiableBlockVolume

use of org.spongepowered.api.world.extent.UnmodifiableBlockVolume in project LanternServer by LanternPowered.

the class LanternBlockVolumeWorker method merge.

@Override
public void merge(BlockVolume second, BlockVolumeMerger merger, MutableBlockVolume destination) {
    final Vector3i offsetSecond = align(second);
    final int xOffsetSecond = offsetSecond.getX();
    final int yOffsetSecond = offsetSecond.getY();
    final int zOffsetSecond = offsetSecond.getZ();
    final Vector3i offsetDestination = align(destination);
    final int xOffsetDestination = offsetDestination.getX();
    final int yOffsetDestination = offsetDestination.getY();
    final int zOffsetDestination = offsetDestination.getZ();
    final UnmodifiableBlockVolume firstUnmodifiableVolume = this.volume.getUnmodifiableBlockView();
    final int xMin = firstUnmodifiableVolume.getBlockMin().getX();
    final int yMin = firstUnmodifiableVolume.getBlockMin().getY();
    final int zMin = firstUnmodifiableVolume.getBlockMin().getZ();
    final int xMax = firstUnmodifiableVolume.getBlockMax().getX();
    final int yMax = firstUnmodifiableVolume.getBlockMax().getY();
    final int zMax = firstUnmodifiableVolume.getBlockMax().getZ();
    final UnmodifiableBlockVolume secondUnmodifiableVolume = second.getUnmodifiableBlockView();
    for (int z = zMin; z <= zMax; z++) {
        for (int y = yMin; y <= yMax; y++) {
            for (int x = xMin; x <= xMax; x++) {
                final BlockState block = merger.merge(firstUnmodifiableVolume, x, y, z, secondUnmodifiableVolume, x + xOffsetSecond, y + yOffsetSecond, z + zOffsetSecond);
                destination.setBlock(x + xOffsetDestination, y + yOffsetDestination, z + zOffsetDestination, block);
            }
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) Vector3i(com.flowpowered.math.vector.Vector3i) UnmodifiableBlockVolume(org.spongepowered.api.world.extent.UnmodifiableBlockVolume)

Example 2 with UnmodifiableBlockVolume

use of org.spongepowered.api.world.extent.UnmodifiableBlockVolume in project LanternServer by LanternPowered.

the class LanternBlockVolumeWorker method reduce.

@Override
public <T> T reduce(BlockVolumeReducer<T> reducer, BiFunction<T, T, T> merge, T identity) {
    final UnmodifiableBlockVolume unmodifiableVolume = this.volume.getUnmodifiableBlockView();
    final int xMin = unmodifiableVolume.getBlockMin().getX();
    final int yMin = unmodifiableVolume.getBlockMin().getY();
    final int zMin = unmodifiableVolume.getBlockMin().getZ();
    final int xMax = unmodifiableVolume.getBlockMax().getX();
    final int yMax = unmodifiableVolume.getBlockMax().getY();
    final int zMax = unmodifiableVolume.getBlockMax().getZ();
    T reduction = identity;
    for (int z = zMin; z <= zMax; z++) {
        for (int y = yMin; y <= yMax; y++) {
            for (int x = xMin; x <= xMax; x++) {
                reduction = reducer.reduce(unmodifiableVolume, x, y, z, reduction);
            }
        }
    }
    return reduction;
}
Also used : UnmodifiableBlockVolume(org.spongepowered.api.world.extent.UnmodifiableBlockVolume)

Example 3 with UnmodifiableBlockVolume

use of org.spongepowered.api.world.extent.UnmodifiableBlockVolume in project LanternServer by LanternPowered.

the class LanternBlockVolumeWorker method map.

@Override
public void map(BlockVolumeMapper mapper, MutableBlockVolume destination) {
    final Vector3i offset = align(destination);
    final int xOffset = offset.getX();
    final int yOffset = offset.getY();
    final int zOffset = offset.getZ();
    final UnmodifiableBlockVolume unmodifiableVolume = this.volume.getUnmodifiableBlockView();
    final int xMin = unmodifiableVolume.getBlockMin().getX();
    final int yMin = unmodifiableVolume.getBlockMin().getY();
    final int zMin = unmodifiableVolume.getBlockMin().getZ();
    final int xMax = unmodifiableVolume.getBlockMax().getX();
    final int yMax = unmodifiableVolume.getBlockMax().getY();
    final int zMax = unmodifiableVolume.getBlockMax().getZ();
    for (int z = zMin; z <= zMax; z++) {
        for (int y = yMin; y <= yMax; y++) {
            for (int x = xMin; x <= xMax; x++) {
                final BlockState block = mapper.map(unmodifiableVolume, x, y, z);
                destination.setBlock(x + xOffset, y + yOffset, z + zOffset, block);
            }
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) Vector3i(com.flowpowered.math.vector.Vector3i) UnmodifiableBlockVolume(org.spongepowered.api.world.extent.UnmodifiableBlockVolume)

Example 4 with UnmodifiableBlockVolume

use of org.spongepowered.api.world.extent.UnmodifiableBlockVolume in project SpongeCommon by SpongePowered.

the class SpongeBlockVolumeWorker method reduce.

@Override
public <T> T reduce(BlockVolumeReducer<T> reducer, BiFunction<T, T, T> merge, T identity) {
    final UnmodifiableBlockVolume unmodifiableVolume = this.volume.getUnmodifiableBlockView();
    final int xMin = unmodifiableVolume.getBlockMin().getX();
    final int yMin = unmodifiableVolume.getBlockMin().getY();
    final int zMin = unmodifiableVolume.getBlockMin().getZ();
    final int xMax = unmodifiableVolume.getBlockMax().getX();
    final int yMax = unmodifiableVolume.getBlockMax().getY();
    final int zMax = unmodifiableVolume.getBlockMax().getZ();
    T reduction = identity;
    for (int z = zMin; z <= zMax; z++) {
        for (int y = yMin; y <= yMax; y++) {
            for (int x = xMin; x <= xMax; x++) {
                reduction = reducer.reduce(unmodifiableVolume, x, y, z, reduction);
            }
        }
    }
    return reduction;
}
Also used : UnmodifiableBlockVolume(org.spongepowered.api.world.extent.UnmodifiableBlockVolume)

Example 5 with UnmodifiableBlockVolume

use of org.spongepowered.api.world.extent.UnmodifiableBlockVolume in project SpongeCommon by SpongePowered.

the class SpongeBlockVolumeWorker method map.

@Override
public void map(BlockVolumeMapper mapper, MutableBlockVolume destination) {
    final Vector3i offset = align(destination);
    final int xOffset = offset.getX();
    final int yOffset = offset.getY();
    final int zOffset = offset.getZ();
    final UnmodifiableBlockVolume unmodifiableVolume = this.volume.getUnmodifiableBlockView();
    final int xMin = unmodifiableVolume.getBlockMin().getX();
    final int yMin = unmodifiableVolume.getBlockMin().getY();
    final int zMin = unmodifiableVolume.getBlockMin().getZ();
    final int xMax = unmodifiableVolume.getBlockMax().getX();
    final int yMax = unmodifiableVolume.getBlockMax().getY();
    final int zMax = unmodifiableVolume.getBlockMax().getZ();
    // a single go, requiring only one event
    try (BasicPluginContext phaseState = PluginPhase.State.BLOCK_WORKER.createPhaseContext().source(this).buildAndSwitch()) {
        for (int z = zMin; z <= zMax; z++) {
            for (int y = yMin; y <= yMax; y++) {
                for (int x = xMin; x <= xMax; x++) {
                    final BlockState block = mapper.map(unmodifiableVolume, x, y, z);
                    destination.setBlock(x + xOffset, y + yOffset, z + zOffset, block);
                }
            }
        }
    }
}
Also used : BasicPluginContext(org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext) BlockState(org.spongepowered.api.block.BlockState) Vector3i(com.flowpowered.math.vector.Vector3i) UnmodifiableBlockVolume(org.spongepowered.api.world.extent.UnmodifiableBlockVolume)

Aggregations

UnmodifiableBlockVolume (org.spongepowered.api.world.extent.UnmodifiableBlockVolume)6 Vector3i (com.flowpowered.math.vector.Vector3i)4 BlockState (org.spongepowered.api.block.BlockState)4 BasicPluginContext (org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext)2