import { world } from "@minecraft/server";
import 'use_items'
import 'head'
import 'use_tools'
import 'on_destroy_blocks'
import 'on_place_blocks'
import 'on_random_tick_blocks'

import 'on_step_blocks'

import 'on_interact_blocks'

import './falling_block/startFalling.js'
import { fence_Manager } from 'fences/fence_Manager'
import 'custom_block_and_tool_integrated_durability'
import 'play_custom_music'
import 'stop_custom_music'

import { IronGolemStructureSpawner, SnowGolemStructureSpawner } from "./golemStructureSpawner.js"

const soulironGolem = new IronGolemStructureSpawner('old_nether:soul_pumpkin', 'minecraft:iron_block', 'old_nether:soul_iron_golem_by_player')
const soulsnowGolem = new SnowGolemStructureSpawner('old_nether:soul_pumpkin', 'minecraft:snow', 'old_nether:soul_snow_golem')

world.afterEvents.playerBreakBlock.subscribe((data) => {
    fence_Manager.updateFencesAround(data.block)
})

world.afterEvents.playerPlaceBlock.subscribe((data) => {
    fence_Manager.updateFencesAround(data.block)
})

import { StructureDetector } from "./structureDetector.js";

//Nether Champion
const netherchampion = new StructureDetector(
    {
        "*": undefined,
        "a": "minecraft:air",
        "s": "minecraft:soul_sand",
        "b": "minecraft:beacon",
        "w": "old_nether:wither_skeleton_brute_skull" // the block that tigger the check.
    },
    [
        ["asa"],
        ["sbs"],
        ["awa"]
    ],
    (dimension, pos) => {
        const entity = dimension.spawnEntity("old_nether:nether_king_shape1", pos);
    }
);

import { NetherspireDetector } from "./netherspireDetector.js";

//Netherrack Reactor Core Pattern
const netherrackreactorcore = new NetherspireDetector(
    {
        "*": undefined,
        "a": "minecraft:air",
        "g": "minecraft:gold_block",
        "c": "minecraft:cobblestone",
        "r": "old_nether:reactor1"
    },
    [
        [
            "gcg",
            "ccc",
            "gcg",
        ],
        [
            "cac",
            "ara",
            "cac",
        ],
        [
            "aca",
            "ccc",
            "aca",
        ]
    ],
    (dimension, pos) => {
        const entity = dimension.spawnEntity("old_nether:netherrack_spire_spawn", pos);
    }
);
//Bloodstone Reactor Core Pattern
const bloodstonereactorcore = new NetherspireDetector(
    {
        "*": undefined,
        "a": "minecraft:air",
        "g": "minecraft:gold_block",
        "c": "minecraft:cobblestone",
        "r": "old_nether:reactor1_ruby"
    },
    [
        [
            "gcg",
            "ccc",
            "gcg",
        ],
        [
            "cac",
            "ara",
            "cac",
        ],
        [
            "aca",
            "ccc",
            "aca",
        ]
    ],
    (dimension, pos) => {
        const entity = dimension.spawnEntity("old_nether:bloodstone_spire_spawn", pos);
    }
);
//Obsidian Reactor Core Pattern
const obsidianreactorcore = new NetherspireDetector(
    {
        "*": undefined,
        "a": "minecraft:air",
        "g": "minecraft:gold_block",
        "i": "minecraft:iron_block",
        "r": "old_nether:reactor1_obsidian"
    },
    [
        [
            "gig",
            "iii",
            "gig",
        ],
        [
            "iai",
            "ara",
            "iai",
        ],
        [
            "aia",
            "iii",
            "aia",
        ]
    ],
    (dimension, pos) => {
        const entity = dimension.spawnEntity("old_nether:obsidian_spire_spawn", pos);
    }
);
//Obsidian Reactor Core Pattern
const volcanicrockreactorcore = new NetherspireDetector(
    {
        "*": undefined,
        "a": "minecraft:air",
        "g": "minecraft:gold_block",
        "i": "minecraft:iron_block",
        "r": "old_nether:reactor1_obsidian_ruby"
    },
    [
        [
            "gig",
            "iii",
            "gig",
        ],
        [
            "iai",
            "ara",
            "iai",
        ],
        [
            "aia",
            "iii",
            "aia",
        ]
    ],
    (dimension, pos) => {
        const entity = dimension.spawnEntity("old_nether:volcanic_rock_spire_spawn", pos);
    }
);
//Infernal Reactor Core Pattern
const infernalreactorcore = new NetherspireDetector(
    {
        "*": undefined,
        "a": "minecraft:air",
        "g": "minecraft:gold_block",
        "b": "old_nether:bloodstone_bricks",
        "c": "old_nether:chiseled_bloodstone_bricks",
        "r": "old_nether:reactor1_inferno"
    },
    [
        [
            "gbg",
            "bbb",
            "gbg",
        ],
        [
            "cac",
            "ara",
            "cac",
        ],
        [
            "aba",
            "bbb",
            "aba",
        ]
    ],
    (dimension, pos) => {
        const entity = dimension.spawnEntity("old_nether:inferno_spire_spawn", pos);
    }
);

world.afterEvents.playerPlaceBlock.subscribe(({ block, dimension }) => {
    netherchampion.detectStructure(dimension, block);
    netherrackreactorcore.detectStructure(dimension, block);
    bloodstonereactorcore.detectStructure(dimension, block);
    obsidianreactorcore.detectStructure(dimension, block);
    volcanicrockreactorcore.detectStructure(dimension, block);
    infernalreactorcore.detectStructure(dimension, block);
});