Search in sources :

Example 1 with ByteTag

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

the class BlockTransformExtent method transformBaseBlockNBT.

private static BaseBlock transformBaseBlockNBT(BlockState transformed, CompoundTag tag, Transform transform) {
    if (tag != null) {
        if (tag.containsKey("Rot")) {
            int rot = tag.asInt("Rot");
            Direction direction = MCDirections.fromRotation(rot);
            if (direction != null) {
                Vector3 applyAbsolute = transform.apply(direction.toVector());
                Vector3 applyOrigin = transform.apply(Vector3.ZERO);
                applyAbsolute.mutX(applyAbsolute.getX() - applyOrigin.getX());
                applyAbsolute.mutY(applyAbsolute.getY() - applyOrigin.getY());
                applyAbsolute.mutZ(applyAbsolute.getZ() - applyOrigin.getZ());
                Direction newDirection = Direction.findClosest(applyAbsolute, Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL);
                if (newDirection != null) {
                    Map<String, Tag> values = new HashMap<>(tag.getValue());
                    values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
                    tag = new CompoundTag(values);
                }
            }
        }
        return new BaseBlock(transformed, tag);
    }
    return transformed.toBaseBlock();
}
Also used : HashMap(java.util.HashMap) ByteTag(com.sk89q.jnbt.ByteTag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) CompoundTag(com.sk89q.jnbt.CompoundTag) ByteTag(com.sk89q.jnbt.ByteTag) Tag(com.sk89q.jnbt.Tag) Direction(com.sk89q.worldedit.util.Direction) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 2 with ByteTag

use of com.sk89q.jnbt.ByteTag 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

ByteTag (com.sk89q.jnbt.ByteTag)2 Tag (com.sk89q.jnbt.Tag)2 Direction (com.sk89q.worldedit.util.Direction)2 CompoundTag (com.sk89q.jnbt.CompoundTag)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 Vector3 (com.sk89q.worldedit.math.Vector3)1 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)1 BlockState (com.sk89q.worldedit.world.block.BlockState)1 BlockType (com.sk89q.worldedit.world.block.BlockType)1 HashMap (java.util.HashMap)1