Search in sources :

Example 41 with BlockType

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

the class AverageColorPattern method apply.

@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
    BlockType blockType = get.getBlock(extent).getBlockType();
    TextureUtil util = holder.getTextureUtil();
    int currentColor;
    if (blockType == BlockTypes.GRASS_BLOCK) {
        currentColor = holder.getTextureUtil().getColor(extent.getBiome(get));
    } else {
        currentColor = holder.getTextureUtil().getColor(blockType);
    }
    if (currentColor == 0) {
        return false;
    }
    int newColor = TextureUtil.averageColor(currentColor, color);
    BlockType newBlock = util.getNearestBlock(newColor);
    if (newBlock == blockType) {
        return false;
    }
    return set.setBlock(extent, newBlock.getDefaultState());
}
Also used : TextureUtil(com.fastasyncworldedit.core.util.TextureUtil) BlockType(com.sk89q.worldedit.world.block.BlockType)

Example 42 with BlockType

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

the class DesaturatePattern method apply.

@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
    BlockType type = get.getBlock(extent).getBlockType();
    TextureUtil util = holder.getTextureUtil();
    int color;
    if (type == BlockTypes.GRASS_BLOCK) {
        color = holder.getTextureUtil().getColor(extent.getBiome(get));
    } else {
        color = holder.getTextureUtil().getColor(type);
    }
    int newColor = getColor(color);
    if (newColor == color) {
        return false;
    }
    BlockType newType = util.getNextNearestBlock(newColor);
    if (type.equals(newType)) {
        return false;
    }
    return set.setBlock(extent, newType.getDefaultState());
}
Also used : TextureUtil(com.fastasyncworldedit.core.util.TextureUtil) BlockType(com.sk89q.worldedit.world.block.BlockType)

Example 43 with BlockType

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

the class BedBlockCompatibilityHandler method updateNBT.

@Override
public <B extends BlockStateHolder<B>> BlockStateHolder<?> updateNBT(B block, Map<String, Tag> values) {
    Tag typeTag = values.get("color");
    if (typeTag instanceof IntTag) {
        String bedType = convertBedType(((IntTag) typeTag).getValue());
        if (bedType != null) {
            BlockType type = BlockTypes.get("minecraft:" + bedType);
            if (type != null) {
                BlockState state = type.getDefaultState();
                Property<Direction> facingProp = type.getProperty("facing");
                state = state.with(facingProp, block.getState(FACING_PROPERTY));
                Property<Boolean> occupiedProp = type.getProperty("occupied");
                state = state.with(occupiedProp, false);
                Property<String> partProp = type.getProperty("part");
                state = state.with(partProp, block.getState(PART_PROPERTY));
                values.remove("color");
                return state;
            }
        }
    }
    return block;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType) Tag(com.sk89q.jnbt.Tag) IntTag(com.sk89q.jnbt.IntTag) Direction(com.sk89q.worldedit.util.Direction) IntTag(com.sk89q.jnbt.IntTag)

Example 44 with BlockType

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

the class FlowerPotCompatibilityHandler method convertLegacyBlockType.

private BlockState convertLegacyBlockType(String id, int data) {
    int newId = 0;
    switch(id) {
        case "minecraft:red_flower":
            // now poppy
            newId = 38;
            break;
        case "minecraft:yellow_flower":
            // now dandelion
            newId = 37;
            break;
        case "minecraft:sapling":
            // oak_sapling
            newId = 6;
            break;
        case "minecraft:deadbush":
        case "minecraft:tallgrass":
            // dead_bush with fern and grass (not 32!)
            newId = 31;
            break;
        default:
            break;
    }
    String plantedName = null;
    if (newId == 0 && id.startsWith("minecraft:")) {
        plantedName = id.substring(10);
    } else {
        BlockState plantedWithData = LegacyMapper.getInstance().getBlockFromLegacy(newId, data);
        if (plantedWithData != null) {
            // remove "minecraft:"
            plantedName = plantedWithData.getBlockType().getId().substring(10);
        }
    }
    if (plantedName != null) {
        BlockType potAndPlanted = BlockTypes.get("minecraft:potted_" + plantedName);
        if (potAndPlanted != null) {
            return potAndPlanted.getDefaultState();
        }
    }
    return null;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType)

Example 45 with BlockType

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

the class SkullBlockCompatibilityHandler method updateNBT.

@Override
public <B extends BlockStateHolder<B>> BlockStateHolder<?> updateNBT(B block, Map<String, Tag> values) {
    boolean isWall = block.getBlockType() == BlockTypes.SKELETON_WALL_SKULL;
    Tag typeTag = values.get("SkullType");
    if (typeTag instanceof ByteTag) {
        String skullType = convertSkullType(((ByteTag) typeTag).getValue(), isWall);
        if (skullType != null) {
            BlockType type = BlockTypes.get("minecraft:" + skullType);
            if (type != null) {
                BlockState state = type.getDefaultState();
                if (isWall) {
                    Property<Direction> newProp = type.getProperty("facing");
                    state = state.with(newProp, block.getState(FacingProperty));
                } else {
                    Tag rotTag = values.get("Rot");
                    if (rotTag instanceof ByteTag) {
                        Property<Integer> newProp = type.getProperty("rotation");
                        state = state.with(newProp, (int) ((ByteTag) rotTag).getValue());
                    }
                }
                values.remove("SkullType");
                values.remove("Rot");
                return state;
            }
        }
    }
    return block;
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) ByteTag(com.sk89q.jnbt.ByteTag) BlockType(com.sk89q.worldedit.world.block.BlockType) ByteTag(com.sk89q.jnbt.ByteTag) Tag(com.sk89q.jnbt.Tag) Direction(com.sk89q.worldedit.util.Direction)

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