Search in sources :

Example 6 with Location

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

the class LongRangeBuildTool method actSecondary.

@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
    Location pos = getTargetFace(player);
    if (pos == null) {
        return false;
    }
    BlockBag bag = session.getBlockBag(player);
    try (EditSession editSession = session.createEditSession(player, "LongRangeBuildTool")) {
        try {
            BlockVector3 blockPoint = pos.toVector().toBlockPoint();
            BaseBlock applied = secondary.applyBlock(blockPoint);
            if (applied.getBlockType().getMaterial().isAir()) {
                editSession.setBlock(blockPoint, secondary);
            } else {
                editSession.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), secondary);
            }
        } catch (MaxChangedBlocksException ignored) {
        } finally {
            session.remember(editSession);
        }
    } finally {
        if (bag != null) {
            bag.flushChanges();
        }
    }
    return true;
}
Also used : BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) EditSession(com.sk89q.worldedit.EditSession) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Location(com.sk89q.worldedit.util.Location) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 7 with Location

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

the class LongRangeBuildTool method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
    Location pos = getTargetFace(player);
    if (pos == null) {
        return false;
    }
    BlockBag bag = session.getBlockBag(player);
    try (EditSession editSession = session.createEditSession(player, "LongRangeBuildTool")) {
        try {
            BlockVector3 blockPoint = pos.toVector().toBlockPoint();
            BaseBlock applied = primary.applyBlock(blockPoint);
            if (applied.getBlockType().getMaterial().isAir()) {
                editSession.setBlock(blockPoint, primary);
            } else {
                editSession.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), primary);
            }
        } catch (MaxChangedBlocksException ignored) {
        } finally {
            session.remember(editSession);
        }
    } finally {
        if (bag != null) {
            bag.flushChanges();
        }
    }
    return true;
}
Also used : BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) EditSession(com.sk89q.worldedit.EditSession) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Location(com.sk89q.worldedit.util.Location) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 8 with Location

use of com.sk89q.worldedit.util.Location 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 9 with Location

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

the class DistanceWand method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
    Location target = getTarget(player);
    if (target == null) {
        return true;
    }
    RegionSelector selector = session.getRegionSelector(player.getWorld());
    BlockVector3 blockPoint = target.toVector().toBlockPoint();
    if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) {
        selector.explainSecondarySelection(player, session, blockPoint);
    }
    return true;
}
Also used : RegionSelector(com.sk89q.worldedit.regions.RegionSelector) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Location(com.sk89q.worldedit.util.Location)

Example 10 with Location

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

the class DistanceWand method getTarget.

private Location getTarget(Player player) {
    Location target;
    Mask mask = getTraceMask();
    if (this.range > -1) {
        target = player.getBlockTrace(getRange(), true, mask);
    } else {
        target = player.getBlockTrace(MAX_RANGE, false, mask);
    }
    if (target == null) {
        player.print(Caption.of("worldedit.tool.no-block"));
        return null;
    }
    return target;
}
Also used : Mask(com.sk89q.worldedit.function.mask.Mask) Location(com.sk89q.worldedit.util.Location)

Aggregations

Location (com.sk89q.worldedit.util.Location)65 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)26 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)12 CompoundTag (com.sk89q.jnbt.CompoundTag)11 World (com.sk89q.worldedit.world.World)11 Region (com.sk89q.worldedit.regions.Region)10 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)9 Command (org.enginehub.piston.annotation.Command)9 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)8 Tag (com.sk89q.jnbt.Tag)8 List (java.util.List)8 ListTag (com.sk89q.jnbt.ListTag)7 Vector3 (com.sk89q.worldedit.math.Vector3)7 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)7 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)7 StringTag (com.sk89q.jnbt.StringTag)6 Player (com.sk89q.worldedit.entity.Player)6 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)6 BlockState (com.sk89q.worldedit.world.block.BlockState)6 IntTag (com.sk89q.jnbt.IntTag)5