Search in sources :

Example 21 with BlockType

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

the class TextureUtil method fromClipboard.

public static TextureUtil fromClipboard(Clipboard clipboard) throws FileNotFoundException {
    boolean[] ids = new boolean[BlockTypes.size()];
    for (BlockVector3 pt : clipboard.getRegion()) {
        ids[clipboard.getBlock(pt).getInternalBlockTypeId()] = true;
    }
    HashSet<BlockType> blocks = new HashSet<>();
    for (int typeId = 0; typeId < ids.length; typeId++) {
        if (ids[typeId]) {
            blocks.add(BlockTypes.get(typeId));
        }
    }
    return fromBlocks(blocks);
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType) BlockVector3(com.sk89q.worldedit.math.BlockVector3) HashSet(java.util.HashSet)

Example 22 with BlockType

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

the class TextureUtil method getIsBlockCloserThanBiome.

protected boolean getIsBlockCloserThanBiome(char[] blockAndBiomeIdOutput, int color, int biomePriority) {
    BlockType block = getNearestBlock(color);
    TextureUtil.BiomeColor biome = getNearestBiome(color);
    int blockColor = getColor(block);
    blockAndBiomeIdOutput[0] = block.getDefaultState().getOrdinalChar();
    blockAndBiomeIdOutput[1] = (char) biome.id;
    return colorDistance(biome.grassCombined, color) - biomePriority > colorDistance(blockColor, color);
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType)

Example 23 with BlockType

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

the class RandomTextureUtil method getNearestBlock.

@Override
public BlockType getNearestBlock(int color) {
    int offsetColor = offsets.getOrDefault((Object) color, 0);
    if (offsetColor != 0) {
        offsetColor = addRandomColor(color, offsetColor);
    } else {
        offsetColor = color;
    }
    BlockType res = super.getNearestBlock(offsetColor);
    if (res == null) {
        return null;
    }
    int newColor = getColor(res);
    byte dr = (byte) (((color >> 16) & 0xFF) - ((newColor >> 16) & 0xFF));
    byte dg = (byte) (((color >> 8) & 0xFF) - ((newColor >> 8) & 0xFF));
    byte db = (byte) (((color >> 0) & 0xFF) - ((newColor >> 0) & 0xFF));
    offsets.put(color, (Integer) ((dr << 16) + (dg << 8) + (db << 0)));
    return res;
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType)

Example 24 with BlockType

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

the class PropertyGroup method get.

public <B extends BlockStateHolder<B>> G get(BlockStateHolder<B> state) {
    BlockType type = state.getBlockType();
    PropertyFunction func = states[type.getInternalId()];
    if (func == null) {
        return defaultValue;
    }
    Object value = state.getState(func.key);
    return (G) func.getFunc.apply(value);
}
Also used : BlockType(com.sk89q.worldedit.world.block.BlockType)

Example 25 with BlockType

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

the class MinecraftStructure method read.

@Override
public Clipboard read(UUID clipboardId) throws IOException {
    NamedTag rootTag = inputStream.readNamedTag();
    // MC structures are all unnamed, but this doesn't seem to be necessary? might remove this later
    if (!rootTag.getName().isEmpty()) {
        throw new IOException("Root tag has name - are you sure this is a structure?");
    }
    Map<String, Tag> tags = ((CompoundTag) rootTag.getTag()).getValue();
    ListTag size = (ListTag) tags.get("size");
    int width = size.getInt(0);
    int height = size.getInt(1);
    int length = size.getInt(2);
    // Init clipboard
    BlockVector3 origin = BlockVector3.at(0, 0, 0);
    CuboidRegion region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
    Clipboard clipboard = new BlockArrayClipboard(region, clipboardId);
    // Blocks
    ListTag blocks = (ListTag) tags.get("blocks");
    if (blocks != null) {
        // Palette
        List<CompoundTag> palette = (List<CompoundTag>) tags.get("palette").getValue();
        BlockState[] combinedArray = new BlockState[palette.size()];
        for (int i = 0; i < palette.size(); i++) {
            CompoundTag compound = palette.get(i);
            Map<String, Tag> map = compound.getValue();
            String name = ((StringTag) map.get("Name")).getValue();
            BlockType type = BlockTypes.get(name);
            BlockState state = type.getDefaultState();
            CompoundTag properties = (CompoundTag) map.get("Properties");
            if (properties != null) {
                for (Map.Entry<String, Tag> entry : properties.getValue().entrySet()) {
                    String key = entry.getKey();
                    String value = ((StringTag) entry.getValue()).getValue();
                    Property<Object> property = type.getProperty(key);
                    state = state.with(property, property.getValueFor(value));
                }
            }
            combinedArray[i] = state;
        }
        // Populate blocks
        List<CompoundTag> blocksList = (List<CompoundTag>) tags.get("blocks").getValue();
        try {
            for (CompoundTag compound : blocksList) {
                Map<String, Tag> blockMap = compound.getValue();
                IntTag stateTag = (IntTag) blockMap.get("state");
                ListTag posTag = (ListTag) blockMap.get("pos");
                BlockState state = combinedArray[stateTag.getValue()];
                int x = posTag.getInt(0);
                int y = posTag.getInt(1);
                int z = posTag.getInt(2);
                if (state.getBlockType().getMaterial().hasContainer()) {
                    CompoundTag nbt = (CompoundTag) blockMap.get("nbt");
                    if (nbt != null) {
                        BaseBlock block = state.toBaseBlock(nbt);
                        clipboard.setBlock(x, y, z, block);
                        continue;
                    }
                }
                clipboard.setBlock(x, y, z, state);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // Entities
    ListTag entities = (ListTag) tags.get("entities");
    if (entities != null) {
        List<CompoundTag> entityList = (List<CompoundTag>) (List<?>) entities.getValue();
        for (CompoundTag entityEntry : entityList) {
            Map<String, Tag> entityEntryMap = entityEntry.getValue();
            ListTag posTag = (ListTag) entityEntryMap.get("pos");
            CompoundTag nbtTag = (CompoundTag) entityEntryMap.get("nbt");
            String id = nbtTag.getString("Id");
            Location location = NBTConversions.toLocation(clipboard, posTag, nbtTag.getListTag("Rotation"));
            if (!id.isEmpty()) {
                BaseEntity state = new BaseEntity(EntityTypes.get(id), nbtTag);
                clipboard.createEntity(location, state);
            }
        }
    }
    return clipboard;
}
Also used : StringTag(com.sk89q.jnbt.StringTag) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) NamedTag(com.sk89q.jnbt.NamedTag) ArrayList(java.util.ArrayList) List(java.util.List) CompoundTag(com.sk89q.jnbt.CompoundTag) IntTag(com.sk89q.jnbt.IntTag) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) IOException(java.io.IOException) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ListTag(com.sk89q.jnbt.ListTag) IOException(java.io.IOException) BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType) StringTag(com.sk89q.jnbt.StringTag) ListTag(com.sk89q.jnbt.ListTag) IntTag(com.sk89q.jnbt.IntTag) NamedTag(com.sk89q.jnbt.NamedTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) HashMap(java.util.HashMap) Map(java.util.Map) Int2ObjectArrayMap(it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap) Location(com.sk89q.worldedit.util.Location)

Aggregations

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