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