Search in sources :

Example 16 with Location

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

the class ErodeBrush method erosion.

public void erosion(final EditSession es, int erodeFaces, int erodeRecursion, int fillFaces, int fillRecursion, BlockVector3 target, double size) {
    int brushSize = (int) size;
    int brushSizeSquared = (int) (size * size);
    Location min = new Location(es.getWorld(), target.toVector3().subtract(size, size, size));
    Location max = new Location(es.getWorld(), target.toVector3().add(size, size, size));
    Region region = new CuboidRegion(es.getWorld(), min.toBlockPoint(), max.toBlockPoint());
    Clipboard buffer1 = new CPUOptimizedClipboard(region);
    Clipboard buffer2 = new CPUOptimizedClipboard(region);
    final int bx = target.getBlockX();
    final int by = target.getBlockY();
    final int bz = target.getBlockZ();
    for (int x = -brushSize, relx = 0; x <= brushSize; x++, relx++) {
        int x0 = x + bx;
        for (int y = -brushSize, rely = 0; y <= brushSize; y++, rely++) {
            int y0 = y + by;
            for (int z = -brushSize, relz = 0; z <= brushSize; z++, relz++) {
                int z0 = z + bz;
                BlockState state = es.getBlock(x0, y0, z0);
                buffer1.setBlock(relx, rely, relz, state);
                buffer2.setBlock(relx, rely, relz, state);
            }
        }
    }
    int swap = 0;
    for (int i = 0; i < erodeRecursion; ++i) {
        erosionIteration(brushSize, brushSizeSquared, erodeFaces, swap % 2 == 0 ? buffer1 : buffer2, swap % 2 == 1 ? buffer1 : buffer2);
        swap++;
    }
    for (int i = 0; i < fillRecursion; ++i) {
        fillIteration(brushSize, brushSizeSquared, fillFaces, swap % 2 == 0 ? buffer1 : buffer2, swap % 2 == 1 ? buffer1 : buffer2);
        swap++;
    }
    Clipboard finalBuffer = swap % 2 == 0 ? buffer1 : buffer2;
    for (BlockVector3 pos : finalBuffer) {
        BlockState block = pos.getBlock(finalBuffer);
        es.setBlock(pos.getX() + bx - brushSize, pos.getY() + by - brushSize, pos.getZ() + bz - brushSize, block);
    }
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) CPUOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.CPUOptimizedClipboard) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Location(com.sk89q.worldedit.util.Location) CPUOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.CPUOptimizedClipboard)

Example 17 with Location

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

the class AbstractPlayerActor method getCardinalDirection.

// FAWE end
@Override
public Direction getCardinalDirection(int yawOffset) {
    final Location location = getLocation();
    if (location.getPitch() > 67.5) {
        return Direction.DOWN;
    }
    if (location.getPitch() < -67.5) {
        return Direction.UP;
    }
    // From hey0's code
    // let's use real yaw now
    double rot = (location.getYaw() + yawOffset) % 360;
    if (rot < 0) {
        rot += 360.0;
    }
    return getDirection(rot);
}
Also used : Location(com.sk89q.worldedit.util.Location)

Example 18 with Location

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

the class AbstractPlayerActor method ascendUpwards.

@Override
public boolean ascendUpwards(int distance, boolean alwaysGlass) {
    final World world = getWorld();
    final Location pos = getBlockLocation();
    final int x = pos.getBlockX();
    final int initialY = Math.max(world.getMinY(), pos.getBlockY());
    int y = Math.max(world.getMinY(), pos.getBlockY() + 1);
    final int z = pos.getBlockZ();
    final int maxY = Math.min(world.getMaxY() + 1, initialY + distance);
    // FAWE start - mutable
    MutableBlockVector3 mutable = new MutableBlockVector3(x, y, z);
    while (y <= world.getMaxY() + 2) {
        // FAWE start - mutable
        if (world.getBlock(mutable.mutY(y)).getBlockType().getMaterial().isMovementBlocker()) {
            // Hit something
            break;
        } else if (y > maxY + 1) {
            break;
        } else if (y == maxY + 1) {
            floatAt(x, y - 1, z, alwaysGlass);
            return true;
        }
        ++y;
    }
    return false;
}
Also used : MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) World(com.sk89q.worldedit.world.World) Location(com.sk89q.worldedit.util.Location)

Example 19 with Location

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

the class AbstractPlayerActor method descendLevel.

@Override
public boolean descendLevel() {
    final World world = getWorld();
    final Location pos = getBlockLocation();
    final int x = pos.getBlockX();
    int y = Math.max(world.getMinY(), pos.getBlockY() - 1);
    final int z = pos.getBlockZ();
    int yLessSearchHeight = y - WorldEdit.getInstance().getConfiguration().defaultVerticalHeight;
    int minY = Math.min(world.getMinY() + 1, yLessSearchHeight);
    // FAWE start - mutable
    MutableBlockVector3 mutable = new MutableBlockVector3(x, y, z);
    while (y >= minY) {
        // FAWE start - mutable
        if (isLocationGoodForStanding(mutable.mutY(y)) && // FAWE end
        trySetPosition(Vector3.at(x + 0.5, y, z + 0.5))) {
            return true;
        }
        --y;
    }
    return false;
}
Also used : MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) World(com.sk89q.worldedit.world.World) Location(com.sk89q.worldedit.util.Location)

Example 20 with Location

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

the class AbstractPlayerActor method ascendToCeiling.

@Override
public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
    World world = getWorld();
    Location pos = getBlockLocation();
    int x = pos.getBlockX();
    int initialY = Math.max(world.getMinY(), pos.getBlockY());
    int y = Math.max(world.getMinY(), pos.getBlockY() + 2);
    int z = pos.getBlockZ();
    // FAWE start - mutable
    MutableBlockVector3 mutable = new MutableBlockVector3(x, y, z);
    // No free space above
    if (!world.getBlock(mutable).getBlockType().getMaterial().isAir()) {
        // FAWE end
        return false;
    }
    int yPlusSearchHeight = y + WorldEdit.getInstance().getConfiguration().defaultVerticalHeight;
    int maxY = Math.min(world.getMaxY(), yPlusSearchHeight);
    while (y <= maxY) {
        // FAWE start - mutable
        if (world.getBlock(mutable.mutY(y)).getBlockType().getMaterial().isMovementBlocker()) {
            // FAWE end
            int platformY = Math.max(initialY, y - 3 - clearance);
            if (platformY < initialY) {
                // if ==, they already have the given clearance, if <, clearance is too large
                return false;
            } else if (platformY == initialY) {
                return false;
            }
            floatAt(x, platformY + 1, z, alwaysGlass);
            return true;
        }
        ++y;
    }
    return false;
}
Also used : MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) World(com.sk89q.worldedit.world.World) 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