Search in sources :

Example 6 with UnmodifiableBlockVolume

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

the class SpongeBlockVolumeWorker 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();
    try (BasicPluginContext context = 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 = merger.merge(firstUnmodifiableVolume, x, y, z, secondUnmodifiableVolume, x + xOffsetSecond, y + yOffsetSecond, z + zOffsetSecond);
                    destination.setBlock(x + xOffsetDestination, y + yOffsetDestination, z + zOffsetDestination, 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