Search in sources :

Example 6 with CuboidRegionSelector

use of com.sk89q.worldedit.regions.selector.CuboidRegionSelector in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardCommands method place.

@Command(name = "/place", desc = "Place the clipboard's contents without applying transformations (e.g. rotate)")
@CommandPermissions("worldedit.clipboard.place")
@Logging(PLACEMENT)
public void place(Actor actor, World world, LocalSession session, final EditSession editSession, @Switch(name = 'a', desc = "Skip air blocks") boolean ignoreAirBlocks, @Switch(name = 'o', desc = "Paste at the original position") boolean atOrigin, @Switch(name = 's', desc = "Select the region after pasting") boolean selectPasted, @Switch(name = 'e', desc = "Paste entities if available") boolean pasteEntities, @Switch(name = 'b', desc = "Paste biomes if available") boolean pasteBiomes) throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    final Clipboard clipboard = holder.getClipboard();
    final BlockVector3 origin = clipboard.getOrigin();
    final BlockVector3 to = atOrigin ? origin : session.getPlacementPosition(actor);
    checkPaste(actor, editSession, to, holder, clipboard);
    clipboard.paste(editSession, to, !ignoreAirBlocks, pasteEntities, pasteBiomes);
    Region region = clipboard.getRegion().clone();
    if (selectPasted) {
        BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
        BlockVector3 realTo = to.add(holder.getTransform().apply(clipboardOffset.toVector3()).toBlockPoint());
        BlockVector3 max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()).toBlockPoint());
        RegionSelector selector = new CuboidRegionSelector(world, realTo, max);
        session.setRegionSelector(world, selector);
        selector.learnChanges();
        selector.explainRegionAdjust(actor, session);
    }
    actor.print(Caption.of("fawe.worldedit.paste.command.paste", to));
    if (!actor.hasPermission("fawe.tips")) {
        actor.print(Caption.of("fawe.tips.tip.copypaste"));
    }
}
Also used : RegionSelector(com.sk89q.worldedit.regions.RegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) ReadOnlyClipboard(com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) 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)

Example 7 with CuboidRegionSelector

use of com.sk89q.worldedit.regions.selector.CuboidRegionSelector in project FastAsyncWorldEdit by IntellectualSites.

the class ServerCUIHandler method createStructureBlock.

/**
 * Creates a structure block that shows the region.
 *
 * <p>
 * Null symbolises removal of the CUI.
 * </p>
 *
 * @param player The player to create the structure block for.
 * @return The structure block, or null
 */
@Nullable
public static BaseBlock createStructureBlock(Player player) {
    LocalSession session = WorldEdit.getInstance().getSessionManager().get(player);
    RegionSelector regionSelector = session.getRegionSelector(player.getWorld());
    int posX;
    int posY;
    int posZ;
    int width;
    int height;
    int length;
    if (regionSelector instanceof CuboidRegionSelector) {
        if (regionSelector.isDefined()) {
            try {
                CuboidRegion region = ((CuboidRegionSelector) regionSelector).getRegion();
                posX = region.getMinimumPoint().getBlockX();
                posY = region.getMinimumPoint().getBlockY();
                posZ = region.getMinimumPoint().getBlockZ();
                width = region.getWidth();
                height = region.getHeight();
                length = region.getLength();
            } catch (IncompleteRegionException e) {
                // This will never happen.
                e.printStackTrace();
                return null;
            }
        } else {
            CuboidRegion region = ((CuboidRegionSelector) regionSelector).getIncompleteRegion();
            BlockVector3 point;
            if (region.getPos1() != null) {
                point = region.getPos1();
            } else if (region.getPos2() != null) {
                point = region.getPos2();
            } else {
                // No more selection
                return null;
            }
            // Just select the point.
            posX = point.getBlockX();
            posY = point.getBlockY();
            posZ = point.getBlockZ();
            width = 1;
            height = 1;
            length = 1;
        }
    } else {
        // We only support cuboid regions right now.
        return null;
    }
    int maxSize = getMaxServerCuiSize();
    if (width > maxSize || length > maxSize || height > maxSize) {
        // Structure blocks have a limit of maxSize^3
        return null;
    }
    // Borrowed this math from FAWE
    final Location location = player.getLocation();
    double rotX = location.getYaw();
    double rotY = location.getPitch();
    double xz = Math.cos(Math.toRadians(rotY));
    int x = (int) (location.getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 12);
    int z = (int) (location.getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 12);
    int y = Math.max(player.getWorld().getMinY(), Math.min(Math.min(player.getWorld().getMaxY(), posY + MAX_DISTANCE), posY + 3));
    // FAWE start - CBT > Map<String, Tag>
    CompoundBinaryTag.Builder structureTag = CompoundBinaryTag.builder();
    posX -= x;
    posY -= y;
    posZ -= z;
    if (Math.abs(posX) > MAX_DISTANCE || Math.abs(posY) > MAX_DISTANCE || Math.abs(posZ) > MAX_DISTANCE) {
        // Structure blocks have a limit
        return null;
    }
    // FAWE start - see comment of CBT
    structureTag.putString("name", "worldedit:" + player.getName());
    structureTag.putString("author", player.getName());
    structureTag.putString("metadata", "");
    structureTag.putInt("x", x);
    structureTag.putInt("y", y);
    structureTag.putInt("z", z);
    structureTag.putInt("posX", posX);
    structureTag.putInt("posY", posY);
    structureTag.putInt("posZ", posZ);
    structureTag.putInt("sizeX", width);
    structureTag.putInt("sizeY", height);
    structureTag.putInt("sizeZ", length);
    structureTag.putString("rotation", "NONE");
    structureTag.putString("mirror", "NONE");
    structureTag.putString("mode", "SAVE");
    structureTag.putByte("ignoreEntities", (byte) 1);
    structureTag.putByte("showboundingbox", (byte) 1);
    structureTag.putString("id", BlockTypes.STRUCTURE_BLOCK.getId());
    return BlockTypes.STRUCTURE_BLOCK.getDefaultState().toBaseBlock(structureTag.build());
// FAWE end
}
Also used : CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) RegionSelector(com.sk89q.worldedit.regions.RegionSelector) LocalSession(com.sk89q.worldedit.LocalSession) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) Location(com.sk89q.worldedit.util.Location) Nullable(javax.annotation.Nullable)

Aggregations

CuboidRegionSelector (com.sk89q.worldedit.regions.selector.CuboidRegionSelector)7 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)5 RegionSelector (com.sk89q.worldedit.regions.RegionSelector)5 Command (org.enginehub.piston.annotation.Command)5 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)4 Logging (com.sk89q.worldedit.command.util.Logging)4 Region (com.sk89q.worldedit.regions.Region)4 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)3 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)3 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)3 DiskOptimizedClipboard (com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard)2 MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)2 ReadOnlyClipboard (com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard)2 LocalSession (com.sk89q.worldedit.LocalSession)2 Locatable (com.sk89q.worldedit.extension.platform.Locatable)2 ConvexPolyhedralRegionSelector (com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector)2 CylinderRegionSelector (com.sk89q.worldedit.regions.selector.CylinderRegionSelector)2 ExtendingCuboidRegionSelector (com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector)2 Polygonal2DRegionSelector (com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector)2 Component (com.sk89q.worldedit.util.formatting.text.Component)2