Search in sources :

Example 1 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method pos1.

@Command(name = "/pos1", aliases = "/1", desc = "Set position 1")
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos1(Actor actor, World world, LocalSession session, @Arg(desc = "Coordinates to set position 1 to", def = "") BlockVector3 coordinates) throws WorldEditException {
    Location pos;
    // FAWE start - clamp
    if (coordinates != null) {
        pos = new Location(world, coordinates.toVector3().clampY(world.getMinY(), world.getMaxY()));
    } else if (actor instanceof Locatable) {
        pos = ((Locatable) actor).getBlockLocation().clampY(world.getMinY(), world.getMaxY());
    // FAWE end
    } else {
        actor.print(Caption.of("worldedit.pos.console-require-coords"));
        return;
    }
    if (!session.getRegionSelector(world).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(actor))) {
        actor.print(Caption.of("worldedit.pos.already-set"));
        return;
    }
    session.getRegionSelector(world).explainPrimarySelection(actor, session, pos.toVector().toBlockPoint());
}
Also used : Location(com.sk89q.worldedit.util.Location) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable in project FastAsyncWorldEdit by IntellectualSites.

the class OffsetConverter method convert.

@Override
public ConversionResult<BlockVector3> convert(String input, InjectedValueAccess context) {
    if (input.startsWith("^")) {
        try {
            // Looking at a relative vector.
            Actor actor = context.injectedValue(Key.of(Actor.class)).orElseThrow(() -> new IllegalStateException("An actor is required to use relative offsets"));
            if (!(actor instanceof Locatable)) {
                throw new IllegalStateException("Only a locatable actor may use relative offsets");
            }
            Location location = ((Locatable) actor).getLocation();
            return vectorConverter.convert(input.substring(1), context).map(blockVector3s -> blockVector3s.stream().map(vector -> rotateToRelative(location, vector)).collect(Collectors.toList()));
        } catch (IllegalStateException e) {
            return FailedConversion.from(e);
        }
    } else {
        return directionVectorConverter.convert(input, context).orElse(vectorConverter.convert(input, context));
    }
}
Also used : Actor(com.sk89q.worldedit.extension.platform.Actor) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Location(com.sk89q.worldedit.util.Location)

Example 3 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable in project FastAsyncWorldEdit by IntellectualSites.

the class ParserContext method getMinY.

/**
 * Attempts to resolve the minimum Y value associated with this context or returns 0.
 * Caches both min and max y values.
 *
 * @return Minimum y value (inclusive) or 0
 */
public int getMinY() {
    if (minY != Integer.MIN_VALUE) {
        return minY;
    }
    Extent extent = null;
    if (actor instanceof Locatable) {
        extent = ((Locatable) actor).getExtent();
    } else if (world != null) {
        extent = world;
    } else if (this.extent != null) {
        extent = this.extent;
    }
    if (extent != null) {
        minY = extent.getMinY();
        maxY = extent.getMaxY();
    } else {
        minY = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).versionMinY();
        maxY = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).versionMaxY();
    }
    return minY;
}
Also used : Extent(com.sk89q.worldedit.extent.Extent) Locatable(com.sk89q.worldedit.extension.platform.Locatable)

Example 4 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method chunk.

