Search in sources :

Example 41 with Logging

use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.

the class BiomeCommands method setBiome.

@Command(name = "/setbiome", desc = "Sets the biome of your current block or region.", descFooter = "By default, uses all the blocks in your selection")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
@CommandPermissions("worldedit.biome.set")
public void setBiome(Actor actor, World world, LocalSession session, EditSession editSession, @Arg(desc = "Biome type.") BiomeType target, @Switch(name = 'p', desc = "Use your current position") boolean atPosition) throws WorldEditException {
    Region region;
    Mask mask = editSession.getMask();
    if (atPosition) {
        if (actor instanceof Locatable) {
            final BlockVector3 pos = ((Locatable) actor).getLocation().toVector().toBlockPoint();
            region = new CuboidRegion(pos, pos);
        } else {
            actor.print(Caption.of("worldedit.setbiome.not-locatable"));
            return;
        }
    } else {
        region = session.getSelection(world);
    }
    RegionFunction replace = new BiomeReplace(editSession, target);
    if (mask != null) {
        replace = new RegionMaskingFilter(editSession, mask, replace);
    }
    RegionVisitor visitor = new RegionVisitor(region, replace);
    Operations.completeLegacy(visitor);
    actor.print(Caption.of("worldedit.setbiome.changed", TextComponent.of(visitor.getAffected() / (editSession.getMaxY() - editSession.getMinY()))));
}
Also used : RegionFunction(com.sk89q.worldedit.function.RegionFunction) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) BiomeReplace(com.sk89q.worldedit.function.biome.BiomeReplace) Mask(com.sk89q.worldedit.function.mask.Mask) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) RegionMaskingFilter(com.sk89q.worldedit.function.RegionMaskingFilter) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 42 with Logging

use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.

the class RegionCommands method smooth.

@Command(name = "/smooth", desc = "Smooth the elevation in the selection", descFooter = "Example: '//smooth 1 grass_block,dirt,stone' would only smooth natural surface terrain.")
@CommandPermissions("worldedit.region.smooth")
@Logging(REGION)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public int smooth(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "# of iterations to perform", def = "1") int iterations, @Arg(desc = "The mask of blocks to use as the height map", def = "") Mask mask) throws WorldEditException {
    // FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
    new MaskTraverser(mask).setNewExtent(editSession);
    // FAWE end
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
    FaweLimit limit = actor.getLimit();
    if (volume >= limit.MAX_CHECKS) {
        throw FaweCache.MAX_CHECKS;
    }
    int affected;
    try {
        HeightMap heightMap = new HeightMap(editSession, region, mask);
        HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
        affected = heightMap.applyFilter(filter, iterations);
        actor.print(Caption.of("worldedit.smooth.changed", TextComponent.of(affected)));
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    return affected;
}
Also used : HeightMapFilter(com.sk89q.worldedit.math.convolution.HeightMapFilter) HeightMap(com.sk89q.worldedit.math.convolution.HeightMap) SnowHeightMap(com.sk89q.worldedit.math.convolution.SnowHeightMap) FaweLimit(com.fastasyncworldedit.core.limit.FaweLimit) MaskTraverser(com.fastasyncworldedit.core.util.MaskTraverser) BlockVector3(com.sk89q.worldedit.math.BlockVector3) GaussianKernel(com.sk89q.worldedit.math.convolution.GaussianKernel) Logging(com.sk89q.worldedit.command.util.Logging) Preload(com.sk89q.worldedit.command.util.annotation.Preload) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 43 with Logging

use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.

the class ExpandCommands method expand.

@org.enginehub.piston.annotation.Command(name = "/expand", desc = "Expand the selection area")
@Logging(REGION)
public void expand(Actor actor, World world, LocalSession session, @Arg(desc = "Amount to expand the selection by, can be `vert` to expand to the whole vertical column") int amount, @Arg(desc = "Amount to expand the selection by in the other direction", def = "0") int reverseAmount, @Arg(desc = "Direction to expand", def = Direction.AIM) @MultiDirection List<BlockVector3> direction) throws WorldEditException {
    Region region = session.getSelection(world);
    long oldSize = region.getVolume();
    if (reverseAmount == 0) {
        for (BlockVector3 dir : direction) {
            region.expand(dir.multiply(amount));
        }
    } else {
        for (BlockVector3 dir : direction) {
            region.expand(dir.multiply(amount), dir.multiply(-reverseAmount));
        }
    }
    session.getRegionSelector(world).learnChanges();
    long newSize = region.getVolume();
    session.getRegionSelector(world).explainRegionAdjust(actor, session);
    long changeSize = newSize - oldSize;
    actor.print(Caption.of("worldedit.expand.expanded", TextComponent.of(changeSize)));
}
Also used : Region(com.sk89q.worldedit.regions.Region) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging)

Example 44 with Logging

use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.

