Search in sources :

Example 51 with BlockType

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

the class CachedBukkitAdapter method adapt.

/**
 * Create a WorldEdit BlockStateHolder from a Bukkit BlockData.
 *
 * @param blockData The Bukkit BlockData
 * @return The WorldEdit BlockState
 */
@Override
public BlockState adapt(BlockData blockData) {
    try {
        checkNotNull(blockData);
        Material material = blockData.getMaterial();
        BlockType type = BlockTypes.getFromStateId(blockTypes[material.ordinal()]);
        List<? extends Property> propList = type.getProperties();
        if (propList.size() == 0) {
            return type.getDefaultState();
        }
        String properties = blockData.getAsString();
        return BlockState.get(type, properties, type.getDefaultState());
    } catch (NullPointerException e) {
        if (init()) {
            return adapt(blockData);
        }
        throw e;
    }
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType) Material(org.bukkit.Material)

Example 52 with BlockType

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

the class FloatingTreeRemover method bfs.

/**
 * Helper method.
 *
 * @param world  the world that contains the tree
 * @param origin any point contained in the floating tree
 * @return a set containing all blocks in the tree/shroom or null if this is not a floating tree/shroom.
 */
private Set<BlockVector3> bfs(World world, BlockVector3 origin) {
    // FAWE start - Use a LBVS over a HashMap & LinkedList
    final LocalBlockVectorSet visited = new LocalBlockVectorSet();
    final LocalBlockVectorSet queue = new LocalBlockVectorSet();
    // FAWE end
    queue.add(origin);
    visited.add(origin);
    while (!queue.isEmpty()) {
        Iterator<BlockVector3> iter = queue.iterator();
        while (iter.hasNext()) {
            final BlockVector3 current = iter.next();
            iter.remove();
            for (BlockVector3 recurseDirection : recurseDirections) {
                final BlockVector3 next = current.add(recurseDirection);
                if (origin.distanceSq(next) > rangeSq) {
                    // Maximum range exceeded => stop walking
                    continue;
                }
                if (visited.add(next)) {
                    BlockState state = world.getBlock(next);
                    if (state.getBlockType().getMaterial().isAir() || state.getBlockType() == BlockTypes.SNOW) {
                        continue;
                    }
                    if (isTreeBlock(state.getBlockType())) {
                        queue.add(next);
                    } else {
                        // we hit something solid - evaluate where we came from
                        final BlockType currentType = world.getBlock(current).getBlockType();
                        if (!BlockCategories.LEAVES.contains(currentType) && currentType != BlockTypes.VINE) {
                            // log/shroom touching a wall/the ground => this is not a floating tree, bail out
                            return null;
                        }
                    }
                }
            }
        }
    }
    return visited;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType) LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 53 with BlockType

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

the class FloodFillTool method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
    World world = (World) clicked.getExtent();
    BlockVector3 origin = clicked.toVector().toBlockPoint();
    BlockType initialType = world.getBlock(origin).getBlockType();
    if (initialType.getMaterial().isAir()) {
        return true;
    }
    if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
        return true;
    }
    try (EditSession editSession = session.createEditSession(player, "FloodFillTool")) {
        try {
            // FAWE start - Respect masks
            Mask mask = initialType.toMask(editSession);
            BlockReplace function = new BlockReplace(editSession, pattern);
            RecursiveVisitor visitor = new RecursiveVisitor(mask, function, range, editSession.getMinY(), editSession.getMaxY(), editSession);
            visitor.visit(origin);
            Operations.completeLegacy(visitor);
        // FAWE end
        } catch (MaxChangedBlocksException e) {
            player.print(Caption.of("worldedit.tool.max-block-changes"));
        } finally {
            session.remember(editSession);
        }
    }
    return true;
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType) Mask(com.sk89q.worldedit.function.mask.Mask) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) EditSession(com.sk89q.worldedit.EditSession) World(com.sk89q.worldedit.world.World) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 54 with BlockType

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