@Command(name = "/chunk", desc = "Set the selection to your current chunk.", descFooter = "This command selects 256-block-tall areas,\nwhich can be specified by the y-coordinate.\nE.g. -c x,1,z will select from y=256 to y=511.")
@Logging(POSITION)
@CommandPermissions("worldedit.selection.chunk")
public void chunk(Actor actor, World world, LocalSession session, @Arg(desc = "The chunk to select", def = "") BlockVector3 coordinates, @Switch(name = 's', desc = "Expand your selection to encompass all chunks that are part of it") boolean expandSelection, @Switch(name = 'c', desc = "Use chunk coordinates instead of block coordinates") boolean useChunkCoordinates) throws WorldEditException {
    final BlockVector3 min;
    final BlockVector3 max;
    if (expandSelection) {
        Region region = session.getSelection(world);
        int minChunkY = world.getMinY() >> CHUNK_SHIFTS_Y;
        int maxChunkY = world.getMaxY() >> CHUNK_SHIFTS_Y;
        BlockVector3 minChunk = ChunkStore.toChunk3d(region.getMinimumPoint()).clampY(minChunkY, maxChunkY);
        BlockVector3 maxChunk = ChunkStore.toChunk3d(region.getMaximumPoint()).clampY(minChunkY, maxChunkY);
        min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS);
        max = maxChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS).add(15, 255, 15);
        actor.print(Caption.of("worldedit.chunk.selected-multiple", TextComponent.of(minChunk.getBlockX()), TextComponent.of(minChunk.getBlockY()), TextComponent.of(minChunk.getBlockZ()), TextComponent.of(maxChunk.getBlockX()), TextComponent.of(maxChunk.getBlockY()), TextComponent.of(maxChunk.getBlockZ())));
    } else {
        BlockVector3 minChunk;
        if (coordinates != null) {
            // coords specified
            minChunk = useChunkCoordinates ? coordinates : ChunkStore.toChunk3d(coordinates);
        } else {
            // use player loc
            if (actor instanceof Locatable) {
                minChunk = ChunkStore.toChunk3d(((Locatable) actor).getBlockLocation().toVector().toBlockPoint());
            } else {
                throw new StopExecutionException(TextComponent.of("A player or coordinates are required."));
            }
        }
        min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS);
        max = min.add(15, 255, 15);
        actor.print(Caption.of("worldedit.chunk.selected", TextComponent.of(minChunk.getBlockX()), TextComponent.of(minChunk.getBlockY()), TextComponent.of(minChunk.getBlockZ())));
    }
    final CuboidRegionSelector selector;
    if (session.getRegionSelector(world) instanceof ExtendingCuboidRegionSelector) {
        selector = new ExtendingCuboidRegionSelector(world);
    } else {
        selector = new CuboidRegionSelector(world);
    }
    selector.selectPrimary(min, ActorSelectorLimits.forActor(actor));
    selector.selectSecondary(max, ActorSelectorLimits.forActor(actor));
    session.setRegionSelector(world, selector);
    session.dispatchCUISelection(actor);
}
Also used : StopExecutionException(org.enginehub.piston.exception.StopExecutionException) Region(com.sk89q.worldedit.regions.Region) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ExtendingCuboidRegionSelector(com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 5 with Locatable

use of com.sk89q.worldedit.extension.platform.Locatable 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)

Aggregations

Locatable (com.sk89q.worldedit.extension.platform.Locatable)10 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)5 Logging (com.sk89q.worldedit.command.util.Logging)5 Command (org.enginehub.piston.annotation.Command)5 Location (com.sk89q.worldedit.util.Location)4 LocalSession (com.sk89q.worldedit.LocalSession)3 Actor (com.sk89q.worldedit.extension.platform.Actor)3 Extent (com.sk89q.worldedit.extent.Extent)3 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 Region (com.sk89q.worldedit.regions.Region)3 Confirm (com.sk89q.worldedit.command.util.annotation.Confirm)2 Preload (com.sk89q.worldedit.command.util.annotation.Preload)2 Player (com.sk89q.worldedit.entity.Player)2 RegionFunction (com.sk89q.worldedit.function.RegionFunction)2 RegionMaskingFilter (com.sk89q.worldedit.function.RegionMaskingFilter)2 BiomeReplace (com.sk89q.worldedit.function.biome.BiomeReplace)2 Mask (com.sk89q.worldedit.function.mask.Mask)2 RegionVisitor (com.sk89q.worldedit.function.visitor.RegionVisitor)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 World (com.sk89q.worldedit.world.World)2