the class GenerationCommands method generate.

@Command(name = "/generate", aliases = { "/gen", "/g" }, desc = "Generates a shape according to a formula.", descFooter = "For details, see https://ehub.to/we/expr")
@CommandPermissions("worldedit.generation.shape")
@Logging(ALL)
@Confirm(Confirm.Processor.REGION)
public int generate(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "The pattern of blocks to set") Pattern pattern, @Arg(desc = "Expression to test block placement locations and set block type", variable = true) List<String> expression, @Switch(name = 'h', desc = "Generate a hollow shape") boolean hollow, @Switch(name = 'r', desc = "Use the game's coordinate origin") boolean useRawCoords, @Switch(name = 'o', desc = "Use the placement's coordinate origin") boolean offset, @Switch(name = 'c', desc = "Use the selection's center as origin") boolean offsetCenter) throws WorldEditException {
    final Vector3 zero;
    Vector3 unit;
    if (useRawCoords) {
        zero = Vector3.ZERO;
        unit = Vector3.ONE;
    } else if (offset) {
        zero = session.getPlacementPosition(actor).toVector3();
        unit = Vector3.ONE;
    } else if (offsetCenter) {
        final Vector3 min = region.getMinimumPoint().toVector3();
        final Vector3 max = region.getMaximumPoint().toVector3();
        zero = max.add(min).multiply(0.5);
        unit = Vector3.ONE;
    } else {
        final Vector3 min = region.getMinimumPoint().toVector3();
        final Vector3 max = region.getMaximumPoint().toVector3();
        zero = max.add(min).multiply(0.5);
        unit = max.subtract(zero);
        if (unit.getX() == 0) {
            unit = unit.withX(1.0);
        }
        if (unit.getY() == 0) {
            unit = unit.withY(1.0);
        }
        if (unit.getZ() == 0) {
            unit = unit.withZ(1.0);
        }
    }
    final Vector3 unit1 = unit;
    try {
        final int affected = editSession.makeShape(region, zero, unit1, pattern, String.join(" ", expression), hollow, session.getTimeout());
        if (actor instanceof Player) {
            ((Player) actor).findFreePosition();
        }
        actor.print(Caption.of("worldedit.generate.created", TextComponent.of(affected)));
        return affected;
    } catch (ExpressionException e) {
        actor.printError(TextComponent.of(e.getMessage()));
        return 0;
    }
}
Also used : Player(com.sk89q.worldedit.entity.Player) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) ExpressionException(com.sk89q.worldedit.internal.expression.ExpressionException) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) Confirm(com.sk89q.worldedit.command.util.annotation.Confirm) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 45 with Logging

use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.

the class GenerationCommands method cyl.

// FAWE end
@Command(name = "/cyl", desc = "Generates a cylinder.")
@CommandPermissions("worldedit.generation.cylinder")
@Logging(PLACEMENT)
public int cyl(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The pattern of blocks to generate") Pattern pattern, @Arg(desc = "The radii of the cylinder. 1st is N/S, 2nd is E/W") @Radii(2) List<Double> radii, @Arg(desc = "The height of the cylinder", def = "1") int height, @Switch(name = 'h', desc = "Make a hollow cylinder") boolean hollow) throws WorldEditException {
    final double radiusX;
    final double radiusZ;
    switch(radii.size()) {
        case 1:
            radiusX = radiusZ = Math.max(1, radii.get(0));
            break;
        case 2:
            radiusX = Math.max(1, radii.get(0));
            radiusZ = Math.max(1, radii.get(1));
            break;
        default:
            actor.print(Caption.of("worldedit.cyl.invalid-radius"));
            return 0;
    }
    worldEdit.checkMaxRadius(radiusX);
    worldEdit.checkMaxRadius(radiusZ);
    worldEdit.checkMaxRadius(height);
    BlockVector3 pos = session.getPlacementPosition(actor);
    int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, !hollow);
    actor.print(Caption.of("worldedit.cyl.created", TextComponent.of(affected)));
    return affected;
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

Logging (com.sk89q.worldedit.command.util.Logging)47 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)45 Command (org.enginehub.piston.annotation.Command)45 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)25 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)17 Preload (com.sk89q.worldedit.command.util.annotation.Preload)15 Region (com.sk89q.worldedit.regions.Region)13 MaskTraverser (com.fastasyncworldedit.core.util.MaskTraverser)10 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)8 Mask (com.sk89q.worldedit.function.mask.Mask)7 Player (com.sk89q.worldedit.entity.Player)6 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)5 Locatable (com.sk89q.worldedit.extension.platform.Locatable)4 SolidBlockMask (com.sk89q.worldedit.function.mask.SolidBlockMask)4 Vector3 (com.sk89q.worldedit.math.Vector3)4 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)3 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)3 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)3 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)3 RegionOperationException (com.sk89q.worldedit.regions.RegionOperationException)3