Search in sources :

Example 11 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class BlockTransformExtent method transform.

/**
 * Transform the given block using the given transform.
 *
 * <p>The provided block is <em>not</em> modified.</p>
 *
 * @param block     the block
 * @param transform the transform
 * @return the same block
 */
public static <B extends BlockStateHolder<B>> B transform(@Nonnull B block, @Nonnull Transform transform) {
    // FAWE start - use own logic
    // performance critical
    BlockState state = block.toImmutableState();
    int transformedId = transformState(state, transform);
    BlockState transformed = BlockState.getFromInternalId(transformedId);
    if (block.hasNbtData()) {
        return (B) transformBaseBlockNBT(transformed, block.getNbtData(), transform);
    }
    return (B) (block instanceof BaseBlock ? transformed.toBaseBlock() : transformed);
// FAWE end
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Example 12 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class ChunkBatchingExtent method commitBefore.

@Override
protected Operation commitBefore() {
    if (!commitRequired()) {
        return null;
    }
    return new Operation() {

        // we get modified between create/resume -- only create this on resume to prevent CME
        private Iterator<BlockVector3> iterator;

        @Override
        public Operation resume(RunContext run) throws WorldEditException {
            if (iterator == null) {
                List<BlockVector3> blockVectors = new ArrayList<>(blockMap.keySet());
                RegionOptimizedVectorSorter.sort(blockVectors);
                iterator = blockVectors.iterator();
            }
            while (iterator.hasNext()) {
                BlockVector3 position = iterator.next();
                BaseBlock block = blockMap.get(position);
                getExtent().setBlock(position, block);
            }
            blockMap.clear();
            return null;
        }

        @Override
        public void cancel() {
        }
    };
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) RunContext(com.sk89q.worldedit.function.operation.RunContext) Operation(com.sk89q.worldedit.function.operation.Operation) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Example 13 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class ChangeSetExtent method setBlock.

@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
    BaseBlock previous = getFullBlock(location);
    changeSet.add(new BlockChange(location, previous, block));
    return super.setBlock(location, block);
}
Also used : BlockChange(com.sk89q.worldedit.history.change.BlockChange) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Example 14 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class Extent method setBlocks.

/**
 * Sets all the blocks inside a region to a given block type.
 *
 * @param region the region
 * @param block  the block
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
default <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException {
    checkNotNull(region);
    checkNotNull(block);
    boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();
    int changes = 0;
    for (BlockVector3 pos : region) {
        if (setBlock(pos, block)) {
            changes++;
        }
    }
    return changes;
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Example 15 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class MultiStageReorder method commitBefore.

@Override
public Operation commitBefore() {
    if (!commitRequired()) {
        return null;
    }
    List<Operation> operations = new ArrayList<>();
    for (PlacementPriority priority : PlacementPriority.values()) {
        BlockMap<BaseBlock> blocks = stages.get(priority);
        operations.add(new SetBlockMap(getExtent(), blocks) {

            @Override
            public Operation resume(RunContext run) throws WorldEditException {
                Operation operation = super.resume(run);
                if (operation == null) {
                    blocks.clear();
                }
                return operation;
            }
        });
    }
    return new OperationQueue(operations);
}
Also used : OperationQueue(com.sk89q.worldedit.function.operation.OperationQueue) ArrayList(java.util.ArrayList) RunContext(com.sk89q.worldedit.function.operation.RunContext) Operation(com.sk89q.worldedit.function.operation.Operation) WorldEditException(com.sk89q.worldedit.WorldEditException) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) SetBlockMap(com.sk89q.worldedit.function.operation.SetBlockMap)

Aggregations

BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)50 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)22 BlockState (com.sk89q.worldedit.world.block.BlockState)10 CompoundTag (com.sk89q.jnbt.CompoundTag)9 HashMap (java.util.HashMap)7 Tag (com.sk89q.jnbt.Tag)6 Location (com.sk89q.worldedit.util.Location)6 World (com.sk89q.worldedit.world.World)6 BlockType (com.sk89q.worldedit.world.block.BlockType)6 IOException (java.io.IOException)6 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)5 ListTag (com.sk89q.jnbt.ListTag)5 StringTag (com.sk89q.jnbt.StringTag)5 WorldEditException (com.sk89q.worldedit.WorldEditException)5 ArrayList (java.util.ArrayList)5 IntTag (com.sk89q.jnbt.IntTag)4 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)4 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)4 Region (com.sk89q.worldedit.regions.Region)4 NamedTag (com.sk89q.jnbt.NamedTag)3