Search in sources :

Example 1 with BlockStateHolder

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;
}
Also used : BlockPattern(com.sk89q.worldedit.function.pattern.BlockPattern) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3)

Example 2 with BlockStateHolder

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);
}
Also used : HollowSphereBrush(com.sk89q.worldedit.command.tool.brush.HollowSphereBrush) BlockType(com.sk89q.worldedit.world.block.BlockType) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) FallingSphere(com.fastasyncworldedit.core.command.tool.brush.FallingSphere) HollowSphereBrush(com.sk89q.worldedit.command.tool.brush.HollowSphereBrush) HeightBrush(com.fastasyncworldedit.core.command.tool.brush.HeightBrush) SphereBrush(com.sk89q.worldedit.command.tool.brush.SphereBrush) ScatterBrush(com.fastasyncworldedit.core.command.tool.brush.ScatterBrush) CopyPastaBrush(com.fastasyncworldedit.core.command.tool.brush.CopyPastaBrush) RaiseBrush(com.fastasyncworldedit.core.command.tool.brush.RaiseBrush) SnowSmoothBrush(com.sk89q.worldedit.command.tool.brush.SnowSmoothBrush) ClipboardBrush(com.sk89q.worldedit.command.tool.brush.ClipboardBrush) GravityBrush(com.sk89q.worldedit.command.tool.brush.GravityBrush) FlattenBrush(com.fastasyncworldedit.core.command.tool.brush.FlattenBrush) BlobBrush(com.fastasyncworldedit.core.command.tool.brush.BlobBrush) SweepBrush(com.fastasyncworldedit.core.command.tool.sweep.SweepBrush) CircleBrush(com.fastasyncworldedit.core.command.tool.brush.CircleBrush) SplatterBrush(com.fastasyncworldedit.core.command.tool.brush.SplatterBrush) CatenaryBrush(com.fastasyncworldedit.core.command.tool.brush.CatenaryBrush) RecurseBrush(com.fastasyncworldedit.core.command.tool.brush.RecurseBrush) CylinderBrush(com.sk89q.worldedit.command.tool.brush.CylinderBrush) ScatterOverlayBrush(com.fastasyncworldedit.core.command.tool.brush.ScatterOverlayBrush) StencilBrush(com.fastasyncworldedit.core.command.tool.brush.StencilBrush) LineBrush(com.fastasyncworldedit.core.command.tool.brush.LineBrush) Brush(com.sk89q.worldedit.command.tool.brush.Brush) ButcherBrush(com.sk89q.worldedit.command.tool.brush.ButcherBrush) ErodeBrush(com.fastasyncworldedit.core.command.tool.brush.ErodeBrush) SurfaceSphereBrush(com.fastasyncworldedit.core.command.tool.brush.SurfaceSphereBrush) SplineBrush(com.fastasyncworldedit.core.command.tool.brush.SplineBrush) HollowCylinderBrush(com.sk89q.worldedit.command.tool.brush.HollowCylinderBrush) SmoothBrush(com.sk89q.worldedit.command.tool.brush.SmoothBrush) LayerBrush(com.fastasyncworldedit.core.command.tool.brush.LayerBrush) CommandBrush(com.fastasyncworldedit.core.command.tool.brush.CommandBrush) ImageBrush(com.fastasyncworldedit.core.command.tool.brush.ImageBrush) ShatterBrush(com.fastasyncworldedit.core.command.tool.brush.ShatterBrush) OperationFactoryBrush(com.sk89q.worldedit.command.tool.brush.OperationFactoryBrush) HollowSphereBrush(com.sk89q.worldedit.command.tool.brush.HollowSphereBrush) SphereBrush(com.sk89q.worldedit.command.tool.brush.SphereBrush) SurfaceSphereBrush(com.fastasyncworldedit.core.command.tool.brush.SurfaceSphereBrush) ScatterCommand(com.fastasyncworldedit.core.command.tool.brush.ScatterCommand) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 3 with BlockStateHolder

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));
}
Also used : BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) LongRangeBuildTool(com.sk89q.worldedit.command.tool.LongRangeBuildTool) Component(com.sk89q.worldedit.util.formatting.text.Component) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 4 with BlockStateHolder

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));
    }
}
Also used : RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) Pattern(com.sk89q.worldedit.function.pattern.Pattern) NoiseRandom(com.fastasyncworldedit.core.math.random.NoiseRandom) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern)

Example 5 with BlockStateHolder

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;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Aggregations

BlockStateHolder (com.sk89q.worldedit.world.block.BlockStateHolder)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 BlobBrush (com.fastasyncworldedit.core.command.tool.brush.BlobBrush)1 CatenaryBrush (com.fastasyncworldedit.core.command.tool.brush.CatenaryBrush)1 CircleBrush (com.fastasyncworldedit.core.command.tool.brush.CircleBrush)1 CommandBrush (com.fastasyncworldedit.core.command.tool.brush.CommandBrush)1 CopyPastaBrush (com.fastasyncworldedit.core.command.tool.brush.CopyPastaBrush)1 ErodeBrush (com.fastasyncworldedit.core.command.tool.brush.ErodeBrush)1 FallingSphere (com.fastasyncworldedit.core.command.tool.brush.FallingSphere)1 FlattenBrush (com.fastasyncworldedit.core.command.tool.brush.FlattenBrush)1 HeightBrush (com.fastasyncworldedit.core.command.tool.brush.HeightBrush)1 ImageBrush (com.fastasyncworldedit.core.command.tool.brush.ImageBrush)1 LayerBrush (com.fastasyncworldedit.core.command.tool.brush.LayerBrush)1 LineBrush (com.fastasyncworldedit.core.command.tool.brush.LineBrush)1 RaiseBrush (com.fastasyncworldedit.core.command.tool.brush.RaiseBrush)1 RecurseBrush (com.fastasyncworldedit.core.command.tool.brush.RecurseBrush)1 ScatterBrush (com.fastasyncworldedit.core.command.tool.brush.ScatterBrush)1 ScatterCommand (com.fastasyncworldedit.core.command.tool.brush.ScatterCommand)1 ScatterOverlayBrush (com.fastasyncworldedit.core.command.tool.brush.ScatterOverlayBrush)1