Search in sources :

Example 11 with Location

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

the class BlockArrayClipboard method getEntities.

@Override
public List<? extends Entity> getEntities(Region region) {
    region = region.clone();
    region.shift(BlockVector3.ZERO.subtract(offset));
    return getParent().getEntities(region).stream().map(e -> {
        if (e instanceof ClipboardEntity) {
            ClipboardEntity ce = (ClipboardEntity) e;
            Location oldloc = ce.getLocation();
            Location loc = new Location(oldloc.getExtent(), oldloc.getX() + offset.getBlockX(), oldloc.getY() + offset.getBlockY(), oldloc.getZ() + offset.getBlockZ(), oldloc.getYaw(), oldloc.getPitch());
            return new ClipboardEntity(loc, ce.entity);
        }
        return e;
    }).collect(Collectors.toList());
}
Also used : OffsetBlockVector3(com.fastasyncworldedit.core.math.OffsetBlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2) BlockTypes(com.sk89q.worldedit.world.block.BlockTypes) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Iterators(com.google.common.collect.Iterators) WorldEditException(com.sk89q.worldedit.WorldEditException) Location(com.sk89q.worldedit.util.Location) MutableBlockVector2(com.fastasyncworldedit.core.math.MutableBlockVector2) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) Nonnull(javax.annotation.Nonnull) Region(com.sk89q.worldedit.regions.Region) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) Nullable(javax.annotation.Nullable) Iterator(java.util.Iterator) SimpleClipboard(com.fastasyncworldedit.core.extent.clipboard.SimpleClipboard) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Entity(com.sk89q.worldedit.entity.Entity) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) CompoundTag(com.sk89q.jnbt.CompoundTag) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Order(com.fastasyncworldedit.core.function.visitor.Order) BlockState(com.sk89q.worldedit.world.block.BlockState) Extent(com.sk89q.worldedit.extent.Extent) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) Location(com.sk89q.worldedit.util.Location)

Example 12 with Location

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

the class PlatformManager method handleBlockInteract.

@Subscribe
public void handleBlockInteract(BlockInteractEvent event) {
    // Create a proxy actor with a potentially different world for
    // making changes to the world
    Actor actor = createProxyActor(event.getCause());
    Location location = event.getLocation();
    // At this time, only handle interaction from players
    if (!(actor instanceof Player)) {
        return;
    }
    Player player = (Player) actor;
    LocalSession session = worldEdit.getSessionManager().get(actor);
    Request.reset();
    Request.request().setSession(session);
    Request.request().setWorld(player.getWorld());
    try {
        if (event.getType() == Interaction.HIT) {
            // in addition, it is implicitly bound to all pickaxe items, not just a single tool item
            if (session.hasSuperPickAxe() && player.isHoldingPickAxe()) {
                final BlockTool superPickaxe = session.getSuperPickaxe();
                if (superPickaxe != null && superPickaxe.canUse(player)) {
                    // FAWE start - run async
                    player.runAction(() -> reset(superPickaxe).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace()), false, true);
                    // FAWE end
                    event.setCancelled(true);
                    return;
                }
            }
            Tool tool = session.getTool(player);
            if (tool instanceof DoubleActionBlockTool && tool.canUse(player)) {
                // FAWE start - run async
                player.runAction(() -> reset((DoubleActionBlockTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace()), false, true);
                // FAWE end
                event.setCancelled(true);
            }
        } else if (event.getType() == Interaction.OPEN) {
            // FAWE start - get general tool over item in main hand & run async
            Tool tool = session.getTool(player);
            if (tool instanceof BlockTool && tool.canUse(player)) {
                if (player.checkAction()) {
                    // FAWE run async
                    player.runAction(() -> {
                        BlockTool blockTool = (BlockTool) tool;
                        if (!(tool instanceof BrushTool)) {
                            blockTool = reset(blockTool);
                        }
                        blockTool.actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace());
                    }, false, true);
                    // FAWE end
                    event.setCancelled(true);
                }
            }
        }
    } catch (Throwable e) {
        handleThrowable(e, actor);
    } finally {
        Request.reset();
    }
}
Also used : BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Player(com.sk89q.worldedit.entity.Player) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) BlockTool(com.sk89q.worldedit.command.tool.BlockTool) LocalSession(com.sk89q.worldedit.LocalSession) Location(com.sk89q.worldedit.util.Location) DoubleActionBlockTool(com.sk89q.worldedit.command.tool.DoubleActionBlockTool) TraceTool(com.sk89q.worldedit.command.tool.TraceTool) BlockTool(com.sk89q.worldedit.command.tool.BlockTool) DoubleActionTraceTool(com.sk89q.worldedit.command.tool.DoubleActionTraceTool) BrushTool(com.sk89q.worldedit.command.tool.BrushTool) Tool(com.sk89q.worldedit.command.tool.Tool) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 13 with Location

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

the class FabricWorldEdit method onLeftClickBlock.

