//set block fence tag here
export const FenceTag = 'gs_cb:is_fence';
export const prefix = 'gs_cb';
const bannedBlocks = [
    "gs_cb:frozen_door",
    "gs_cb:frozen_trapdoor",
    "gs_cb:frozen_slab",
    "gs_cb:burnt_door",
    "gs_cb:burnt_trapdoor",
    "gs_cb:burnt_slab",
    "gs_cb:charred_burnt_door",
    "gs_cb:charred_burnt_trapdoor",
    "gs_cb:charred_burnt_slab",
    "gs_cb:smoldering_burnt_door",
    "gs_cb:smoldering_burnt_trapdoor",
    "gs_cb:smoldering_burnt_slab",
    "minecraft:acacia_button",
    "minecraft:acacia_door",
    "minecraft:acacia_hanging_sign",
    "minecraft:acacia_leaves",
    "minecraft:acacia_pressure_plate",
    "minecraft:acacia_sapling",
    "minecraft:acacia_slab",
    "minecraft:acacia_standing_sign",
    "minecraft:acacia_trapdoor",
    "minecraft:acacia_wall_sign",
    "minecraft:activator_rail",
    "minecraft:allium",
    "minecraft:amethyst_cluster",
    "minecraft:andesite_slab",
    "minecraft:anvil",
    "minecraft:azalea",
    "minecraft:azalea_leaves",
    "minecraft:azalea_leaves_flowered",
    "minecraft:azure_bluet",
    "minecraft:bamboo",
    "minecraft:bamboo_button",
    "minecraft:bamboo_door",
    "minecraft:bamboo_hanging_sign",
    "minecraft:bamboo_mosaic_slab",
    "minecraft:bamboo_pressure_plate",
    "minecraft:bamboo_sapling",
    "minecraft:bamboo_slab",
    "minecraft:bamboo_standing_sign",
    "minecraft:bamboo_trapdoor",
    "minecraft:bamboo_wall_sign",
    "minecraft:barrier",
    "minecraft:beetroot",
    "minecraft:bell",
    "minecraft:big_dripleaf",
    "minecraft:birch_button",
    "minecraft:birch_door",
    "minecraft:birch_hanging_sign",
    "minecraft:birch_leaves",
    "minecraft:birch_pressure_plate",
    "minecraft:birch_sapling",
    "minecraft:birch_slab",
    "minecraft:birch_standing_sign",
    "minecraft:birch_trapdoor",
    "minecraft:birch_wall_sign",
    "minecraft:black_candle",
    "minecraft:black_candle_cake",
    "minecraft:black_carpet",
    "minecraft:black_shulker_box",
    "minecraft:black_stained_glass_pane",
    "minecraft:blackstone_slab",
    "minecraft:blackstone_wall",
    "minecraft:blue_candle",
    "minecraft:blue_candle_cake",
    "minecraft:blue_carpet",
    "minecraft:blue_orchid",
    "minecraft:blue_shulker_box",
    "minecraft:blue_stained_glass_pane",
    "minecraft:border_block",
    "minecraft:brain_coral",
    "minecraft:brain_coral_fan",
    "minecraft:brain_coral_wall_fan",
    "minecraft:brewing_stand",
    "minecraft:brick_slab",
    "minecraft:brown_candle",
    "minecraft:brown_candle_cake",
    "minecraft:brown_carpet",
    "minecraft:brown_carpet",
    "minecraft:brown_mushroom",
    "minecraft:brown_shulker_box",
    "minecraft:brown_stained_glass_pane",
    "minecraft:bubble_column",
    "minecraft:bubble_coral",
    "minecraft:bubble_coral_fan",
    "minecraft:bubble_coral_wall_fan",
    "minecraft:cactus",
    "minecraft:cake",
    "minecraft:calibrated_sculk_sensor",
    "minecraft:camera",
    "minecraft:campfire",
    "minecraft:candle",
    "minecraft:candle_cake",
    "minecraft:carpet",
    "minecraft:carrots",
    "minecraft:carved_pumpkin",
    "minecraft:cauldron",
    "minecraft:cave_vines",
    "minecraft:cave_vines_body_with_berries",
    "minecraft:cave_vines_head_with_berries",
    "minecraft:chain",
    "minecraft:cherry_button",
    "minecraft:cherry_door",
    "minecraft:cherry_hanging_sign",
    "minecraft:cherry_leaves",
    "minecraft:cherry_pressure_plate",
    "minecraft:cherry_sapling",
    "minecraft:cherry_slab",
    "minecraft:cherry_standing_sign",
    "minecraft:cherry_trapdoor",
    "minecraft:cherry_wall_sign",
    "minecraft:chest",
    "minecraft:chipped_anvil",
    "minecraft:chorus_flower",
    "minecraft:chorus_plant",
    "minecraft:cobbled_deepslate_slab",
    "minecraft:cobbled_deepslate_wall",
    "minecraft:cobblestone_slab",
    "minecraft:cobblestone_wall",
    "minecraft:cocoa",
    "minecraft:conduit",
    "minecraft:copper_bulb",
    "minecraft:copper_door",
    "minecraft:copper_grate",
    "minecraft:copper_trapdoor",
    "minecraft:coral",
    "minecraft:coral_fan",
    "minecraft:coral_fan_dead",
    "minecraft:coral_fan_hang",
    "minecraft:coral_fan_hang2",
    "minecraft:coral_fan_hang3",
    "minecraft:cornflower",
    "minecraft:crimson_button",
    "minecraft:crimson_door",
    "minecraft:crimson_fungus",
    "minecraft:crimson_hanging_sign",
    "minecraft:crimson_leaves",
    "minecraft:crimson_pressure_plate",
    "minecraft:crimson_sapling",
    "minecraft:crimson_roots",
    "minecraft:crimson_slab",
    "minecraft:crimson_standing_sign",
    "minecraft:crimson_trapdoor",
    "minecraft:crimson_wall_sign",
    "minecraft:cut_copper_slab",
    "minecraft:cut_red_sandstone_slab",
    "minecraft:cut_sandstone_slab",
    "minecraft:cyan_candle",
    "minecraft:cyan_candle_cake",
    "minecraft:cyan_carpet",
    "minecraft:cyan_shulker_box",
    "minecraft:cyan_stained_glass_pane",
    "minecraft:damaged_anvil",
    "minecraft:dandelion",
    "minecraft:dark_oak_button",
    "minecraft:dark_oak_door",
    "minecraft:dark_oak_hanging_sign",
    "minecraft:dark_oak_leaves",
    "minecraft:dark_oak_pressure_plate",
    "minecraft:dark_oak_sapling",
    "minecraft:dark_oak_slab",
    "minecraft:dark_oak_trapdoor",
    "minecraft:dark_prismarine_slab",
    "minecraft:darkoak_standing_sign",
    "minecraft:darkoak_wall_sign",
    "minecraft:daylight_detector",
    "minecraft:daylight_detector_inverted",
    "minecraft:dead_brain_coral",
    "minecraft:dead_brain_coral_fan",
    "minecraft:dead_brain_coral_wall_fan",
    "minecraft:dead_bubble_coral",
    "minecraft:dead_bubble_coral_fan",
    "minecraft:dead_bubble_coral_wall_fan",
    "minecraft:dead_fire_coral",
    "minecraft:dead_fire_coral_fan",
    "minecraft:dead_fire_coral_wall_fan",
    "minecraft:dead_horn_coral",
    "minecraft:dead_horn_coral_fan",
    "minecraft:dead_horn_coral_wall_fan",
    "minecraft:dead_tube_coral",
    "minecraft:dead_tube_coral_fan",
    "minecraft:dead_tube_coral_wall_fan",
    "minecraft:deadbush",
    "minecraft:decorated_pot",
    "minecraft:deepslate_brick_slab",
    "minecraft:deepslate_brick_wall",
    "minecraft:deepslate_tile_slab",
    "minecraft:deepslate_tile_wall",
    "minecraft:deprecated_anvil",
    "minecraft:detector_rail",
    "minecraft:diorite_slab",
    "minecraft:double_cut_copper_slab",
    "minecraft:double_plant",
    "minecraft:dragon_egg",
    "minecraft:enchanting_table",
    "minecraft:end_gateway",
    "minecraft:end_portal",
    "minecraft:end_portal_frame",
    "minecraft:end_rod",
    "minecraft:end_stone_brick_slab",
    "minecraft:ender_chest",
    "minecraft:exposed_copper_door",
    "minecraft:exposed_copper_trapdoor",
    "minecraft:exposed_cut_copper_slab",
    "minecraft:fern",
    "minecraft:fire",
    "minecraft:fire_coral",
    "minecraft:fire_coral_fan",
    "minecraft:fire_coral_wall_fan",
    "minecraft:flower_pot",
    "minecraft:flowering_azalea",
    "minecraft:flowing_lava",
    "minecraft:flowing_water",
    "minecraft:frame",
    "minecraft:frog_spawn",
    "minecraft:glass_pane",
    "minecraft:glow_frame",
    "minecraft:glow_lichen",
    "minecraft:golden_rail",
    "minecraft:granite_slab",
    "minecraft:gray_candle",
    "minecraft:gray_candle_cake",
    "minecraft:gray_carpet",
    "minecraft:gray_shulker_box",
    "minecraft:gray_stained_glass_pane",
    "minecraft:green_candle",
    "minecraft:green_candle_cake",
    "minecraft:green_carpet",
    "minecraft:green_shulker_box",
    "minecraft:green_stained_glass_pane",
    "minecraft:grindstone",
    "minecraft:hanging_roots",
    "minecraft:heavy_core",
    "minecraft:heavy_weighted_pressure_plate",
    "minecraft:hopper",
    "minecraft:horn_coral",
    "minecraft:horn_coral_fan",
    "minecraft:horn_coral_wall_fan",
    "minecraft:info_update",
    "minecraft:info_update2",
    "minecraft:invisibleBedrock",
    "minecraft:iron_bars",
    "minecraft:iron_door",
    "minecraft:iron_trapdoor",
    "minecraft:jungle_button",
    "minecraft:jungle_door",
    "minecraft:jungle_hanging_sign",
    "minecraft:jungle_leaves",
    "minecraft:jungle_pressure_plate",
    "minecraft:jungle_sapling",
    "minecraft:jungle_slab",
    "minecraft:jungle_standing_sign",
    "minecraft:jungle_trapdoor",
    "minecraft:jungle_wall_sign",
    "minecraft:kelp",
    "minecraft:ladder",
    "minecraft:lantern",
    "minecraft:large_amethyst_bud",
    "minecraft:large_fern",
    "minecraft:lava",
    "minecraft:lava_cauldron",
    "minecraft:leaves",
    "minecraft:leaves2",
    "minecraft:lectern",
    "minecraft:lever",
    "minecraft:light_block",
    "minecraft:light_block_0",
    "minecraft:light_block_1",
    "minecraft:light_block_10",
    "minecraft:light_block_11",
    "minecraft:light_block_12",
    "minecraft:light_block_13",
    "minecraft:light_block_14",
    "minecraft:light_block_15",
    "minecraft:light_block_2",
    "minecraft:light_block_3",
    "minecraft:light_block_4",
    "minecraft:light_block_5",
    "minecraft:light_block_6",
    "minecraft:light_block_7",
    "minecraft:light_block_8",
    "minecraft:light_block_9",
    "minecraft:light_blue_candle",
    "minecraft:light_blue_candle_cake",
    "minecraft:light_blue_carpet",
    "minecraft:light_blue_shulker_box",
    "minecraft:light_blue_stained_glass_pane",
    "minecraft:light_gray_candle",
    "minecraft:light_gray_candle_cake",
    "minecraft:light_gray_carpet",
    "minecraft:light_gray_shulker_box",
    "minecraft:light_gray_stained_glass_pane",
    "minecraft:light_weighted_pressure_plate",
    "minecraft:lightning_rod",
    "minecraft:lilac",
    "minecraft:lily_of_the_valley",
    "minecraft:lime_candle",
    "minecraft:lime_candle_cake",
    "minecraft:lime_carpet",
    "minecraft:lime_shulker_box",
    "minecraft:lime_stained_glass_pane",
    "minecraft:lit_pumpkin",
    "minecraft:magenta_candle",
    "minecraft:magenta_candle_cake",
    "minecraft:magenta_carpet",
    "minecraft:magenta_shulker_box",
    "minecraft:magenta_stained_glass_pane",
    "minecraft:mangrove_button",
    "minecraft:mangrove_door",
    "minecraft:mangrove_hanging_sign",
    "minecraft:mangrove_leaves",
    "minecraft:mangrove_pressure_plate",
    "minecraft:mangrove_propagule",
    "minecraft:mangrove_sapling",
    "minecraft:mangrove_slab",
    "minecraft:mangrove_standing_sign",
    "minecraft:mangrove_trapdoor",
    "minecraft:mangrove_wall_sign",
    "minecraft:medium_amethyst_bud",
    "minecraft:melon_block",
    "minecraft:melon_stem",
    "minecraft:moss_carpet",
    "minecraft:mossy_cobblestone_slab",
    "minecraft:mossy_stone_brick_slab",
    "minecraft:movingBlock",
    "minecraft:mud_brick_slab",
    "minecraft:mud_brick_wall",
    "minecraft:nether_brick_slab",
    "minecraft:nether_sprouts",
    "minecraft:nether_wart",
    "minecraft:normal_stone_slab",
    "minecraft:oak_button",
    "minecraft:oak_door",
    "minecraft:oak_hanging_sign",
    "minecraft:oak_leaves",
    "minecraft:oak_pressure_plate",
    "minecraft:oak_sapling",
    "minecraft:oak_slab",
    "minecraft:oak_standing_sign",
    "minecraft:oak_trapdoor",
    "minecraft:oak_wall_sign",
    "minecraft:orange_candle",
    "minecraft:orange_candle_cake",
    "minecraft:orange_carpet",
    "minecraft:orange_shulker_box",
    "minecraft:orange_stained_glass_pane",
    "minecraft:orange_tulip",
    "minecraft:oxeye_daisy",
    "minecraft:oxidized_copper_door",
    "minecraft:oxidized_copper_trapdoor",
    "minecraft:oxidized_cut_copper_slab",
    "minecraft:peony",
    "minecraft:petrified_oak_slab",
    "minecraft:pink_candle",
    "minecraft:pink_candle_cake",
    "minecraft:pink_carpet",
    "minecraft:pink_petals",
    "minecraft:pink_shulker_box",
    "minecraft:pink_stained_glass_pane",
    "minecraft:pink_tulip",
    "minecraft:pistonArmCollision",
    "minecraft:pitcher_crop",
    "minecraft:pitcher_plant",
    "minecraft:pointed_dripstone",
    "minecraft:polished_andesite_slab",
    "minecraft:polished_blackstone_brick_slab",
    "minecraft:polished_blackstone_brick_wall",
    "minecraft:polished_blackstone_button",
    "minecraft:polished_blackstone_pressure_plate",
    "minecraft:polished_blackstone_slab",
    "minecraft:polished_blackstone_wall",
    "minecraft:polished_deepslate_slab",
    "minecraft:polished_deepslate_wall",
    "minecraft:polished_diorite_slab",
    "minecraft:polished_granite_slab",
    "minecraft:polished_tuff_slab",
    "minecraft:poppy",
    "minecraft:portal",
    "minecraft:potatoes",
    "minecraft:powder_snow",
    "minecraft:powered_comparator",
    "minecraft:powered_repeater",
    "minecraft:prismarine_brick_slab",
    "minecraft:prismarine_slab",
    "minecraft:pumpkin",
    "minecraft:pumpkin_stem",
    "minecraft:purple_candle",
    "minecraft:purple_candle_cake",
    "minecraft:purple_carpet",
    "minecraft:purple_shulker_box",
    "minecraft:purple_stained_glass_pane",
    "minecraft:purpur_slab",
    "minecraft:quartz_slab",
    "minecraft:rail",
    "minecraft:red_candle",
    "minecraft:red_candle_cake",
    "minecraft:red_carpet",
    "minecraft:red_flower",
    "minecraft:red_mushroom",
    "minecraft:red_nether_brick_slab",
    "minecraft:red_sandstone_slab",
    "minecraft:red_shulker_box",
    "minecraft:red_stained_glass_pane",
    "minecraft:red_tulip",
    "minecraft:redstone_torch",
    "minecraft:redstone_wire",
    "minecraft:reeds",
    "minecraft:reserved6",
    "minecraft:rose_bush",
    "minecraft:sandstone_slab",
    "minecraft:sapling",
    "minecraft:scaffolding",
    "minecraft:sculk",
    "minecraft:sculk_sensor",
    "minecraft:sculk_shrieker",
    "minecraft:sculk_vein",
    "minecraft:sea_pickle",
    "minecraft:seagrass",
    "minecraft:short_grass",
    "minecraft:shulker_box",
    "minecraft:skull",
    "minecraft:small_amethyst_bud",
    "minecraft:small_dripleaf_block",
    "minecraft:smooth_quartz_slab",
    "minecraft:smooth_red_sandstone_slab",
    "minecraft:smooth_sandstone_slab",
    "minecraft:smooth_stone_slab",
    "minecraft:sniffer_egg",
    "minecraft:snow_layer",
    "minecraft:soul_campfire",
    "minecraft:soul_fire",
    "minecraft:soul_lantern",
    "minecraft:soul_torch",
    "minecraft:spore_blossom",
    "minecraft:spruce_button",
    "minecraft:spruce_door",
    "minecraft:spruce_hanging_sign",
    "minecraft:spruce_leaves",
    "minecraft:spruce_pressure_plate",
    "minecraft:spruce_sapling",
    "minecraft:spruce_slab",
    "minecraft:spruce_standing_sign",
    "minecraft:spruce_trapdoor",
    "minecraft:spruce_wall_sign",
    "minecraft:stained_glass_pane",
    "minecraft:standing_banner",
    "minecraft:standing_sign",
    "minecraft:stickyPistonArmCollision",
    "minecraft:stone_brick_slab",
    "minecraft:stone_button",
    "minecraft:stone_pressure_plate",
    "minecraft:stone_slab",
    "minecraft:stone_slab2",
    "minecraft:stone_slab3",
    "minecraft:stone_slab4",
    "minecraft:stonecutter",
    "minecraft:stonecutter_block",
    "minecraft:structure_void",
    "minecraft:sunflower",
    "minecraft:sweet_berry_bush",
    "minecraft:tall_grass",
    "minecraft:tallgrass",
    "minecraft:torch",
    "minecraft:torchflower",
    "minecraft:torchflower_crop",
    "minecraft:trapdoor",
    "minecraft:trapped_chest",
    "minecraft:tripWire",
    "minecraft:tripwire_hook",
    "minecraft:tube_coral",
    "minecraft:tube_coral_fan",
    "minecraft:tube_coral_wall_fan",
    "minecraft:tuff_brick_slab",
    "minecraft:tuff_brick_wall",
    "minecraft:tuff_slab",
    "minecraft:tuff_wall",
    "minecraft:turtle_egg",
    "minecraft:twisting_vines",
    "minecraft:undyed_shulker_box",
    "minecraft:unlit_redstone_torch",
    "minecraft:unpowered_comparator",
    "minecraft:unpowered_repeater",
    "minecraft:vault",
    "minecraft:vine",
    "minecraft:wall_banner",
    "minecraft:wall_sign",
    "minecraft:warped_button",
    "minecraft:warped_door",
    "minecraft:warped_fungus",
    "minecraft:warped_hanging_sign",
    "minecraft:warped_leaves",
    "minecraft:warped_pressure_plate",
    "minecraft:warped_sapling",
    "minecraft:warped_roots",
    "minecraft:warped_slab",
    "minecraft:warped_standing_sign",
    "minecraft:warped_trapdoor",
    "minecraft:warped_wall_sign",
    "minecraft:water",
    "minecraft:waterlily",
    "minecraft:waxed_copper_door",
    "minecraft:waxed_copper_trapdoor",
    "minecraft:waxed_cut_copper_slab",
    "minecraft:waxed_exposed_copper_door",
    "minecraft:waxed_exposed_copper_trapdoor",
    "minecraft:waxed_exposed_cut_copper_slab",
    "minecraft:waxed_oxidizedcopper_door",
    "minecraft:waxed_oxidizedcopper_trapdoor",
    "minecraft:waxed_oxidizedcut_copper_slab",
    "minecraft:waxed_weathered_copper_door",
    "minecraft:waxed_weathered_copper_trapdoor",
    "minecraft:waxed_weathered_cut_copper_slab",
    "minecraft:web",
    "minecraft:weeping_vines",
    "minecraft:wheat",
    "minecraft:white_candle",
    "minecraft:white_candle_cake",
    "minecraft:white_carpet",
    "minecraft:white_shulker_box",
    "minecraft:white_stained_glass_pane",
    "minecraft:white_tulip",
    "minecraft:wither_rose",
    "minecraft:wooden_button",
    "minecraft:wooden_door",
    "minecraft:wooden_pressure_plate",
    "minecraft:wooden_slab",
    "minecraft:yellow_candle",
    "minecraft:yellow_candle_cake",
    "minecraft:yellow_carpet",
    "minecraft:yellow_flower",
    "minecraft:yellow_shulker_box",
    "minecraft:yellow_stained_glass_pane"
];
export class FenceManager {
    static onPlaceFence(data) {
        data.permutationToPlace = data.permutationToPlace.withState(`${prefix}:display`, false);
    }
    static updateFenceStates(Fence) {
        let north = undefined;
        try {
            north = Fence.north(1);
        }
        catch { }
        let south = undefined;
        try {
            south = Fence.south(1);
        }
        catch { }
        let east = undefined;
        try {
            east = Fence.east(1);
        }
        catch { }
        let west = undefined;
        try {
            west = Fence.west(1);
        }
        catch { }
        const blocks = [
            { block: north, side: "north" },
            { block: south, side: "south" },
            { block: east, side: "east" },
            { block: west, side: "west" },
        ];
        for (const blockData of blocks) {
            if (blockData.block != undefined) {
                if (!(blockData.block.isLiquid || blockData.block.isAir) && !bannedBlocks.includes(blockData.block.typeId)) {
                    Fence.setPermutation(Fence.permutation.withState(`${prefix}:connect_` + blockData.side, true));
                }
                else {
                    Fence.setPermutation(Fence.permutation.withState(`${prefix}:connect_` + blockData.side, false));
                }
            }
            else {
                Fence.setPermutation(Fence.permutation.withState(`${prefix}:connect_` + blockData.side, false));
            }
        }
    }
    static updateFencesAround(Block) {
        let north = undefined;
        try {
            north = Block.north(1);
        }
        catch { }
        let south = undefined;
        try {
            south = Block.south(1);
        }
        catch { }
        let east = undefined;
        try {
            east = Block.east(1);
        }
        catch { }
        let west = undefined;
        try {
            west = Block.west(1);
        }
        catch { }
        const blocks = [Block, north, south, east, west];
        for (const block of blocks) {
            if (block != undefined) {
                if (block.hasTag(FenceTag))
                    this.updateFenceStates(block);
            }
        }
    }
}
