use of com.sk89q.worldedit.world.block.BlockStateHolder in project FastAsyncWorldEdit by IntellectualSites.
the class Extent method setBlocks.
/**
* Sets all the blocks inside a region to a given pattern.
*
* @param region the region
* @param pattern the pattern that provides the replacement block
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
default int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
checkNotNull(region);
checkNotNull(pattern);
if (pattern instanceof BlockPattern) {
return setBlocks(region, ((BlockPattern) pattern).getBlock());
}
if (pattern instanceof BlockStateHolder) {
return setBlocks(region, (BlockStateHolder) pattern);
}
int count = 0;
for (BlockVector3 pos : region) {
if (pattern.apply(this, pos, pos)) {
count++;
}
}
return count;
}
use of com.sk89q.worldedit.world.block.BlockStateHolder in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method sphereBrush.
@Command(name = "sphere", aliases = { "s" }, desc = "Choose the sphere brush")
@CommandPermissions("worldedit.brush.sphere")
public void sphereBrush(Player player, InjectedValueAccess context, @Arg(desc = "The pattern of blocks to set") Pattern pattern, @Arg(desc = "The radius of the sphere", def = "2") Expression radius, @Switch(name = 'h', desc = "Create hollow spheres instead") boolean hollow, @Switch(name = 'f', desc = "Create falling spheres instead") boolean falling) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius);
Brush brush;
if (hollow) {
brush = new HollowSphereBrush();
} else {
// FAWE start - Suggest different brush material if sand or gravel is used
if (pattern instanceof BlockStateHolder) {
BlockType type = ((BlockStateHolder) pattern).getBlockType();
switch(type.getId()) {
case "minecraft:sand":
case "minecraft:gravel":
player.print(Caption.of("fawe.worldedit.brush.brush.try.other"));
falling = true;
break;
default:
break;
}
}
if (falling) {
brush = new FallingSphere();
} else {
brush = new SphereBrush();
}
}
// FAWE end
set(context, brush, "worldedit.brush.sphere").setSize(radius).setFill(pattern);
}
use of com.sk89q.worldedit.world.block.BlockStateHolder in project FastAsyncWorldEdit by IntellectualSites.
the class ToolCommands method longrangebuildtool.
@Command(name = "lrbuild", aliases = { "/lrbuild" }, desc = "Long-range building tool")
@CommandPermissions("worldedit.tool.lrbuild")
public void longrangebuildtool(Player player, LocalSession session, @Arg(desc = "Pattern to set on left-click") Pattern primary, @Arg(desc = "Pattern to set on right-click") Pattern secondary) throws WorldEditException {
setTool(player, session, new LongRangeBuildTool(primary, secondary), "worldedit.tool.lrbuild.equip");
Component primaryName;
Component secondaryName;
if (primary instanceof BlockStateHolder) {
primaryName = ((BlockStateHolder<?>) primary).getBlockType().getRichName();
} else {
primaryName = TextComponent.of("pattern");
}
if (secondary instanceof BlockStateHolder) {
secondaryName = ((BlockStateHolder<?>) secondary).getBlockType().getRichName();
} else {
secondaryName = TextComponent.of("pattern");
}
player.print(Caption.of("worldedit.tool.lrbuild.set", primaryName, secondaryName));
}
use of com.sk89q.worldedit.world.block.BlockStateHolder in project FastAsyncWorldEdit by IntellectualSites.
the class NoisePatternParser method parseFromInput.
@Override
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) {
if (arguments.length != 2) {
throw new InputParseException(Caption.of("fawe.error.command.syntax", TextComponent.of(getPrefix() + "[scale][pattern] (e.g. " + getPrefix() + "[5][dirt,stone])")));
}
double scale = parseScale(arguments[0]);
Pattern inner = worldEdit.getPatternFactory().parseFromInput(arguments[1], context);
if (inner instanceof RandomPattern) {
return new RandomPattern(new NoiseRandom(this.generatorSupplier.get(), scale), (RandomPattern) inner);
} else if (inner instanceof BlockStateHolder) {
// single blocks won't have any impact on how a noise behaves
return inner;
} else {
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName() + " cannot be used with #" + this.name));
}
}
use of com.sk89q.worldedit.world.block.BlockStateHolder in project FastAsyncWorldEdit by IntellectualSites.
the class HeightMap method applyLayers.
public int applyLayers(int[] data) {
checkNotNull(data);
BlockVector3 min = region.getMinimumPoint();
int originX = min.getBlockX();
int originZ = min.getBlockZ();
int maxY = region.getMaximumPoint().getBlockY();
BlockState fillerAir = BlockTypes.AIR.getDefaultState();
int blocksChanged = 0;
BlockStateHolder<BlockState> tmpBlock = BlockTypes.AIR.getDefaultState();
int maxY4 = maxY << 4;
int index = 0;
// Apply heightmap
for (int z = 0; z < height; ++z) {
int zr = z + originZ;
for (int x = 0; x < width; ++x) {
int curHeight = this.data[index];
// Clamp newHeight within the selection area
int newHeight = Math.min(maxY4, data[index++]);
int curBlock = (curHeight) >> 4;
int newBlock = (newHeight + 15) >> 4;
// Offset x,z to be 'real' coordinates
int xr = x + originX;
// Depending on growing or shrinking we need to start at the bottom or top
if (newHeight > curHeight) {
// Set the top block of the column to be the same type (this might go wrong with rounding)
BlockStateHolder<BlockState> existing = session.getBlock(xr, curBlock, zr);
// Skip water/lava
if (!existing.getBlockType().getMaterial().isLiquid()) {
// Grow -- start from 1 below top replacing airblocks
for (int setY = newBlock - 1, getY = curBlock; setY >= curBlock; --setY, getY--) {
BlockStateHolder<BlockState> get = session.getBlock(xr, getY, zr);
if (get != BlockTypes.AIR.getDefaultState()) {
tmpBlock = get;
}
session.setBlock(xr, setY, zr, tmpBlock);
++blocksChanged;
}
int setData = newHeight & 15;
if (setData != 0) {
existing = PropertyGroup.LEVEL.set(existing, setData - 1);
session.setBlock(xr, newBlock, zr, existing);
++blocksChanged;
} else {
existing = PropertyGroup.LEVEL.set(existing, 15);
session.setBlock(xr, newBlock, zr, existing);
++blocksChanged;
}
}
} else if (curHeight > newHeight) {
// Fill rest with air
for (int y = newBlock + 1; y <= ((curHeight + 15) >> 4); ++y) {
session.setBlock(xr, y, zr, fillerAir);
++blocksChanged;
}
// Set the top block of the column to be the same type
// (this could otherwise go wrong with rounding)
int setData = newHeight & 15;
BlockStateHolder<BlockState> existing = session.getBlock(xr, curBlock, zr);
if (setData != 0) {
existing = PropertyGroup.LEVEL.set(existing, setData - 1);
session.setBlock(xr, newBlock, zr, existing);
} else {
existing = PropertyGroup.LEVEL.set(existing, 15);
session.setBlock(xr, newBlock, zr, existing);
}
++blocksChanged;
}
}
}
return blocksChanged;
}
Aggregations