private ActionResult onLeftClickBlock(PlayerEntity playerEntity, World world, Hand hand, BlockPos blockPos, Direction direction) {
    if (shouldSkip() || hand == Hand.OFF_HAND || world.isClient) {
        return ActionResult.PASS;
    }
    WorldEdit we = WorldEdit.getInstance();
    FabricPlayer player = adaptPlayer((ServerPlayerEntity) playerEntity);
    FabricWorld localWorld = getWorld(world);
    Location pos = new Location(localWorld, blockPos.getX(), blockPos.getY(), blockPos.getZ());
    com.sk89q.worldedit.util.Direction weDirection = FabricAdapter.adaptEnumFacing(direction);
    if (we.handleBlockLeftClick(player, pos, weDirection)) {
        return ActionResult.SUCCESS;
    }
    if (we.handleArmSwing(player)) {
        return ActionResult.SUCCESS;
    }
    return ActionResult.PASS;
}
Also used : WorldEdit(com.sk89q.worldedit.WorldEdit) Location(com.sk89q.worldedit.util.Location)

Example 14 with Location

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

the class FabricEntity method getLocation.

@Override
public Location getLocation() {
    net.minecraft.entity.Entity entity = entityRef.get();
    if (entity != null) {
        Vector3 position = Vector3.at(entity.x, entity.y, entity.z);
        float yaw = entity.yaw;
        float pitch = entity.pitch;
        return new Location(FabricAdapter.adapt(entity.world), position, yaw, pitch);
    } else {
        return new Location(NullWorld.getInstance());
    }
}
Also used : Vector3(com.sk89q.worldedit.math.Vector3) Location(com.sk89q.worldedit.util.Location)

Example 15 with Location

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

the class CopyPastaBrush method build.

@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
    Actor actor = editSession.getActor();
    if (!(actor instanceof Player)) {
        throw FaweCache.PLAYER_ONLY;
    }
    Player player = (Player) actor;
    ClipboardHolder clipboard = session.getExistingClipboard();
    if (clipboard == null) {
        Mask mask = editSession.getMask();
        if (mask == null) {
            mask = Masks.alwaysTrue();
        }
        final ResizableClipboardBuilder builder = new ResizableClipboardBuilder(editSession.getWorld());
        final int minY = position.getBlockY();
        mask = new AbstractDelegateMask(mask) {

            @Override
            public boolean test(BlockVector3 vector) {
                if (super.test(vector) && vector.getBlockY() >= minY) {
                    BaseBlock block = editSession.getFullBlock(vector);
                    if (!block.getBlockType().getMaterial().isAir()) {
                        builder.add(vector, BlockTypes.AIR.getDefaultState().toBaseBlock(), block);
                        return true;
                    }
                }
                return false;
            }
        };
        // Add origin
        mask.test(position);
        RecursiveVisitor visitor = new RecursiveVisitor(mask, new NullRegionFunction(), (int) size, editSession.getMinY(), editSession.getMaxY());
        visitor.visit(position);
        Operations.completeBlindly(visitor);
        // Build the clipboard
        Clipboard newClipboard = builder.build();
        newClipboard.setOrigin(position);
        ClipboardHolder holder = new ClipboardHolder(newClipboard);
        session.setClipboard(holder);
        int blocks = builder.size();
        player.print(Caption.of("fawe.worldedit.copy.command.copy", blocks));
    } else {
        AffineTransform transform = null;
        if (randomRotate) {
            transform = new AffineTransform();
            int rotate = 90 * ThreadLocalRandom.current().nextInt(4);
            transform = transform.rotateY(rotate);
        }
        if (autoRotate) {
            if (transform == null) {
                transform = new AffineTransform();
            }
            Location loc = player.getLocation();
            float yaw = loc.getYaw();
            float pitch = loc.getPitch();
            transform = transform.rotateY(-yaw % 360);
            transform = transform.rotateX(pitch - 90);
        }
        if (transform != null && !transform.isIdentity()) {
            clipboard.setTransform(transform);
        }
        Operation operation = clipboard.createPaste(editSession).to(position.add(0, 1, 0)).ignoreAirBlocks(true).build();
        Operations.completeLegacy(operation);
        editSession.flushQueue();
    }
}
Also used : Player(com.sk89q.worldedit.entity.Player) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) AbstractDelegateMask(com.fastasyncworldedit.core.function.mask.AbstractDelegateMask) Mask(com.sk89q.worldedit.function.mask.Mask) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) Operation(com.sk89q.worldedit.function.operation.Operation) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) NullRegionFunction(com.fastasyncworldedit.core.function.NullRegionFunction) Actor(com.sk89q.worldedit.extension.platform.Actor) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) ResizableClipboardBuilder(com.fastasyncworldedit.core.extent.clipboard.ResizableClipboardBuilder) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) AbstractDelegateMask(com.fastasyncworldedit.core.function.mask.AbstractDelegateMask) 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