import { Biome } from '../chunk';
import BlockTransformation from '../transformations/blockTransformation';
import ConditionalBlockTransformation from '../transformations/conditionalBlockTransformation';
import { convertBlockBelow, convertCactus, convertNeighbouringCacti, convertSeaGrass, destroyHangingPlant, destroyRisingPlant, destroyRisingPlantBidirectional, destroyTallPlant, isInAshPatch, replaceDirtBelow } from './utils';
const TALL_FLOWER_CONVERSION_CHANCE = 0.7;
const rules = [
    {
        from: ['minecraft:short_grass'],
        to: new BlockTransformation(null)
    },
    {
        from: ['minecraft:tall_grass'],
        to: new BlockTransformation(null, {
            conditions: { upper_block_bit: false },
            afterConvert: destroyTallPlant
        })
    },
    {
        from: [
            'minecraft:cornflower',
            'minecraft:orange_tulip',
            'minecraft:pink_tulip',
            'minecraft:red_tulip',
            'minecraft:white_tulip',
            'minecraft:poppy',
            'minecraft:dandelion',
            'minecraft:blue_orchid',
            'minecraft:azure_bluet',
            'minecraft:oxeye_daisy',
            'minecraft:lily_of_the_valley',
            'minecraft:fern',
            'minecraft:closed_eyeblossom',
            'minecraft:open_eyeblossom',
            'minecraft:allium',
            'minecraft:wildflower',
            'minecraft:leaf_litter',
            'minecraft:bush',
            'minecraft:firefly_bush',
            'minecraft:tall_dry_grass',
            'minecraft:cactus_flower',
        ],
        // to: new ConditionalBlockTransformation(
        //   new BlockTransformation(null),
        //   new BlockTransformation('minecraft:wither_rose'),
        //   (b) => isInAshPatch(b.below())
        // ),
        to: new BlockTransformation(null)
    },
    {
        from: [
            'minecraft:large_fern',
            'minecraft:sunflower',
            'minecraft:peony',
            'minecraft:lilac',
            'minecraft:rose_bush'
        ],
        to: new ConditionalBlockTransformation(new BlockTransformation(null, {
            conditions: { upper_block_bit: false },
            afterConvert: destroyTallPlant
        }), new BlockTransformation('twb_wisu:blooming_wilt', {
            conditions: { upper_block_bit: false },
            mapStates: { upper_block_bit: 'twb_wisu:upper_block_bit' }
        }), (b) => Math.random() > TALL_FLOWER_CONVERSION_CHANCE || isInAshPatch(b.below())),
    },
    {
        from: [
            'minecraft:snow_layer',
            'minecraft:vine',
            'minecraft:red_mushroom',
            'minecraft:brown_mushroom',
            'minecraft:red_mushroom_block',
            'minecraft:brown_mushroom_block',
        ],
        to: new BlockTransformation(null)
    },
    {
        from: ['minecraft:mushroom_stem'],
        to: new BlockTransformation(null, { afterConvert: replaceDirtBelow })
    },
    {
        from: ['minecraft:sweet_berry_bush'],
        to: new ConditionalBlockTransformation(new BlockTransformation(null), new BlockTransformation('twb_wisu:blooming_wilt'), (b) => isInAshPatch(b.below())),
    },
    {
        from: ['minecraft:reeds'],
        to: new BlockTransformation(null, { beforeConvert: destroyRisingPlant })
    },
    {
        from: ['minecraft:bamboo'],
        to: new BlockTransformation(null, { setBiome: Biome.JUNGLE, afterConvert: destroyRisingPlantBidirectional }),
    },
    {
        from: [
            'minecraft:vine',
            'minecraft:cave_vine',
            'minecraft:pale_hanging_moss',
        ],
        to: new BlockTransformation(null, { beforeConvert: destroyHangingPlant })
    },
    {
        from: [
            'minecraft:melon_block',
            'minecraft:melon_stem',
            'minecraft:pumpkin',
            'minecraft:carved_pumpkin',
            'minecraft:pumpkin_stem',
            'minecraft:moss_carpet',
            'minecraft:pink_petals',
        ],
        to: new BlockTransformation(null)
    },
    {
        from: ['minecraft:seagrass'],
        to: new BlockTransformation('minecraft:water', { afterConvert: convertSeaGrass })
    },
    {
        from: ['minecraft:cactus'],
        to: new BlockTransformation('twb_wisu:hollowed_cactus', { setBiome: Biome.DESERT, afterConvert: convertCactus })
    },
    {
        from: ['minecraft:deadbush'],
        to: new BlockTransformation('twb_wisu:hollowed_bush', { setBiome: Biome.DESERT, beforeConvert: convertNeighbouringCacti })
    },
    {
        from: ['minecraft:waterlily'],
        to: new BlockTransformation('twb_wisu:witherlily_block')
    },
    {
        from: [
            'minecraft:carrots',
            'minecraft:potatoes',
            'minecraft:beetroot',
            'minecraft:wheat',
        ],
        to: new BlockTransformation('twb_wisu:wilt', { afterConvert: convertBlockBelow })
    },
    {
        from: ['minecraft:moss_block'],
        to: new BlockTransformation('twb_wisu:ash', { beforeConvert: convertBlockBelow })
    },
    {
        from: ['minecraft:moss_layer'],
        to: new BlockTransformation('twb_wisu:ash_layer')
    },
    {
        from: [
            'minecraft:cave_vines',
            'minecraft:cave_vines_body_with_berries',
            'minecraft:cave_vines_head_with_berries',
        ],
        to: new BlockTransformation(null, { beforeConvert: convertBlockBelow })
    },
    {
        from: ['minecraft:spore_blossom'],
        to: new BlockTransformation(null)
    },
];
export default rules;
