Search in sources :

Example 1 with BlockState

use of com.sk89q.worldedit.world.block.BlockState in project CoreProtect by PlayPro.

the class CoreProtectLogger method setBlock.

@Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
    org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
    if (!Config.getConfig(world).WORLDEDIT) {
        return eventExtent.setBlock(position, block);
    }
    BlockState oldBlock = eventExtent.getBlock(position);
    Material oldType = BukkitAdapter.adapt(oldBlock.getBlockType());
    Location location = new Location(world, position.getBlockX(), position.getBlockY(), position.getBlockZ());
    BaseBlock baseBlock = WorldEditLogger.getBaseBlock(eventExtent, position, location, oldType, oldBlock);
    // No clear way to get container content data from within the WorldEdit API
    // Data may be available by converting oldBlock.toBaseBlock().getNbtData()
    // e.g. BaseBlock block = eventWorld.getBlock(position);
    ItemStack[] containerData = Util.getContainerContents(oldType, null, location);
    if (eventExtent.setBlock(position, block)) {
        WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
        return true;
    }
    return false;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Location(org.bukkit.Location)

Example 2 with BlockState

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

the class AngleColorPattern method apply.

@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
    BlockState block = get.getBlock(extent);
    int slope = getSlope(block, get, extent);
    if (slope == -1) {
        return false;
    }
    BlockType type = block.getBlockType();
    int color;
    if (type == BlockTypes.GRASS_BLOCK) {
        color = holder.getTextureUtil().getColor(extent.getBiome(get));
    } else {
        color = holder.getTextureUtil().getColor(type);
    }
    if (color == 0) {
        return false;
    }
    int newColor = getColor(color, slope);
    BlockType newBlock = holder.getTextureUtil().getNearestBlock(newColor);
    if (newBlock == null) {
        return false;
    }
    return set.setBlock(extent, newBlock.getDefaultState());
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType)

Example 3 with BlockState

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

the class AngleColorPattern method getSlope.

@Override
public <T extends BlockStateHolder<T>> int getSlope(T block, BlockVector3 vector, Extent extent) {
    int slope = super.getSlope(block, vector, extent);
    if (slope != -1) {
        int x = vector.getBlockX();
        int y = vector.getBlockY();
        int z = vector.getBlockZ();
        int height = extent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY);
        if (height > minY) {
            BlockState below = extent.getBlock(x, height - 1, z);
            if (!below.getBlockType().getMaterial().isMovementBlocker()) {
                return Integer.MAX_VALUE;
            }
        }
    }
    return slope;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState)

Example 4 with BlockState

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

the class LayerBrushMask method test.

@Override
public boolean test(BlockVector3 pos) {
    int depth = (visitor.getDepth() + 1) % layers.length;
    if (depth > 1) {
        boolean found = false;
        BlockState previous = layers[depth - 1];
        BlockState previous2 = layers[depth - 2];
        for (BlockVector3 dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) {
            mutable.setComponents(pos.getBlockX() + dir.getBlockX(), pos.getBlockY() + dir.getBlockY(), pos.getBlockZ() + dir.getBlockZ());
            if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous) {
                mutable.setComponents(pos.getBlockX() + dir.getBlockX() * 2, pos.getBlockY() + dir.getBlockY() * 2, pos.getBlockZ() + dir.getBlockZ() * 2);
                if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous2) {
                    found = true;
                    break;
                } else {
                    return false;
                }
            }
        }
        if (!found) {
            return false;
        }
    }
    return !adjacent.test(pos);
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3)

Example 5 with BlockState

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

the class BlockTransformExtent method transformState.

private static int transformState(BlockState state, Transform transform) {
    int newMaskedId = state.getInternalId();
    BlockType type = state.getBlockType();
    // Rotate North, East, South, West
    if (type.hasProperty(PropertyKey.NORTH) && type.hasProperty(PropertyKey.EAST) && type.hasProperty(PropertyKey.SOUTH) && type.hasProperty(PropertyKey.WEST)) {
        BlockState tmp = state;
        for (Map.Entry<Direction, PropertyKey> entry : directionMap.entrySet()) {
            Direction newDir = findClosest(transform.apply(entry.getKey().toVector()), Flag.CARDINAL);
            if (newDir != null) {
                Object dirState = state.getState(entry.getValue());
                tmp = tmp.with(directionMap.get(newDir), dirState);
            }
        }
        newMaskedId = tmp.getInternalId();
    }
    // True if relying on two different "directions" for the result, e.g. stairs with both facing and shape
    for (AbstractProperty property : (List<AbstractProperty<?>>) type.getProperties()) {
        if (isDirectional(property)) {
            long[] directions = getDirections(property);
            if (directions != null) {
                int oldIndex = property.getIndex(state.getInternalId());
                if (oldIndex >= directions.length) {
                    if (Settings.settings().ENABLED_COMPONENTS.DEBUG) {
                        LOGGER.warn(String.format("Index outside direction array length found for block:{%s} property:{%s}", state.getBlockType().getId(), property.getName()));
                    }
                    continue;
                }
                Integer newIndex = getNewStateIndex(transform, directions, oldIndex);
                if (newIndex != null) {
                    newMaskedId = property.modifyIndex(newMaskedId, newIndex);
                }
            }
        }
    }
    return newMaskedId;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType) AbstractProperty(com.sk89q.worldedit.registry.state.AbstractProperty) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Direction(com.sk89q.worldedit.util.Direction) PropertyKey(com.fastasyncworldedit.core.registry.state.PropertyKey)

Aggregations

BlockState (com.sk89q.worldedit.world.block.BlockState)68 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)24 BlockType (com.sk89q.worldedit.world.block.BlockType)18 HashMap (java.util.HashMap)11 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)10 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)10 CompoundTag (com.sk89q.jnbt.CompoundTag)9 Tag (com.sk89q.jnbt.Tag)9 Map (java.util.Map)8 IntTag (com.sk89q.jnbt.IntTag)7 Region (com.sk89q.worldedit.regions.Region)7 ArrayList (java.util.ArrayList)7 ListTag (com.sk89q.jnbt.ListTag)6 StringTag (com.sk89q.jnbt.StringTag)6 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)5 IOException (java.io.IOException)5 NamedTag (com.sk89q.jnbt.NamedTag)4 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)4 Direction (com.sk89q.worldedit.util.Direction)4 Location (com.sk89q.worldedit.util.Location)4