Search in sources :

Example 11 with IntTag

use of com.sk89q.jnbt.IntTag 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 12 with IntTag

use of com.sk89q.jnbt.IntTag in project FastAsyncWorldEdit by IntellectualSites.

the class FlowerPotCompatibilityHandler method updateNBT.

@Override
public <B extends BlockStateHolder<B>> BlockStateHolder<?> updateNBT(B block, Map<String, Tag> values) {
    Tag item = values.get("Item");
    if (item instanceof StringTag) {
        String id = ((StringTag) item).getValue();
        if (id.isEmpty()) {
            return BlockTypes.FLOWER_POT.getDefaultState();
        }
        int data = 0;
        Tag dataTag = values.get("Data");
        if (dataTag instanceof IntTag) {
            data = ((IntTag) dataTag).getValue();
        }
        BlockState newState = convertLegacyBlockType(id, data);
        if (newState != null) {
            values.clear();
            return newState;
        }
    }
    return block;
}
Also used : StringTag(com.sk89q.jnbt.StringTag) BlockState(com.sk89q.worldedit.world.block.BlockState) Tag(com.sk89q.jnbt.Tag) StringTag(com.sk89q.jnbt.StringTag) IntTag(com.sk89q.jnbt.IntTag) IntTag(com.sk89q.jnbt.IntTag)

Aggregations

IntTag (com.sk89q.jnbt.IntTag)12 Tag (com.sk89q.jnbt.Tag)12 CompoundTag (com.sk89q.jnbt.CompoundTag)10 HashMap (java.util.HashMap)9 ListTag (com.sk89q.jnbt.ListTag)7 StringTag (com.sk89q.jnbt.StringTag)7 ShortTag (com.sk89q.jnbt.ShortTag)5 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)5 BlockState (com.sk89q.worldedit.world.block.BlockState)5 ByteArrayTag (com.sk89q.jnbt.ByteArrayTag)4 IntArrayTag (com.sk89q.jnbt.IntArrayTag)4 NamedTag (com.sk89q.jnbt.NamedTag)3 BlockType (com.sk89q.worldedit.world.block.BlockType)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 IntTriple (com.fastasyncworldedit.core.math.IntTriple)2 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 Region (com.sk89q.worldedit.regions.Region)2 Direction (com.sk89q.worldedit.util.Direction)2