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