Search in sources :

Example 6 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock 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 BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock 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 BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class ArbitraryShape method generate.

/**
 * Generates the shape.
 *
 * @param editSession The EditSession to use.
 * @param pattern     The pattern to generate default materials from.
 * @param hollow      Specifies whether to generate a hollow shape.
 * @return number of affected blocks.
 * @throws MaxChangedBlocksException if the maximum blocks changed is exceeded
 */
public int generate(EditSession editSession, Pattern pattern, boolean hollow) throws MaxChangedBlocksException {
    int affected = 0;
    for (BlockVector3 position : getExtent()) {
        int x = position.getBlockX();
        int y = position.getBlockY();
        int z = position.getBlockZ();
        if (!hollow) {
            BaseBlock material = getMaterial(x, y, z, pattern.applyBlock(position));
            if (material != null && editSession.setBlock(position, material)) {
                ++affected;
            }
            continue;
        }
        BaseBlock material = getMaterial(x, y, z, pattern.applyBlock(position));
        if (material == null) {
            final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
            cache[index] = -1;
            continue;
        }
        boolean draw = false;
        do {
            if (!isInsideCached(x + 1, y, z, pattern)) {
                draw = true;
                break;
            }
            if (!isInsideCached(x - 1, y, z, pattern)) {
                draw = true;
                break;
            }
            if (!isInsideCached(x, y, z + 1, pattern)) {
                draw = true;
                break;
            }
            if (!isInsideCached(x, y, z - 1, pattern)) {
                draw = true;
                break;
            }
            if (!isInsideCached(x, y + 1, z, pattern)) {
                draw = true;
                break;
            }
            if (!isInsideCached(x, y - 1, z, pattern)) {
                draw = true;
                break;
            }
        } while (false);
        if (!draw) {
            continue;
        }
        if (editSession.setBlock(position, material)) {
            ++affected;
        }
    }
    return affected;
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock)

Example 9 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class BukkitWorld method setBlock.

@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, SideEffectSet sideEffects) {
    if (worldNativeAccess != null) {
        try {
            return worldNativeAccess.setBlock(position, block, sideEffects);
        } catch (Exception e) {
            if (block instanceof BaseBlock && ((BaseBlock) block).getNbt() != null) {
                LOGGER.warn("Tried to set a corrupt tile entity at " + position.toString() + ": " + ((BaseBlock) block).getNbt(), e);
            } else {
                LOGGER.warn("Failed to set block via adapter, falling back to generic", e);
            }
        }
    }
    Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
    bukkitBlock.setBlockData(BukkitAdapter.adapt(block), sideEffects.doesApplyAny());
    return true;
}
Also used : Block(org.bukkit.block.Block) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) UnsupportedVersionEditException(com.sk89q.worldedit.bukkit.adapter.UnsupportedVersionEditException) WorldUnloadedException(com.fastasyncworldedit.bukkit.util.WorldUnloadedException) FaweException(com.fastasyncworldedit.core.internal.exception.FaweException) WorldEditException(com.sk89q.worldedit.WorldEditException)

Example 10 with BaseBlock

use of com.sk89q.worldedit.world.block.BaseBlock in project FastAsyncWorldEdit by IntellectualSites.

the class BlockTransformExtent method transformBaseBlockNBT.

private static BaseBlock transformBaseBlockNBT(BlockState transformed, CompoundTag tag, Transform transform) {
    if (tag != null) {
        if (tag.containsKey("Rot")) {
            int rot = tag.asInt("Rot");
            Direction direction = MCDirections.fromRotation(rot);
            if (direction != null) {
                Vector3 applyAbsolute = transform.apply(direction.toVector());
                Vector3 applyOrigin = transform.apply(Vector3.ZERO);
                applyAbsolute.mutX(applyAbsolute.getX() - applyOrigin.getX());
                applyAbsolute.mutY(applyAbsolute.getY() - applyOrigin.getY());
                applyAbsolute.mutZ(applyAbsolute.getZ() - applyOrigin.getZ());
                Direction newDirection = Direction.findClosest(applyAbsolute, Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL);
                if (newDirection != null) {
                    Map<String, Tag> values = new HashMap<>(tag.getValue());
                    values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
                    tag = new CompoundTag(values);
                }
            }
        }
        return new BaseBlock(transformed, tag);
    }
    return transformed.toBaseBlock();
}
Also used : HashMap(java.util.HashMap) ByteTag(com.sk89q.jnbt.ByteTag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) CompoundTag(com.sk89q.jnbt.CompoundTag) ByteTag(com.sk89q.jnbt.ByteTag) Tag(com.sk89q.jnbt.Tag) Direction(com.sk89q.worldedit.util.Direction) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) CompoundTag(com.sk89q.jnbt.CompoundTag)

Aggregations

BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)50 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)22 BlockState (com.sk89q.worldedit.world.block.BlockState)10 CompoundTag (com.sk89q.jnbt.CompoundTag)9 HashMap (java.util.HashMap)7 Tag (com.sk89q.jnbt.Tag)6 Location (com.sk89q.worldedit.util.Location)6 World (com.sk89q.worldedit.world.World)6 BlockType (com.sk89q.worldedit.world.block.BlockType)6 IOException (java.io.IOException)6 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)5 ListTag (com.sk89q.jnbt.ListTag)5 StringTag (com.sk89q.jnbt.StringTag)5 WorldEditException (com.sk89q.worldedit.WorldEditException)5 ArrayList (java.util.ArrayList)5 IntTag (com.sk89q.jnbt.IntTag)4 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)4 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)4 Region (com.sk89q.worldedit.regions.Region)4 NamedTag (com.sk89q.jnbt.NamedTag)3