the class RecursivePickaxe method actPrimary.

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
    World world = (World) clicked.getExtent();
    final BlockVector3 pos = clicked.toBlockPoint();
    BlockVector3 origin = clicked.toVector().toBlockPoint();
    BlockType initialType = world.getBlock(origin).getBlockType();
    if (initialType.getMaterial().isAir()) {
        return false;
    }
    if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
        return false;
    }
    try (EditSession editSession = session.createEditSession(player, "RecursivePickaxe")) {
        editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
        // FAWE start
        final int radius = (int) range;
        final BlockReplace replace = new BlockReplace(editSession, (BlockTypes.AIR.getDefaultState()));
        editSession.setMask(null);
        RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession.getMinY(), editSession.getMaxY(), editSession);
        // TODO: Fix below
        // visitor.visit(pos);
        // Operations.completeBlindly(visitor);
        recurse(server, editSession, world, pos, origin, radius, initialType, visitor.getVisited());
        // FAWE end
        editSession.flushQueue();
        session.remember(editSession);
    }
    return true;
}
Also used : IdMask(com.fastasyncworldedit.core.function.mask.IdMask) BlockType(com.sk89q.worldedit.world.block.BlockType) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) EditSession(com.sk89q.worldedit.EditSession) World(com.sk89q.worldedit.world.World) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace)

Example 55 with BlockType

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

the class EditSession method popMissingBlocks.

/**
 * Gets the list of missing blocks and clears the list for the next
 * operation.
 *
 * @return a map of missing blocks
 */
public Map<BlockType, Integer> popMissingBlocks() {
    BlockBag bag = getBlockBag();
    if (bag != null) {
        bag.flushChanges();
        Map<BlockType, Integer> missingBlocks;
        ChangeSet changeSet = getChangeSet();
        if (changeSet instanceof BlockBagChangeSet) {
            missingBlocks = ((BlockBagChangeSet) changeSet).popMissing();
        } else {
            ExtentTraverser<BlockBagExtent> find = new ExtentTraverser<>(getExtent()).find(BlockBagExtent.class);
            if (find != null && find.get() != null) {
                missingBlocks = find.get().popMissing();
            } else {
                missingBlocks = null;
            }
        }
        if (missingBlocks != null && !missingBlocks.isEmpty()) {
            StringBuilder str = new StringBuilder();
            int size = missingBlocks.size();
            int i = 0;
            for (Map.Entry<BlockType, Integer> entry : missingBlocks.entrySet()) {
                BlockType type = entry.getKey();
                int amount = entry.getValue();
                str.append((type.getName())).append((amount != 1 ? "x" + amount : ""));
                ++i;
                if (i != size) {
                    str.append(", ");
                }
            }
            actor.print(Caption.of("fawe.error.worldedit.some.fails.blockbag", str.toString()));
        }
    }
    return Collections.emptyMap();
}
Also used : BlockBagExtent(com.sk89q.worldedit.extent.inventory.BlockBagExtent) BlockBag(com.sk89q.worldedit.extent.inventory.BlockBag) BlockBagChangeSet(com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlockType(com.sk89q.worldedit.world.block.BlockType) BlockBagChangeSet(com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet) ChangeSet(com.sk89q.worldedit.history.changeset.ChangeSet) AbstractChangeSet(com.fastasyncworldedit.core.history.changeset.AbstractChangeSet) Map(java.util.Map) HashMap(java.util.HashMap) BlockMap(com.sk89q.worldedit.util.collection.BlockMap)

Aggregations

BlockType (com.sk89q.worldedit.world.block.BlockType)66 BlockState (com.sk89q.worldedit.world.block.BlockState)20 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)19 Map (java.util.Map)12 HashMap (java.util.HashMap)10 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)9 World (com.sk89q.worldedit.world.World)8 ArrayList (java.util.ArrayList)8 TextureUtil (com.fastasyncworldedit.core.util.TextureUtil)7 List (java.util.List)7 EditSession (com.sk89q.worldedit.EditSession)6 IOException (java.io.IOException)6 Set (java.util.Set)6 CompoundTag (com.sk89q.jnbt.CompoundTag)5 Tag (com.sk89q.jnbt.Tag)5 Region (com.sk89q.worldedit.regions.Region)5 Property (com.sk89q.worldedit.registry.state.Property)5 Direction (com.sk89q.worldedit.util.Direction)5 Locale (java.util.Locale)5 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)4