// scripts/main.ts
import { Direction as Direction9, system as system13, world as world5 } from "@minecraft/server";

// scripts/utils/blockHelper.ts
import {
  Direction,
  EntityComponentTypes as EntityComponentTypes2,
  GameMode as GameMode2,
  ItemStack as ItemStack2,
  system as system2,
  world
} from "@minecraft/server";

// scripts/utils/entityHelper.ts
import {
  EntityComponentTypes,
  GameMode,
  system
} from "@minecraft/server";

// scripts/utils/commandHelper.ts
function generateSetBlockCommand(location, setAs = "minecraft:air" /* Air */, breakMethod = "destroy") {
  const { x, y, z } = location;
  return `setblock ${x} ${y} ${z} ${setAs} ${breakMethod}`;
}
function generateClearCommand(itemTypeId, maxCount = 1, target = "@s", data = 0) {
  return `clear ${target} ${itemTypeId} ${data} ${maxCount}`;
}

// scripts/utils/entityHelper.ts
function giveItem(itemStack, entity) {
  const inventory = entity.getComponent(EntityComponentTypes.Inventory);
  const container = inventory?.container;
  if (!container || !inventory)
    return;
  container.addItem(itemStack);
}
function summon(dimension, entityId, location, spawnEvent) {
  try {
    return dimension.spawnEntity(entityId + (spawnEvent ? "<" + spawnEvent + ">" : ""), location);
  } catch {
    return void 0;
  }
}
function clearPlayerItem(source, equipmentSlot = null, amount = 1, itemStackId = null, checkGameMode = true) {
  if (checkGameMode && source.getGameMode() == GameMode.creative)
    return;
  if (!equipmentSlot && itemStackId) {
    const command = generateClearCommand(itemStackId);
    source.runCommand(command);
    return;
  }
  if (!equipmentSlot)
    return;
  const equippable = source.getComponent(EntityComponentTypes.Equippable);
  const itemStack = equippable.getEquipment(equipmentSlot);
  if (!itemStack)
    return;
  system.run(() => {
    if (itemStack.amount <= amount)
      equippable.setEquipment(equipmentSlot);
    else {
      itemStack.amount -= amount;
      equippable.setEquipment(equipmentSlot, itemStack);
    }
  });
}
function getEntityName(typeid) {
  return typeid.replace(/^piki_ghosts:ghost_/, "").replace(/_\d+/g, "").replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
}

// scripts/utils/blockGroups.ts
var SINGLE_SLABS = /* @__PURE__ */ new Set([
  "minecraft:bamboo_mosaic_slab",
  "minecraft:dark_prismarine_slab",
  "minecraft:brick_slab",
  "minecraft:polished_tuff_slab",
  "minecraft:deepslate_tile_slab",
  "minecraft:waxed_oxidized_cut_copper_slab",
  "minecraft:cobblestone_slab",
  "minecraft:dark_oak_slab",
  "minecraft:diorite_slab",
  "minecraft:red_sandstone_slab",
  "minecraft:smooth_sandstone_slab",
  "minecraft:quartz_slab",
  "minecraft:waxed_exposed_cut_copper_slab",
  "minecraft:purpur_slab",
  "minecraft:tuff_slab",
  "minecraft:polished_deepslate_slab",
  "minecraft:sandstone_slab",
  "minecraft:mossy_stone_brick_slab",
  "minecraft:cut_sandstone_slab",
  "minecraft:blackstone_slab",
  "minecraft:nether_brick_slab",
  "minecraft:end_stone_brick_slab",
  "minecraft:polished_granite_slab",
  "minecraft:oxidized_cut_copper_slab",
  "minecraft:acacia_slab",
  "minecraft:polished_andesite_slab",
  "minecraft:deepslate_brick_slab",
  "minecraft:mossy_cobblestone_slab",
  "minecraft:mangrove_slab",
  "minecraft:exposed_cut_copper_slab",
  "minecraft:tuff_brick_slab",
  "minecraft:prismarine_brick_slab",
  "minecraft:birch_slab",
  "minecraft:jungle_slab",
  "minecraft:mud_brick_slab",
  "minecraft:polished_blackstone_brick_slab",
  "minecraft:normal_stone_slab",
  "minecraft:oak_slab",
  "minecraft:smooth_stone_slab",
  "minecraft:pale_oak_slab",
  "minecraft:prismarine_slab",
  "minecraft:granite_slab",
  "minecraft:waxed_weathered_cut_copper_slab",
  "minecraft:polished_diorite_slab",
  "minecraft:bamboo_slab",
  "minecraft:red_nether_brick_slab",
  "minecraft:smooth_red_sandstone_slab",
  "minecraft:cut_copper_slab",
  "minecraft:cobbled_deepslate_slab",
  "minecraft:crimson_slab",
  "minecraft:polished_blackstone_slab",
  "minecraft:weathered_cut_copper_slab",
  "minecraft:cherry_slab",
  "minecraft:stone_brick_slab",
  "minecraft:andesite_slab",
  "minecraft:warped_slab",
  "minecraft:spruce_slab",
  "minecraft:resin_brick_slab",
  "minecraft:petrified_oak_slab",
  "minecraft:cut_red_sandstone_slab",
  "minecraft:smooth_quartz_slab",
  "minecraft:waxed_cut_copper_slab"
]);
var PISTON_ARMS = /* @__PURE__ */ new Set([
  "minecraft:piston_arm_collision",
  "minecraft:sticky_piston_arm_collision"
]);
var TORCHES = /* @__PURE__ */ new Set([
  "minecraft:soul_torch",
  "minecraft:unlit_redstone_torch",
  "minecraft:underwater_torch",
  "minecraft:torch",
  "minecraft:colored_torch_red",
  "minecraft:redstone_torch",
  "minecraft:colored_torch_blue",
  "minecraft:colored_torch_purple",
  "minecraft:colored_torch_green"
]);
var VANILLA_CROPS = /* @__PURE__ */ new Set([
  "minecraft:wheat",
  "minecraft:carrots",
  "minecraft:potatoes",
  "minecraft:beetroot",
  "minecraft:pumpkin_stem",
  "minecraft:melon_stem",
  "minecraft:torchflower_crop"
]);
var VANILLA_WALLS = /* @__PURE__ */ new Set([
  "minecraft:tuff_brick_wall",
  "minecraft:diorite_wall",
  "minecraft:end_stone_brick_wall",
  "minecraft:polished_blackstone_brick_wall",
  "minecraft:brick_wall",
  "minecraft:red_sandstone_wall",
  "minecraft:red_nether_brick_wall",
  "minecraft:deepslate_brick_wall",
  "minecraft:polished_tuff_wall",
  "minecraft:mud_brick_wall",
  "minecraft:mossy_cobblestone_wall",
  "minecraft:cobblestone_wall",
  "minecraft:tuff_wall",
  "minecraft:blackstone_wall",
  "minecraft:polished_blackstone_wall",
  "minecraft:sandstone_wall",
  "minecraft:nether_brick_wall",
  "minecraft:prismarine_wall",
  "minecraft:deepslate_tile_wall",
  "minecraft:stone_brick_wall",
  "minecraft:andesite_wall",
  "minecraft:granite_wall",
  "minecraft:cobbled_deepslate_wall",
  "minecraft:polished_deepslate_wall",
  "minecraft:resin_brick_wall",
  "minecraft:mossy_stone_brick_wall"
]);
var VANILLA_STAIRS = /* @__PURE__ */ new Set([
  "minecraft:waxed_cut_copper_stairs",
  "minecraft:oxidized_cut_copper_stairs",
  "minecraft:polished_granite_stairs",
  "minecraft:prismarine_bricks_stairs",
  "minecraft:cut_copper_stairs",
  "minecraft:stone_brick_stairs",
  "minecraft:nether_brick_stairs",
  "minecraft:cobbled_deepslate_stairs",
  "minecraft:resin_brick_stairs",
  "minecraft:spruce_stairs",
  "minecraft:polished_blackstone_brick_stairs",
  "minecraft:stone_stairs",
  "minecraft:dark_prismarine_stairs",
  "minecraft:bamboo_mosaic_stairs",
  "minecraft:granite_stairs",
  "minecraft:cherry_stairs",
  "minecraft:oak_stairs",
  "minecraft:crimson_stairs",
  "minecraft:polished_deepslate_stairs",
  "minecraft:end_brick_stairs",
  "minecraft:andesite_stairs",
  "minecraft:normal_stone_stairs",
  "minecraft:waxed_oxidized_cut_copper_stairs",
  "minecraft:bamboo_stairs",
  "minecraft:polished_blackstone_stairs",
  "minecraft:sandstone_stairs",
  "minecraft:smooth_sandstone_stairs",
  "minecraft:warped_stairs",
  "minecraft:waxed_exposed_cut_copper_stairs",
  "minecraft:mossy_cobblestone_stairs",
  "minecraft:jungle_stairs",
  "minecraft:weathered_cut_copper_stairs",
  "minecraft:deepslate_tile_stairs",
  "minecraft:diorite_stairs",
  "minecraft:prismarine_stairs",
  "minecraft:exposed_cut_copper_stairs",
  "minecraft:mangrove_stairs",
  "minecraft:red_sandstone_stairs",
  "minecraft:quartz_stairs",
  "minecraft:dark_oak_stairs",
  "minecraft:mud_brick_stairs",
  "minecraft:smooth_red_sandstone_stairs",
  "minecraft:mossy_stone_brick_stairs",
  "minecraft:tuff_stairs",
  "minecraft:waxed_weathered_cut_copper_stairs",
  "minecraft:acacia_stairs",
  "minecraft:polished_andesite_stairs",
  "minecraft:tuff_brick_stairs",
  "minecraft:deepslate_brick_stairs",
  "minecraft:pale_oak_stairs",
  "minecraft:brick_stairs",
  "minecraft:red_nether_brick_stairs",
  "minecraft:polished_diorite_stairs",
  "minecraft:birch_stairs",
  "minecraft:blackstone_stairs",
  "minecraft:polished_tuff_stairs",
  "minecraft:smooth_quartz_stairs",
  "minecraft:purpur_stairs"
]);
var VANILLA_TRAPDOOR = /* @__PURE__ */ new Set([
  "minecraft:trapdoor",
  "minecraft:waxed_copper_trapdoor",
  "minecraft:exposed_copper_trapdoor",
  "minecraft:iron_trapdoor",
  "minecraft:oxidized_copper_trapdoor",
  "minecraft:cherry_trapdoor",
  "minecraft:weathered_copper_trapdoor",
  "minecraft:acacia_trapdoor",
  "minecraft:crimson_trapdoor",
  "minecraft:waxed_weathered_copper_trapdoor",
  "minecraft:mangrove_trapdoor",
  "minecraft:copper_trapdoor",
  "minecraft:warped_trapdoor",
  "minecraft:waxed_oxidized_copper_trapdoor",
  "minecraft:bamboo_trapdoor",
  "minecraft:jungle_trapdoor",
  "minecraft:waxed_exposed_copper_trapdoor",
  "minecraft:spruce_trapdoor",
  "minecraft:birch_trapdoor",
  "minecraft:pale_oak_trapdoor",
  "minecraft:dark_oak_trapdoor"
]);
var VANILLA_DOORS = /* @__PURE__ */ new Set([
  "minecraft:warped_door",
  "minecraft:wooden_door",
  "minecraft:jungle_door",
  "minecraft:dark_oak_door",
  "minecraft:bamboo_door",
  "minecraft:pale_oak_door",
  "minecraft:oxidized_copper_door",
  "minecraft:crimson_door",
  "minecraft:waxed_weathered_copper_door",
  "minecraft:spruce_door",
  "minecraft:acacia_door",
  "minecraft:cherry_door",
  "minecraft:mangrove_door",
  "minecraft:copper_door",
  "minecraft:iron_door",
  "minecraft:exposed_copper_door",
  "minecraft:waxed_exposed_copper_door",
  "minecraft:waxed_oxidized_copper_door",
  "minecraft:weathered_copper_door",
  "minecraft:birch_door",
  "minecraft:waxed_copper_door"
]);
var VANILLA_FENCEGATES = /* @__PURE__ */ new Set([
  "minecraft:fence_gate",
  "minecraft:pale_oak_fence_gate",
  "minecraft:acacia_fence_gate",
  "minecraft:birch_fence_gate",
  "minecraft:dark_oak_fence_gate",
  "minecraft:bamboo_fence_gate",
  "minecraft:mangrove_fence_gate",
  "minecraft:crimson_fence_gate",
  "minecraft:jungle_fence_gate",
  "minecraft:warped_fence_gate",
  "minecraft:spruce_fence_gate",
  "minecraft:cherry_fence_gate"
]);
var VANILLA_PISTONS = /* @__PURE__ */ new Set(["minecraft:piston" /* Piston */, "minecraft:sticky_piston" /* StickyPiston */]);
var VANILLA_FENCES = /* @__PURE__ */ new Set([
  "minecraft:bamboo_fence",
  "minecraft:oak_fence",
  "minecraft:jungle_fence",
  "minecraft:pale_oak_fence",
  "minecraft:spruce_fence",
  "minecraft:cherry_fence",
  "minecraft:nether_brick_fence",
  "minecraft:warped_fence",
  "minecraft:mangrove_fence",
  "minecraft:dark_oak_fence",
  "minecraft:crimson_fence",
  "minecraft:birch_fence",
  "minecraft:acacia_fence"
]);
var VANILLA_PRESSURE_PLATES = /* @__PURE__ */ new Set([
  "minecraft:bamboo_pressure_plate",
  "minecraft:spruce_pressure_plate",
  "minecraft:cherry_pressure_plate",
  "minecraft:warped_pressure_plate",
  "minecraft:pale_oak_pressure_plate",
  "minecraft:polished_blackstone_pressure_plate",
  "minecraft:heavy_weighted_pressure_plate",
  "minecraft:mangrove_pressure_plate",
  "minecraft:birch_pressure_plate",
  "minecraft:jungle_pressure_plate",
  "minecraft:light_weighted_pressure_plate",
  "minecraft:stone_pressure_plate",
  "minecraft:acacia_pressure_plate",
  "minecraft:crimson_pressure_plate",
  "minecraft:dark_oak_pressure_plate",
  "minecraft:wooden_pressure_plate"
]);
var VANILLA_BUTTONS = /* @__PURE__ */ new Set([
  "minecraft:dark_oak_button",
  "minecraft:jungle_button",
  "minecraft:polished_blackstone_button",
  "minecraft:mangrove_button",
  "minecraft:stone_button",
  "minecraft:spruce_button",
  "minecraft:birch_button",
  "minecraft:cherry_button",
  "minecraft:crimson_button",
  "minecraft:bamboo_button",
  "minecraft:wooden_button",
  "minecraft:acacia_button",
  "minecraft:warped_button",
  "minecraft:pale_oak_button"
]);
var VANILLA_CARPETS = /* @__PURE__ */ new Set([
  "minecraft:blue_carpet",
  "minecraft:cyan_carpet",
  "minecraft:pale_moss_carpet",
  "minecraft:white_carpet",
  "minecraft:gray_carpet",
  "minecraft:magenta_carpet",
  "minecraft:moss_carpet",
  "minecraft:pink_carpet",
  "minecraft:brown_carpet",
  "minecraft:orange_carpet",
  "minecraft:green_carpet",
  "minecraft:black_carpet",
  "minecraft:light_blue_carpet",
  "minecraft:yellow_carpet",
  "minecraft:purple_carpet",
  "minecraft:lime_carpet",
  "minecraft:red_carpet",
  "minecraft:light_gray_carpet"
]);
var VANILLA_HEADS = /* @__PURE__ */ new Set([
  "minecraft:zombie_head",
  "minecraft:creeper_head",
  "minecraft:player_head",
  "minecraft:dragon_head",
  "minecraft:piglin_head",
  "minecraft:wither_skeleton_skull",
  "minecraft:skeleton_skull"
]);
var VANILLA_SHULKER_BOXES = /* @__PURE__ */ new Set([
  "minecraft:yellow_shulker_box",
  "minecraft:lime_shulker_box",
  "minecraft:undyed_shulker_box",
  "minecraft:magenta_shulker_box",
  "minecraft:white_shulker_box",
  "minecraft:purple_shulker_box",
  "minecraft:orange_shulker_box",
  "minecraft:blue_shulker_box",
  "minecraft:brown_shulker_box",
  "minecraft:pink_shulker_box",
  "minecraft:red_shulker_box",
  "minecraft:gray_shulker_box",
  "minecraft:light_gray_shulker_box",
  "minecraft:black_shulker_box",
  "minecraft:cyan_shulker_box",
  "minecraft:green_shulker_box",
  "minecraft:light_blue_shulker_box"
]);
var VANILLA_CAKES = /* @__PURE__ */ new Set([
  "minecraft:yellow_candle_cake",
  "minecraft:gray_candle_cake",
  "minecraft:red_candle_cake",
  "minecraft:black_candle_cake",
  "minecraft:green_candle_cake",
  "minecraft:light_blue_candle_cake",
  "minecraft:cyan_candle_cake",
  "minecraft:lime_candle_cake",
  "minecraft:brown_candle_cake",
  "minecraft:pink_candle_cake",
  "minecraft:purple_candle_cake",
  "minecraft:light_gray_candle_cake",
  "minecraft:blue_candle_cake",
  "minecraft:magenta_candle_cake",
  "minecraft:white_candle_cake",
  "minecraft:orange_candle_cake",
  "minecraft:cake"
]);
var VANILLA_HANGING_SIGNS = /* @__PURE__ */ new Set([
  "minecraft:cherry_hanging_sign",
  "minecraft:pale_oak_hanging_sign",
  "minecraft:dark_oak_hanging_sign",
  "minecraft:warped_hanging_sign",
  "minecraft:birch_hanging_sign",
  "minecraft:acacia_hanging_sign",
  "minecraft:jungle_hanging_sign",
  "minecraft:bamboo_hanging_sign",
  "minecraft:oak_hanging_sign",
  "minecraft:spruce_hanging_sign",
  "minecraft:mangrove_hanging_sign",
  "minecraft:crimson_hanging_sign"
]);
var VANILLA_STANDING_SIGN = /* @__PURE__ */ new Set([
  "minecraft:birch_standing_sign",
  "minecraft:spruce_standing_sign",
  "minecraft:acacia_standing_sign",
  "minecraft:darkoak_standing_sign",
  "minecraft:mangrove_standing_sign",
  "minecraft:warped_standing_sign",
  "minecraft:cherry_standing_sign",
  "minecraft:jungle_standing_sign",
  "minecraft:pale_oak_standing_sign",
  "minecraft:bamboo_standing_sign",
  "minecraft:crimson_standing_sign"
]);
var VANILLA_LIGHTS = /* @__PURE__ */ new Set([
  "minecraft:light_block_1",
  "minecraft:light_block_14",
  "minecraft:light_block_8",
  "minecraft:light_block_9",
  "minecraft:light_block_7",
  "minecraft:light_block_6",
  "minecraft:light_block_5",
  "minecraft:light_block_4",
  "minecraft:light_block_3",
  "minecraft:light_block_2",
  "minecraft:light_block_0",
  "minecraft:light_block_13",
  "minecraft:light_block_10",
  "minecraft:light_block_12",
  "minecraft:light_block_11",
  "minecraft:light_block_15"
]);
var VANILLA_CORAL_WALL_FANS = /* @__PURE__ */ new Set([
  "minecraft:dead_bubble_coral_wall_fan",
  "minecraft:dead_horn_coral_wall_fan",
  "minecraft:dead_fire_coral_wall_fan",
  "minecraft:tube_coral_wall_fan",
  "minecraft:dead_brain_coral_wall_fan",
  "minecraft:brain_coral_wall_fan",
  "minecraft:horn_coral_wall_fan",
  "minecraft:fire_coral_wall_fan",
  "minecraft:bubble_coral_wall_fan",
  "minecraft:dead_tube_coral_wall_fan"
]);
var VANILLA_WALL_SIGNS = /* @__PURE__ */ new Set([
  "minecraft:wall_sign",
  "minecraft:acacia_wall_sign",
  "minecraft:warped_wall_sign",
  "minecraft:darkoak_wall_sign",
  "minecraft:crimson_wall_sign",
  "minecraft:pale_oak_wall_sign",
  "minecraft:jungle_wall_sign",
  "minecraft:mangrove_wall_sign",
  "minecraft:spruce_wall_sign",
  "minecraft:birch_wall_sign",
  "minecraft:bamboo_wall_sign",
  "minecraft:cherry_wall_sign"
]);
var VANILLA_CANDLES = /* @__PURE__ */ new Set([
  "minecraft:light_gray_candle",
  "minecraft:blue_candle",
  "minecraft:magenta_candle",
  "minecraft:black_candle",
  "minecraft:gray_candle",
  "minecraft:orange_candle",
  "minecraft:cyan_candle",
  "minecraft:green_candle",
  "minecraft:pink_candle",
  "minecraft:brown_candle",
  "minecraft:purple_candle",
  "minecraft:light_blue_candle",
  "minecraft:red_candle",
  "minecraft:yellow_candle",
  "minecraft:white_candle",
  "minecraft:lime_candle"
]);
var VANILLA_SAPLINGS = /* @__PURE__ */ new Set([
  "minecraft:spruce_sapling",
  "minecraft:dark_oak_sapling",
  "minecraft:pale_oak_sapling",
  "minecraft:oak_sapling",
  "minecraft:jungle_sapling",
  "minecraft:acacia_sapling",
  "minecraft:cherry_sapling",
  "minecraft:birch_sapling",
  "minecraft:bamboo_sapling"
]);
var VANILLA_LEAVES = /* @__PURE__ */ new Set([
  "minecraft:azalea_leaves_flowered",
  "minecraft:pale_oak_leaves",
  "minecraft:mangrove_leaves",
  "minecraft:acacia_leaves",
  "minecraft:oak_leaves",
  "minecraft:jungle_leaves",
  "minecraft:birch_leaves",
  "minecraft:azalea_leaves",
  "minecraft:spruce_leaves",
  "minecraft:cherry_leaves",
  "minecraft:dark_oak_leaves"
]);
var VANILLA_CORAL_FANS = /* @__PURE__ */ new Set([
  "minecraft:dead_bubble_coral_fan",
  "minecraft:bubble_coral_fan",
  "minecraft:dead_brain_coral_fan",
  "minecraft:tube_coral_fan",
  "minecraft:brain_coral_fan",
  "minecraft:dead_horn_coral_fan",
  "minecraft:horn_coral_fan",
  "minecraft:fire_coral_fan",
  "minecraft:dead_tube_coral_fan",
  "minecraft:dead_fire_coral_fan"
]);
var NO_PICKET_CONNECTION = /* @__PURE__ */ new Set([
  "minecraft:pink_tulip",
  "minecraft:detector_rail",
  "minecraft:melon_block",
  "minecraft:cornflower",
  "minecraft:vine",
  "minecraft:white_tulip",
  "minecraft:open_eyeblossom",
  "minecraft:brown_mushroom",
  "minecraft:powder_snow",
  "minecraft:ladder",
  "minecraft:powered_repeater",
  "minecraft:hanging_roots",
  "minecraft:end_gateway",
  "minecraft:azure_bluet",
  "minecraft:snow_layer",
  "minecraft:cactus",
  "minecraft:glow_frame",
  "minecraft:sculk_shrieker",
  "minecraft:nether_wart",
  "minecraft:wheat",
  "minecraft:grindstone",
  "minecraft:lily_of_the_valley",
  "minecraft:blue_orchid",
  "minecraft:seagrass",
  "minecraft:big_dripleaf",
  "minecraft:dead_horn_coral",
  "minecraft:cake",
  "minecraft:pitcher_crop",
  "minecraft:ender_chest",
  "minecraft:redstone_wire",
  "minecraft:sculk_vein",
  "minecraft:fern",
  "minecraft:poppy",
  "minecraft:warped_fungus",
  "minecraft:melon_stem",
  "minecraft:flower_pot",
  "minecraft:short_grass",
  "minecraft:small_amethyst_bud",
  "minecraft:activator_rail",
  "minecraft:large_amethyst_bud",
  "minecraft:potatoes",
  "minecraft:soul_torch",
  "minecraft:allium",
  "minecraft:lava",
  "minecraft:scaffolding",
  "minecraft:powered_comparator",
  "minecraft:chalkboard",
  "minecraft:pink_petals",
  "minecraft:soul_fire",
  "minecraft:brain_coral",
  "minecraft:chest",
  "minecraft:cauldron",
  "minecraft:pitcher_plant",
  "minecraft:frame",
  "minecraft:unlit_redstone_torch",
  "minecraft:warped_roots",
  "minecraft:small_dripleaf_block",
  "minecraft:barrier",
  "minecraft:unpowered_repeater",
  "minecraft:fire_coral",
  "minecraft:kelp",
  "minecraft:underwater_torch",
  "minecraft:sea_pickle",
  "minecraft:heavy_core",
  "minecraft:flowering_azalea",
  "minecraft:resin_clump",
  "minecraft:torch",
  "minecraft:lit_pumpkin",
  "minecraft:water",
  "minecraft:wall_banner",
  "minecraft:wall_sign",
  "minecraft:torchflower",
  "minecraft:colored_torch_red",
  "minecraft:spore_blossom",
  "minecraft:waterlily",
  "minecraft:conduit",
  "minecraft:anvil",
  "minecraft:redstone_torch",
  "minecraft:lightning_rod",
  "minecraft:horn_coral",
  "minecraft:daylight_detector",
  "minecraft:bamboo",
  "minecraft:rose_bush",
  "minecraft:farmland",
  "minecraft:rail",
  "minecraft:soul_lantern",
  "minecraft:carrots",
  "minecraft:pale_hanging_moss",
  "minecraft:bubble_coral",
  "minecraft:calibrated_sculk_sensor",
  "minecraft:dead_tube_coral",
  "minecraft:colored_torch_blue",
  "minecraft:flowing_lava",
  "minecraft:medium_amethyst_bud",
  "minecraft:sculk_sensor",
  "minecraft:frog_spawn",
  "minecraft:daylight_detector_inverted",
  "minecraft:chorus_flower",
  "minecraft:torchflower_crop",
  "minecraft:pumpkin",
  "minecraft:colored_torch_purple",
  "minecraft:red_mushroom",
  "minecraft:bubble_column",
  "minecraft:sunflower",
  "minecraft:wither_rose",
  "minecraft:deadbush",
  "minecraft:glow_lichen",
  "minecraft:chipped_anvil",
  "minecraft:flowing_water",
  "minecraft:cave_vines",
  "minecraft:jigsaw",
  "minecraft:beetroot",
  "minecraft:golden_rail",
  "minecraft:structure_block",
  "minecraft:deprecated_anvil",
  "minecraft:dead_brain_coral",
  "minecraft:weeping_vines",
  "minecraft:chorus_plant",
  "minecraft:pumpkin_stem",
  "minecraft:lever",
  "minecraft:moving_block",
  "minecraft:trapped_chest",
  "minecraft:standing_sign",
  "minecraft:twisting_vines",
  "minecraft:reeds",
  "minecraft:campfire",
  "minecraft:bed",
  "minecraft:end_rod",
  "minecraft:end_portal_frame",
  "minecraft:sniffer_egg",
  "minecraft:cave_vines_body_with_berries",
  "minecraft:oxeye_daisy",
  "minecraft:tripwire_hook",
  "minecraft:large_fern",
  "minecraft:sweet_berry_bush",
  "minecraft:web",
  "minecraft:cocoa",
  "minecraft:fire",
  "minecraft:dead_fire_coral",
  "minecraft:unpowered_comparator",
  "minecraft:tall_grass",
  "minecraft:nether_sprouts",
  "minecraft:chain",
  "minecraft:colored_torch_green",
  "minecraft:air",
  "minecraft:closed_eyeblossom",
  "minecraft:decorated_pot",
  "minecraft:enchanting_table",
  "minecraft:orange_tulip",
  "minecraft:azalea",
  "minecraft:bell",
  "minecraft:hopper",
  "minecraft:lectern",
  "minecraft:standing_banner",
  "minecraft:mangrove_propagule",
  "minecraft:lantern",
  "minecraft:dead_bubble_coral",
  "minecraft:dragon_egg",
  "minecraft:camera",
  "minecraft:lilac",
  "minecraft:carved_pumpkin",
  "minecraft:candle",
  "minecraft:pointed_dripstone",
  "minecraft:red_tulip",
  "minecraft:trip_wire",
  "minecraft:cave_vines_head_with_berries",
  "minecraft:brewing_stand",
  "minecraft:crimson_roots",
  "minecraft:stonecutter_block",
  "minecraft:candle_cake",
  "minecraft:end_portal",
  "minecraft:crimson_fungus",
  "minecraft:tube_coral",
  "minecraft:portal",
  "minecraft:peony",
  "minecraft:amethyst_cluster",
  "minecraft:turtle_egg",
  "minecraft:soul_campfire",
  "minecraft:damaged_anvil",
  "minecraft:grass_path",
  "minecraft:dandelion",
  "minecraft:structure_void"
]);
var SHORT_WALL_CONNECTION = /* @__PURE__ */ new Set([
  "minecraft:warped_fungus",
  "minecraft:melon_stem",
  "minecraft:flower_pot",
  "minecraft:small_amethyst_bud",
  "minecraft:activator_rail",
  "minecraft:large_amethyst_bud",
  "minecraft:soul_torch",
  "minecraft:soul_fire",
  "minecraft:heavy_core",
  "minecraft:conduit",
  "minecraft:bubble_column",
  "minecraft:deadbush",
  "minecraft:chorus_plant",
  "minecraft:pumpkin_stem",
  "minecraft:moving_block",
  "minecraft:standing_sign",
  "minecraft:bed",
  "minecraft:end_rod",
  "minecraft:tripwire_hook",
  "minecraft:fire",
  "minecraft:chain",
  "minecraft:colored_torch_green",
  "minecraft:air",
  "minecraft:standing_banner",
  "minecraft:candle",
  "minecraft:pointed_dripstone"
]);
function hasNoPicketConnection(blockType) {
  return NO_PICKET_CONNECTION.has(blockType) || VANILLA_FENCES.has(blockType) || VANILLA_WALLS.has(blockType) || SINGLE_SLABS.has(blockType) || VANILLA_PRESSURE_PLATES.has(blockType) || VANILLA_CARPETS.has(blockType) || VANILLA_BUTTONS.has(blockType) || VANILLA_SHULKER_BOXES.has(blockType) || VANILLA_HEADS.has(blockType) || VANILLA_CAKES.has(blockType) || VANILLA_CORAL_WALL_FANS.has(blockType) || VANILLA_LIGHTS.has(blockType) || VANILLA_STANDING_SIGN.has(blockType) || VANILLA_HANGING_SIGNS.has(blockType) || VANILLA_CANDLES.has(blockType) || VANILLA_WALL_SIGNS.has(blockType) || VANILLA_CORAL_FANS.has(blockType) || VANILLA_SAPLINGS.has(blockType) || VANILLA_LEAVES.has(blockType) || VANILLA_DOORS.has(blockType);
}
function makesWallPost(blockType) {
  return VANILLA_STANDING_SIGN.has(blockType) || VANILLA_CANDLES.has(blockType);
}

// scripts/utils/blockHelper.ts
function destroy(block, breakAnimation, player, killItem = false) {
  const blockType = block.typeId;
  if (!breakAnimation)
    return block.setType("minecraft:air" /* Air */);
  else {
    if (player && player.getGameMode() == GameMode2.creative || killItem) {
      const o = world.afterEvents.entitySpawn.subscribe((ev) => {
        const itemEntity = ev.entity.getComponent(EntityComponentTypes2.Item);
        if (!itemEntity)
          return;
        if (itemEntity.itemStack.typeId != blockType)
          return;
        ev.entity.kill();
        world.afterEvents.entitySpawn.unsubscribe(o);
      });
      system2.runTimeout(() => world.afterEvents.entitySpawn.unsubscribe(o), 5);
    }
    block.dimension.runCommandAsync(generateSetBlockCommand(block.location));
  }
  blockUpdated(block);
}
function getBlockFromFace(block, blockFace, isReverse = false, steps = 1) {
  switch (blockFace) {
    case "Up":
    case 1:
      return isReverse ? block.below(steps) : block.above(steps);
    case "East":
    case 4:
      return isReverse ? block.west(steps) : block.east(steps);
    case "West":
    case 5:
      return isReverse ? block.east(steps) : block.west(steps);
    case "North":
    case 3:
      return isReverse ? block.south(steps) : block.north(steps);
    case "South":
    case 2:
      return isReverse ? block.north(steps) : block.south(steps);
    case "Down":
    case 0:
      return isReverse ? block.above(steps) : block.below(steps);
  }
}
function waitAfterMove(block, handler, ...params) {
  const interval = system2.runInterval(() => {
    if (block?.typeId === "minecraft:moving_block")
      return;
    system2.clearRun(interval);
    handler(...params);
  });
}

// node_modules/@minecraft/math/lib/general/clamp.js
function clampNumber(val, min, max) {
  return Math.min(Math.max(val, min), max);
}

// node_modules/@minecraft/math/lib/vector3/coreHelpers.js
var Vector3Utils = class _Vector3Utils {
  /**
   * equals
   *
   * Check the equality of two vectors
   */
  static equals(v1, v2) {
    return v1.x === v2.x && v1.y === v2.y && v1.z === v2.z;
  }
  /**
   * add
   *
   * Add two vectors to produce a new vector
   */
  static add(v1, v2) {
    return { x: v1.x + (v2.x ?? 0), y: v1.y + (v2.y ?? 0), z: v1.z + (v2.z ?? 0) };
  }
  /**
   * subtract
   *
   * Subtract two vectors to produce a new vector (v1-v2)
   */
  static subtract(v1, v2) {
    return { x: v1.x - (v2.x ?? 0), y: v1.y - (v2.y ?? 0), z: v1.z - (v2.z ?? 0) };
  }
  /** scale
   *
   * Multiple all entries in a vector by a single scalar value producing a new vector
   */
  static scale(v1, scale) {
    return { x: v1.x * scale, y: v1.y * scale, z: v1.z * scale };
  }
  /**
   * dot
   *
   * Calculate the dot product of two vectors
   */
  static dot(a, b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
  }
  /**
   * cross
   *
   * Calculate the cross product of two vectors. Returns a new vector.
   */
  static cross(a, b) {
    return { x: a.y * b.z - a.z * b.y, y: a.z * b.x - a.x * b.z, z: a.x * b.y - a.y * b.x };
  }
  /**
   * magnitude
   *
   * The magnitude of a vector
   */
  static magnitude(v) {
    return Math.sqrt(v.x ** 2 + v.y ** 2 + v.z ** 2);
  }
  /**
   * distance
   *
   * Calculate the distance between two vectors
   */
  static distance(a, b) {
    return _Vector3Utils.magnitude(_Vector3Utils.subtract(a, b));
  }
  /**
   * normalize
   *
   * Takes a vector 3 and normalizes it to a unit vector
   */
  static normalize(v) {
    const mag = _Vector3Utils.magnitude(v);
    return { x: v.x / mag, y: v.y / mag, z: v.z / mag };
  }
  /**
   * floor
   *
   * Floor the components of a vector to produce a new vector
   */
  static floor(v) {
    return { x: Math.floor(v.x), y: Math.floor(v.y), z: Math.floor(v.z) };
  }
  /**
   * toString
   *
   * Create a string representation of a vector3
   */
  static toString(v, options) {
    const decimals = options?.decimals ?? 2;
    const str = [v.x.toFixed(decimals), v.y.toFixed(decimals), v.z.toFixed(decimals)];
    return str.join(options?.delimiter ?? ", ");
  }
  /**
   * fromString
   *
   * Gets a Vector3 from the string representation produced by {@link Vector3Utils.toString}. If any numeric value is not a number
   * or the format is invalid, undefined is returned.
   * @param str - The string to parse
   * @param delimiter - The delimiter used to separate the components. Defaults to the same as the default for {@link Vector3Utils.toString}
   */
  static fromString(str, delimiter = ",") {
    const parts = str.split(delimiter);
    if (parts.length !== 3) {
      return void 0;
    }
    const output = parts.map((part) => parseFloat(part));
    if (output.some((part) => isNaN(part))) {
      return void 0;
    }
    return { x: output[0], y: output[1], z: output[2] };
  }
  /**
   * clamp
   *
   * Clamps the components of a vector to limits to produce a new vector
   */
  static clamp(v, limits) {
    return {
      x: clampNumber(v.x, limits?.min?.x ?? Number.MIN_SAFE_INTEGER, limits?.max?.x ?? Number.MAX_SAFE_INTEGER),
      y: clampNumber(v.y, limits?.min?.y ?? Number.MIN_SAFE_INTEGER, limits?.max?.y ?? Number.MAX_SAFE_INTEGER),
      z: clampNumber(v.z, limits?.min?.z ?? Number.MIN_SAFE_INTEGER, limits?.max?.z ?? Number.MAX_SAFE_INTEGER)
    };
  }
  /**
   * lerp
   *
   * Constructs a new vector using linear interpolation on each component from two vectors.
   */
  static lerp(a, b, t) {
    return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t, z: a.z + (b.z - a.z) * t };
  }
  /**
   * slerp
   *
   * Constructs a new vector using spherical linear interpolation on each component from two vectors.
   */
  static slerp(a, b, t) {
    const theta = Math.acos(_Vector3Utils.dot(a, b));
    const sinTheta = Math.sin(theta);
    const ta = Math.sin((1 - t) * theta) / sinTheta;
    const tb = Math.sin(t * theta) / sinTheta;
    return _Vector3Utils.add(_Vector3Utils.scale(a, ta), _Vector3Utils.scale(b, tb));
  }
  /**
   * multiply
   *
   * Element-wise multiplication of two vectors together.
   * Not to be confused with {@link Vector3Utils.dot} product or {@link Vector3Utils.cross} product
   */
  static multiply(a, b) {
    return { x: a.x * b.x, y: a.y * b.y, z: a.z * b.z };
  }
  /**
   * rotateX
   *
   * Rotates the vector around the x axis counterclockwise (left hand rule)
   * @param a - Angle in radians
   */
  static rotateX(v, a) {
    let cos = Math.cos(a);
    let sin = Math.sin(a);
    return { x: v.x, y: v.y * cos - v.z * sin, z: v.z * cos + v.y * sin };
  }
  /**
   * rotateY
   *
   * Rotates the vector around the y axis counterclockwise (left hand rule)
   * @param a - Angle in radians
   */
  static rotateY(v, a) {
    let cos = Math.cos(a);
    let sin = Math.sin(a);
    return { x: v.x * cos + v.z * sin, y: v.y, z: v.z * cos - v.x * sin };
  }
  /**
   * rotateZ
   *
   * Rotates the vector around the z axis counterclockwise (left hand rule)
   * @param a - Angle in radians
   */
  static rotateZ(v, a) {
    let cos = Math.cos(a);
    let sin = Math.sin(a);
    return { x: v.x * cos - v.y * sin, y: v.y * cos + v.x * sin, z: v.z };
  }
};

// node_modules/@minecraft/math/lib/vector3/vectorWrapper.js
var Vector3Builder = class {
  x;
  y;
  z;
  constructor(first, second, z) {
    if (typeof first === "object") {
      this.x = first.x;
      this.y = first.y;
      this.z = first.z;
    } else if (typeof first === "string") {
      const parsed = Vector3Utils.fromString(first, second ?? ",");
      if (!parsed) {
        this.x = 0;
        this.y = 0;
        this.z = 0;
        return;
      }
      this.x = parsed.x;
      this.y = parsed.y;
      this.z = parsed.z;
    } else {
      this.x = first;
      this.y = second ?? 0;
      this.z = z ?? 0;
    }
  }
  /**
   * Assigns the values of the passed in vector to this vector. Returns itself.
   */
  assign(vec) {
    this.x = vec.x;
    this.y = vec.y;
    this.z = vec.z;
    return this;
  }
  /**
   * equals
   *
   * Check the equality of two vectors
   */
  equals(v) {
    return Vector3Utils.equals(this, v);
  }
  /**
   * add
   *
   * Adds the vector v to this, returning itself.
   */
  add(v) {
    return this.assign(Vector3Utils.add(this, v));
  }
  /**
   * subtract
   *
   * Subtracts the vector v from this, returning itself.
   */
  subtract(v) {
    return this.assign(Vector3Utils.subtract(this, v));
  }
  /** scale
   *
   * Scales this by the passed in value, returning itself.
   */
  scale(val) {
    return this.assign(Vector3Utils.scale(this, val));
  }
  /**
   * dot
   *
   * Computes the dot product of this and the passed in vector.
   */
  dot(vec) {
    return Vector3Utils.dot(this, vec);
  }
  /**
   * cross
   *
   * Computes the cross product of this and the passed in vector, returning itself.
   */
  cross(vec) {
    return this.assign(Vector3Utils.cross(this, vec));
  }
  /**
   * magnitude
   *
   * The magnitude of the vector
   */
  magnitude() {
    return Vector3Utils.magnitude(this);
  }
  /**
   * distance
   *
   * Calculate the distance between two vectors
   */
  distance(vec) {
    return Vector3Utils.distance(this, vec);
  }
  /**
   * normalize
   *
   * Normalizes this vector, returning itself.
   */
  normalize() {
    return this.assign(Vector3Utils.normalize(this));
  }
  /**
   * floor
   *
   * Floor the components of a vector to produce a new vector
   */
  floor() {
    return this.assign(Vector3Utils.floor(this));
  }
  /**
   * toString
   *
   * Create a string representation of a vector
   */
  toString(options) {
    return Vector3Utils.toString(this, options);
  }
  /**
   * clamp
   *
   * Clamps the components of a vector to limits to produce a new vector
   */
  clamp(limits) {
    return this.assign(Vector3Utils.clamp(this, limits));
  }
  /**
   * lerp
   *
   * Constructs a new vector using linear interpolation on each component from two vectors.
   */
  lerp(vec, t) {
    return this.assign(Vector3Utils.lerp(this, vec, t));
  }
  /**
   * slerp
   *
   * Constructs a new vector using spherical linear interpolation on each component from two vectors.
   */
  slerp(vec, t) {
    return this.assign(Vector3Utils.slerp(this, vec, t));
  }
  /**
   * multiply
   *
   * Element-wise multiplication of two vectors together.
   * Not to be confused with {@link Vector3Builder.dot} product or {@link Vector3Builder.cross} product
   */
  multiply(vec) {
    return this.assign(Vector3Utils.multiply(this, vec));
  }
  /**
   * rotateX
   *
   * Rotates the vector around the x axis counterclockwise (left hand rule)
   * @param a - Angle in radians
   */
  rotateX(a) {
    return this.assign(Vector3Utils.rotateX(this, a));
  }
  /**
   * rotateY
   *
   * Rotates the vector around the y axis counterclockwise (left hand rule)
   * @param a - Angle in radians
   */
  rotateY(a) {
    return this.assign(Vector3Utils.rotateY(this, a));
  }
  /**
   * rotateZ
   *
   * Rotates the vector around the z axis counterclockwise (left hand rule)
   * @param a - Angle in radians
   */
  rotateZ(a) {
    return this.assign(Vector3Utils.rotateZ(this, a));
  }
};

// scripts/modules/ghosts.ts
import {
  EntityComponentTypes as EntityComponentTypes3,
  Player as Player3,
  world as world4
} from "@minecraft/server";

// scripts/utils/generalHelper.ts
import { BlockPermutation as BlockPermutation2, TimeOfDay } from "@minecraft/server";
function removeNamespace(data) {
  const typeId = data instanceof BlockPermutation2 ? data.type.id : data.typeId;
  const index = typeId.indexOf(":");
  return index !== -1 ? typeId.substring(index + 1) : typeId;
}
function generateUUID(length = 16) {
  let uuid = "";
  for (let i = 0; i < length; i++)
    uuid += Math.floor(Math.random() * 16).toString(16);
  return uuid;
}
function getTimeOfDay(time) {
  if (time >= 23e3 && time < 24e3 || time >= 0 && time < 1e3) {
    return TimeOfDay.Sunrise;
  } else if (time >= 1e3 && time < 6e3) {
    return TimeOfDay.Day;
  } else if (time >= 6e3 && time < 12e3) {
    return TimeOfDay.Noon;
  } else if (time >= 12e3 && time < 13e3) {
    return TimeOfDay.Sunset;
  } else if (time >= 13e3 && time < 18e3) {
    return TimeOfDay.Night;
  } else {
    return TimeOfDay.Midnight;
  }
}
function gameLog(...args) {
}
function toTitleCase(str) {
  return str.toLowerCase().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
}

// scripts/modules/grave.ts
import {
  BlockPermutation as BlockPermutation3,
  Direction as Direction3,
  system as system4,
  TimeOfDay as TimeOfDay2,
  world as world3
} from "@minecraft/server";

// scripts/utils/locationHelper.ts
import { world as world2 } from "@minecraft/server";
var LocationHelper = class _LocationHelper extends Vector3Utils {
  static toString(vector3) {
    return Vector3Utils.toString(vector3, { decimals: 0, delimiter: "_" });
  }
  static getDynamicProperty(vector3, key, addPrefix) {
    const prefix = addPrefix ? this.toString(vector3) + "#" : "";
    return world2.getDynamicProperty(prefix + key);
  }
  static {
    this.North = new Vector3Builder(0, 0, -1);
  }
  static {
    this.South = new Vector3Builder(0, 0, 1);
  }
  static {
    this.East = new Vector3Builder(1, 0, 0);
  }
  static {
    this.West = new Vector3Builder(-1, 0, 0);
  }
  static {
    this.Up = new Vector3Builder(0, 1, 0);
  }
  static {
    this.Down = new Vector3Builder(0, -1, 0);
  }
  static getVectorByDirection(blockFace) {
    switch (blockFace) {
      case "Up":
      case 1:
        return _LocationHelper.Up;
      case "East":
      case 4:
        return _LocationHelper.East;
      case "West":
      case 5:
        return _LocationHelper.West;
      case "North":
      case 3:
        return _LocationHelper.North;
      case "South":
      case 2:
        return _LocationHelper.South;
      case "Down":
      case 0:
        return _LocationHelper.Down;
      default:
        return new Vector3Builder(0, 0, 0);
    }
  }
  static setDynamicProperty(vector3, key, addPrefix = true, value) {
    const prefix = addPrefix ? this.toString(vector3) + "#" : "";
    return world2.setDynamicProperty(prefix + key, value);
  }
  static getDynamicPropertyIds(vector3, withLocation) {
    const prefix = this.toString(vector3) + "#" + "piki_ghosts:" /* Namespace */;
    const ids = world2.getDynamicPropertyIds().filter((i) => i.startsWith(prefix));
    if (withLocation)
      return ids;
    else
      return ids.map((i) => i.replace(this.toString(vector3) + "#", ""));
  }
};

// scripts/modules/grave.ts
var TAG_GRAVE_REPLACEABLE = "piki_ghosts:is_grave_replaceable";
var CUSTOM_COMPONENT = "piki_ghosts:graves";
var TIME_REQUIREMENT = [TimeOfDay2.Sunrise, TimeOfDay2.Day, TimeOfDay2.Noon];
function isGraveReplaceable(block) {
  if (block.isAir || block.isLiquid)
    return true;
  if (block.hasTag(TAG_GRAVE_REPLACEABLE))
    return true;
  return VANILLA_CROPS.has(block.typeId) || VANILLA_BUTTONS.has(block.typeId) || VANILLA_CANDLES.has(block.typeId) || VANILLA_CARPETS.has(block.typeId) || VANILLA_SAPLINGS.has(block.typeId) || VANILLA_LIGHTS.has(block.typeId) || VANILLA_PRESSURE_PLATES.has(block.typeId);
}
function findSpot(dimension, x, y, z) {
  for (let dy = -1; dy <= 1; dy++) {
    for (let dx = -1; dx <= 1; dx++) {
      for (let dz = -1; dz <= 1; dz++) {
        const block = dimension.getBlock({ x: x + dx, y: y + dy, z: z + dz });
        if (block && isGraveReplaceable(block))
          return block;
      }
    }
  }
  return void 0;
}
function onPistonPush(block, locationData) {
  if (block?.typeId != "piki_ghosts:grave" /* Grave */)
    return;
  const location = locationData ?? block.location;
  for (const id of DP_TRAPPED_GHOSTS.getIds(location, false)) {
    const value = LocationHelper.getDynamicProperty(location, id, true);
    LocationHelper.setDynamicProperty(block.location, id, true, value);
    LocationHelper.setDynamicProperty(location, id, true);
  }
}
function onWorldInitialize(blockComponentRegistry) {
  blockComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT, {
    onTick: (ev) => onTick(ev.block)
  });
}
function onTick(block) {
  if (getTimeOfDay(world3.getTimeOfDay()) != TimeOfDay2.Night)
    return;
  if (!block.permutation.getState("piki_ghosts:waiting_night"))
    return;
  destroyGrave(block, block.location);
}
function placeGrave(dimension, location, ghostId, eventId, nameTag) {
  const xz = { x: location.x, z: location.z };
  const targetBlock = dimension.getTopmostBlock(xz, location.y);
  if (!targetBlock)
    return gameLog("Cannot retrieve target block");
  let finalBlock;
  if (targetBlock.y == Math.floor(location.y)) {
    if (isGraveReplaceable(targetBlock))
      finalBlock = targetBlock;
    else
      finalBlock = findSpot(dimension, targetBlock.x, targetBlock.y, targetBlock.z);
  } else {
    if (isGraveReplaceable(targetBlock))
      finalBlock = targetBlock;
    else
      finalBlock = getBlockFromFace(targetBlock, Direction3.Up);
  }
  if (!finalBlock) {
    gameLog("No suitable spot to place grave.");
    return;
  }
  const gravePermutation = BlockPermutation3.resolve("piki_ghosts:grave" /* Grave */, {
    "piki_ghosts:waiting_night": true
  });
  finalBlock.setPermutation(gravePermutation);
  const ids = DP_TRAPPED_GHOSTS.getIds(finalBlock.location);
  for (const id of ids) {
    world3.setDynamicProperty(id);
  }
  const newUnique = generateUUID(8);
  const timestampKey = DP_TRAPPED_GHOSTS.getKey(newUnique, "timestamp");
  const variantKey = DP_TRAPPED_GHOSTS.getKey(newUnique, "variant");
  const typeIdKey = DP_TRAPPED_GHOSTS.getKey(newUnique, "typeId");
  const nameKey = DP_TRAPPED_GHOSTS.getKey(newUnique, "name");
  LocationHelper.setDynamicProperty(finalBlock.location, timestampKey, true, system4.currentTick);
  LocationHelper.setDynamicProperty(finalBlock.location, variantKey, true, eventId);
  LocationHelper.setDynamicProperty(finalBlock.location, typeIdKey, true, ghostId);
  LocationHelper.setDynamicProperty(finalBlock.location, nameKey, true, nameTag);
}
function destroyGrave(block, locationData) {
  if (block?.typeId != "piki_ghosts:grave" /* Grave */)
    return;
  const location = locationData ?? block.location;
  const dimension = block.dimension;
  for (const unique of DP_TRAPPED_GHOSTS.getUniques(LocationHelper.getDynamicPropertyIds(location, false))) {
    const variantKey = DP_TRAPPED_GHOSTS.getKey(unique, "variant");
    const typeIdKey = DP_TRAPPED_GHOSTS.getKey(unique, "typeId");
    const timeStampKey = DP_TRAPPED_GHOSTS.getKey(unique, "timestamp");
    const nameKey = DP_TRAPPED_GHOSTS.getKey(unique, "name");
    const entityId = LocationHelper.getDynamicProperty(location, typeIdKey, true);
    const variant = LocationHelper.getDynamicProperty(location, variantKey, true);
    const nametag = LocationHelper.getDynamicProperty(location, nameKey, true);
    system4.run(() => {
      const ghostEntity = dimension.spawnEntity(entityId, location);
      if (variant)
        ghostEntity.triggerEvent(VARIANT_EVENT_PREFIX + variant);
      ghostEntity.nameTag = nametag ?? "";
    });
    LocationHelper.setDynamicProperty(location, variantKey, true);
    LocationHelper.setDynamicProperty(location, typeIdKey, true);
    LocationHelper.setDynamicProperty(location, timeStampKey, true);
    LocationHelper.setDynamicProperty(location, nameKey, true);
  }
  system4.run(() => destroy(block, true, void 0, true));
}

// scripts/utils/dynamicProperties.ts
import { Entity as Entity3, ItemStack as ItemStack4 } from "@minecraft/server";
var DynamicPropertyHelper = class {
  constructor(prefix) {
    this.prefix = "";
    this.prefix = "piki_ghosts:" /* Namespace */ + prefix;
  }
  getUniques(dynamicPropertyIds) {
    return [...new Set(dynamicPropertyIds.filter((i) => i.startsWith(this.prefix)).map((id) => id.split("/")[1]))];
  }
  getUnique(dynamicPropertyId) {
    return dynamicPropertyId.split("/")[1];
  }
  getKey(uniqueId, property) {
    return `${this.prefix}/${uniqueId}/${property}`;
  }
  getIds(data, withLocation = true) {
    if (data instanceof ItemStack4 || data instanceof Entity3) {
      return data.getDynamicPropertyIds().filter((i) => i.startsWith(this.prefix));
    } else {
      return LocationHelper.getDynamicPropertyIds(data, withLocation);
    }
  }
};

// scripts/modules/ghosts.ts
var GHOSTS_SUPPORTED_MOBS = {
  families: ["mob"],
  excludeFamilies: ["ghost"]
};
var GHOSTS_ENTITIES2 = {
  families: ["ghost"]
};
var VARIANT_EVENTS = {
  "minecraft:wolf": {
    variantComponent: EntityComponentTypes3.Variant,
    events: {
      0: "minecraft:spawn_wild_pale",
      1: "minecraft:spawn_wild_ashen",
      2: "minecraft:spawn_wild_black",
      3: "minecraft:spawn_wild_chestnut",
      4: "minecraft:spawn_wild_rusty",
      5: "minecraft:spawn_wild_snowy",
      6: "minecraft:spawn_wild_spotted",
      7: "minecraft:spawn_wild_striped",
      8: "minecraft:spawn_wild_woods"
    }
  }
};
var DP_TRAPPED_GHOSTS = new DynamicPropertyHelper(
  "TrappedGhosts"
);
var VARIANT_EVENT_PREFIX = "piki_ghosts:variant";
function getGhostVanillaId(entityId) {
  return entityId.replace(`${"piki_ghosts:" /* Namespace */}ghost_`, "minecraft:");
}
function getGhostId(entity) {
  const entityType = removeNamespace(entity);
  return `${"piki_ghosts:" /* Namespace */}ghost_${entityType}`;
}
function onEntityHurt(damagingEntity, hitEntity) {
  if (!damagingEntity || !hitEntity)
    return;
  if (!hitEntity?.matches(GHOSTS_SUPPORTED_MOBS))
    return;
  if (!(damagingEntity instanceof Player3))
    return;
  const health = hitEntity.getComponent(EntityComponentTypes3.Health);
  if (health.currentValue > 0)
    return;
  gameLog(hitEntity.typeId, "died");
  const ghostId = getGhostId(hitEntity);
  const variantComponent = VARIANT_EVENTS[hitEntity?.typeId]?.variantComponent;
  let eventId;
  if (variantComponent) {
    const value = hitEntity?.getComponent(variantComponent)?.value;
    if (value != void 0)
      eventId = VARIANT_EVENT_PREFIX + value;
  }
  if (TIME_REQUIREMENT.includes(getTimeOfDay(world4.getTimeOfDay()))) {
    placeGrave(hitEntity.dimension, hitEntity.location, ghostId, eventId, hitEntity.nameTag);
    return;
  }
  try {
    const entity = summon(hitEntity?.dimension, ghostId, hitEntity?.location, eventId);
    if (entity)
      entity.nameTag = hitEntity.nameTag ?? "";
  } catch {
    gameLog(`${hitEntity.typeId} doesn't have a ghost version`);
  }
}

// scripts/modules/silverMirror.ts
import {
  EntityComponentTypes as EntityComponentTypes5,
  EquipmentSlot as EquipmentSlot3,
  ItemStack as ItemStack6,
  system as system6
} from "@minecraft/server";

// scripts/utils/itemHelper.ts
import {
  EntityComponentTypes as EntityComponentTypes4,
  ItemComponentTypes
} from "@minecraft/server";
function damageItem(player, equipmentSlot, itemStack, setDamage, damage = 1) {
  const equippable = player.getComponent(EntityComponentTypes4.Equippable);
  if (!itemStack)
    itemStack = equippable.getEquipment(equipmentSlot);
  if (!itemStack)
    return;
  const durability = itemStack.getComponent(ItemComponentTypes.Durability);
  durability.damage = setDamage ?? Math.min(durability.damage + damage, durability.maxDurability);
  equippable.setEquipment(equipmentSlot, itemStack);
}

// scripts/modules/silverMirror.ts
var CUSTOM_COMPONENT2 = "piki_ghost:silver_mirror";
function getTrappedGhostSum(itemStack) {
  if (!itemStack)
    return 0;
  const entitiesTrapped = DP_TRAPPED_GHOSTS.getUniques(itemStack.getDynamicPropertyIds());
  return entitiesTrapped.length;
}
function onItemUse(source, itemStack) {
  if (itemStack?.typeId != "piki_ghosts:silver_mirror" /* SilverMirror */)
    return;
  tranferGhosts(itemStack, source);
}
function onWorldInitialize2(itemComponentRegistry) {
  itemComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT2, {
    onBeforeDurabilityDamage: (ev) => ev.durabilityDamage = 0,
    onUse: (ev) => onItemUse(ev.source, ev.itemStack),
    onCompleteUse: (ev) => trapGhost(void 0, ev.itemStack, ev.source)
  });
}
function trapGhost(ghostEntity, itemStack, player) {
  if (!ghostEntity) {
    const raycast = player.getEntitiesFromViewDirection({
      families: ["ghost"],
      maxDistance: 3
    });
    if (raycast.length <= 0)
      return;
    ghostEntity = raycast[0].entity;
  }
  if (!ghostEntity?.matches(GHOSTS_ENTITIES2))
    return;
  const trappedGhostsNumber = getTrappedGhostSum(itemStack);
  if (trappedGhostsNumber >= 1) {
    player.playSound("note.bass" /* NoteBass */);
    player.sendMessage("\xA7cA ghost is already stored in this item");
    return;
  }
  const uniqueId = generateUUID(8);
  const variant = ghostEntity.getComponent(EntityComponentTypes5.SkinId)?.value;
  const timeStampKey = DP_TRAPPED_GHOSTS.getKey(uniqueId, "timestamp");
  const typeIdKey = DP_TRAPPED_GHOSTS.getKey(uniqueId, "typeId");
  const variantKey = DP_TRAPPED_GHOSTS.getKey(uniqueId, "variant");
  const nameKey = DP_TRAPPED_GHOSTS.getKey(uniqueId, "name");
  itemStack.setDynamicProperty(timeStampKey, system6.currentTick);
  itemStack.setDynamicProperty(typeIdKey, ghostEntity.typeId);
  itemStack.setDynamicProperty(variantKey, variant);
  itemStack.setDynamicProperty(nameKey, ghostEntity.nameTag);
  ghostEntity.triggerEvent("piki_ghosts:despawn" /* CustomDespawn */);
  damageItem(player, EquipmentSlot3.Mainhand, itemStack);
}
function tranferGhosts(itemStack, player) {
  const equippable = player.getComponent(EntityComponentTypes5.Equippable);
  const leftItemStack = equippable?.getEquipment(EquipmentSlot3.Offhand);
  if (leftItemStack?.typeId != "piki_ghosts:spirit_capsule_empty" /* SpiritCapsuleEmpty */)
    return;
  const newItem = new ItemStack6("piki_ghosts:spirit_capsule_filled" /* SpiritCapsuleFilled */);
  const uniques = DP_TRAPPED_GHOSTS.getUniques(itemStack.getDynamicPropertyIds());
  if (uniques.length == 0)
    return;
  const targetId = uniques[0];
  const variantKey = DP_TRAPPED_GHOSTS.getKey(targetId, "variant");
  const typeIdKey = DP_TRAPPED_GHOSTS.getKey(targetId, "typeId");
  const timeStampKey = DP_TRAPPED_GHOSTS.getKey(targetId, "timestamp");
  const nameKey = DP_TRAPPED_GHOSTS.getKey(targetId, "name");
  const variant = itemStack.getDynamicProperty(variantKey);
  const typeId = itemStack.getDynamicProperty(typeIdKey);
  const timestamp = itemStack.getDynamicProperty(timeStampKey);
  const name = itemStack.getDynamicProperty(nameKey);
  newItem.setDynamicProperty(variantKey, variant);
  newItem.setDynamicProperty(typeIdKey, typeId);
  newItem.setDynamicProperty(timeStampKey, timestamp);
  newItem.setDynamicProperty(nameKey, name);
  itemStack.setDynamicProperty(variantKey);
  itemStack.setDynamicProperty(typeIdKey);
  itemStack.setDynamicProperty(timeStampKey);
  itemStack.setDynamicProperty(nameKey);
  const entityName = getEntityName(typeId);
  const lore = name ? `${name} (${entityName})` : entityName;
  newItem.setLore([lore]);
  equippable.setEquipment(EquipmentSlot3.Mainhand, itemStack);
  equippable.setEquipment(EquipmentSlot3.Offhand, newItem);
}

// scripts/modules/spiritCapsule.ts
import {
  EntityComponentTypes as EntityComponentTypes6,
  EntityTypes,
  EquipmentSlot as EquipmentSlot4,
  ItemStack as ItemStack7,
  system as system7
} from "@minecraft/server";
var BLOCK_CUSTOM_COMPONENT = "piki_ghosts:spirit_capsule";
function onWorldInitialize3(blockComponentRegistry) {
  blockComponentRegistry.registerCustomComponent(BLOCK_CUSTOM_COMPONENT, {
    beforeOnPlayerPlace: (ev) => onPlayerPlace(ev.block, ev.player),
    onPlayerInteract: (ev) => getBlockAsItem(ev.block, ev.player),
    onPlayerDestroy: (ev) => getBlockAsItem(ev.block, ev.player),
    onEntityFallOn: (ev) => {
      if (ev.fallDistance > 10)
        destroyCapsuleBlock(ev.block);
    }
  });
}
function onPlayerPlace(block, player) {
  if (!player)
    return;
  const equippable = player.getComponent(EntityComponentTypes6.Equippable);
  const itemStack = equippable?.getEquipment(EquipmentSlot4.Mainhand);
  if (itemStack?.typeId != "piki_ghosts:spirit_capsule_filled" /* SpiritCapsuleFilled */)
    return;
  const location = block.location;
  for (const unique of DP_TRAPPED_GHOSTS.getUniques(LocationHelper.getDynamicPropertyIds(location, false))) {
    const variant = DP_TRAPPED_GHOSTS.getKey(unique, "variant");
    const typeIdKey = DP_TRAPPED_GHOSTS.getKey(unique, "typeId");
    const timeStampKey = DP_TRAPPED_GHOSTS.getKey(unique, "timestamp");
    const nameKey = DP_TRAPPED_GHOSTS.getKey(unique, "name");
    LocationHelper.setDynamicProperty(location, variant, true);
    LocationHelper.setDynamicProperty(location, typeIdKey, true);
    LocationHelper.setDynamicProperty(location, timeStampKey, true);
    LocationHelper.setDynamicProperty(location, nameKey, true);
  }
  const dpIds = DP_TRAPPED_GHOSTS.getIds(itemStack);
  for (const dpId of dpIds) {
    const value = itemStack.getDynamicProperty(dpId);
    itemStack.setDynamicProperty(dpId);
    LocationHelper.setDynamicProperty(block.location, dpId, true, value);
  }
}
function onPistonPush2(block, lastLocation) {
  destroyCapsuleBlock(block, lastLocation);
}
function onEntitySpawn(entity) {
  if (entity.typeId != "minecraft:lightning_bolt" /* LightningBolt */)
    return;
  const block = entity.dimension.getBlock(entity.location)?.below();
  destroyCapsuleBlock(block);
}
function getBlockAsItem(block, player) {
  if (!player)
    return;
  const newItem = new ItemStack7("piki_ghosts:spirit_capsule_filled" /* SpiritCapsuleFilled */);
  for (const dpId of LocationHelper.getDynamicPropertyIds(block.location, false)) {
    const value = LocationHelper.getDynamicProperty(block.location, dpId, true);
    newItem.setDynamicProperty(dpId, value);
    LocationHelper.setDynamicProperty(block.location, dpId, true);
  }
  const lore = [];
  for (const unique of DP_TRAPPED_GHOSTS.getUniques(LocationHelper.getDynamicPropertyIds(block.location, false))) {
    const nameKey = DP_TRAPPED_GHOSTS.getKey(unique, "name");
    const typeIdKey = DP_TRAPPED_GHOSTS.getKey(unique, "typeId");
    const name = LocationHelper.getDynamicProperty(block.location, nameKey, false);
    const type = LocationHelper.getDynamicProperty(block.location, nameKey, false);
    lore.push((name ? name + ": " : "") + EntityTypes.get(type));
  }
  newItem.setLore(lore);
  destroy(block, true, void 0, true);
  giveItem(newItem, player);
}
function destroyCapsuleBlock(block, locationData) {
  if (block?.typeId != "piki_ghosts:spirit_capsule" /* SpiritCapsule */)
    return;
  const location = locationData ?? block.location;
  const dimension = block.dimension;
  for (const unique of DP_TRAPPED_GHOSTS.getUniques(LocationHelper.getDynamicPropertyIds(location, false))) {
    const variantKey = DP_TRAPPED_GHOSTS.getKey(unique, "variant");
    const typeIdKey = DP_TRAPPED_GHOSTS.getKey(unique, "typeId");
    const timeStampKey = DP_TRAPPED_GHOSTS.getKey(unique, "timestamp");
    const entityId = LocationHelper.getDynamicProperty(location, typeIdKey, true);
    const variant = LocationHelper.getDynamicProperty(location, variantKey, true);
    system7.run(() => {
      const ghostEntity = dimension.spawnEntity(entityId, location);
      if (variant)
        ghostEntity.triggerEvent(VARIANT_EVENT_PREFIX + variant);
    });
    LocationHelper.setDynamicProperty(location, variantKey, true);
    LocationHelper.setDynamicProperty(location, typeIdKey, true);
    LocationHelper.setDynamicProperty(location, timeStampKey, true);
  }
  system7.run(() => destroy(block, true, void 0, true));
}

// scripts/modules/silverBlocks.ts
import {
  EntityComponentTypes as EntityComponentTypes7,
  EquipmentSlot as EquipmentSlot5,
  system as system9
} from "@minecraft/server";

// scripts/modules/customDoors.ts
import {
  Direction as Direction4,
  system as system8
} from "@minecraft/server";
var TAG_CUSTOM_DOOR = "piki_ghosts:is_custom_doors";
var CUSTOM_COMPONENT3 = "piki_ghosts:custom_doors";
function getHingeState(block, permutation) {
  const northBlock = block.north();
  const southBlock = block.south();
  const eastBlock = block.east();
  const westBlock = block.west();
  const cardinalDirection = permutation.getState("minecraft:cardinal_direction");
  const expectedHingeType = permutation.type.id;
  if (cardinalDirection === Direction4.South.toLowerCase() && eastBlock?.typeId === expectedHingeType) {
    const isAdjacentHinge = eastBlock.permutation.getState("piki_ghosts:door_hinge_bit");
    const isAdjacentUpper = eastBlock.permutation.getState("piki_ghosts:upper_block_bit");
    if (isAdjacentHinge || isAdjacentUpper)
      return permutation;
    return permutation.withState("piki_ghosts:door_hinge_bit", true);
  }
  if (cardinalDirection === Direction4.East.toLowerCase() && northBlock?.typeId === expectedHingeType) {
    const isAdjacentHinge = northBlock.permutation.getState("piki_ghosts:door_hinge_bit");
    const isAdjacentUpper = northBlock.permutation.getState("piki_ghosts:upper_block_bit");
    if (isAdjacentHinge || isAdjacentUpper)
      return permutation;
    return permutation.withState("piki_ghosts:door_hinge_bit", true);
  }
  if (cardinalDirection === Direction4.North.toLowerCase() && westBlock?.typeId === expectedHingeType) {
    const isAdjacentHinge = westBlock.permutation.getState("piki_ghosts:door_hinge_bit");
    const isAdjacentUpper = westBlock.permutation.getState("piki_ghosts:upper_block_bit");
    if (isAdjacentHinge || isAdjacentUpper)
      return permutation;
    return permutation.withState("piki_ghosts:door_hinge_bit", true);
  }
  if (cardinalDirection === Direction4.West.toLowerCase() && southBlock?.typeId === expectedHingeType) {
    const isAdjacentHinge = southBlock.permutation.getState("piki_ghosts:door_hinge_bit");
    const isAdjacentUpper = southBlock.permutation.getState("piki_ghosts:upper_block_bit");
    if (isAdjacentHinge || isAdjacentUpper)
      return permutation;
    return permutation.withState("piki_ghosts:door_hinge_bit", true);
  }
  return permutation;
}
function onWorldInitialize4(blockComponentRegistry) {
  blockComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT3, {
    onPlayerInteract,
    onPlace: (ev) => onPlace(ev.block)
  });
}
function onPlace(block) {
  const hingeState = getHingeState(block, block.permutation);
  block.setPermutation(hingeState);
  const aboveBlock = block.above();
  if (block.permutation.getState("piki_ghosts:upper_block_bit"))
    return;
  if (!aboveBlock || !aboveBlock.isAir && !aboveBlock.isLiquid)
    return destroy(block, true, void 0, true);
  const counterpartPermutation = hingeState.withState("piki_ghosts:upper_block_bit", true);
  aboveBlock.setPermutation(counterpartPermutation);
  blockUpdated(aboveBlock);
}
function onPlayerInteract(ev) {
  const { block, dimension, player } = ev;
  const isUpperBlock = block.permutation.getState("piki_ghosts:upper_block_bit");
  const counterPartBlock = isUpperBlock ? block.below() : block.above();
  if (!counterPartBlock)
    return destroyDoor(block, player);
  const currentOpenState = block.permutation.getState("piki_ghosts:open_bit");
  block.setPermutation(block.permutation.withState("piki_ghosts:open_bit", !currentOpenState));
  counterPartBlock.setPermutation(counterPartBlock.permutation.withState("piki_ghosts:open_bit", !currentOpenState));
  const sound = currentOpenState ? "close_door.copper" /* CloseDoorCopper */ : "open_door.copper" /* OpenDoorCopper */;
  dimension.playSound(sound, block.location);
  blockUpdated(block);
  blockUpdated(counterPartBlock);
}
function destroyDoor(block, player, blockLocation) {
  if (!block.hasTag(TAG_CUSTOM_DOOR))
    return;
  if (blockLocation == void 0)
    blockLocation = block;
  const isUpper = block.permutation.getState("piki_ghosts:upper_block_bit");
  const counterPartBlock = isUpper ? blockLocation.below() : blockLocation.above();
  system8.run(() => {
    if (block.hasTag(TAG_CUSTOM_DOOR))
      destroy(block, true, player, isUpper);
    if (counterPartBlock?.hasTag(TAG_CUSTOM_DOOR))
      destroy(counterPartBlock, true, player, !isUpper);
  });
}
function processBlockAttached(block) {
  if (VANILLA_BUTTONS.has(block.typeId)) {
    const facing = block.permutation.getState("facing_direction");
    const blockFacing = getBlockFromFace(block, facing, facing <= 1);
    if (!blockFacing || !blockFacing.hasTag(TAG_CUSTOM_DOOR))
      return;
  } else if (VANILLA_PRESSURE_PLATES.has(block.typeId)) {
    const below = block.below();
    if (!below || !below.hasTag(TAG_CUSTOM_DOOR))
      return;
  } else
    return;
  destroy(block, true);
}

// scripts/modules/silverBlocks.ts
var CUSTOM_COMPONENT4 = "piki_ghosts:silver_blocks";
var DP_LAST_TARNISHED = new DynamicPropertyHelper("SilverBlock");
var TAG_SILVER_BLOCK = "piki_ghosts:is_silver_block";
var TARNISH_DURATION = 30 * 60;
function hasNearbyPhasingPlayer(block) {
  if (!block)
    return false;
  const entities = block.dimension.getEntities({
    location: block.center(),
    type: "minecraft:player" /* Player */,
    maxDistance: 4
  });
  for (const player of entities) {
    const flooredLocation = LocationHelper.floor(player.location);
    if (flooredLocation.x == block.x && flooredLocation.z == block.z && flooredLocation.y > block.y)
      continue;
    const equippable = player.getComponent(EntityComponentTypes7.Equippable);
    if (!equippable)
      continue;
    if (equippable.getEquipment(EquipmentSlot5.Chest)?.typeId != "piki_ghosts:hardened_ectoplasm_chestplate" /* HardenedEctoplasmChestplate */)
      continue;
    if (equippable.getEquipment(EquipmentSlot5.Legs)?.typeId != "piki_ghosts:hardened_ectoplasm_leggings" /* HardenedEctoplasmLeggings */)
      continue;
    if (equippable.getEquipment(EquipmentSlot5.Head)?.typeId != "piki_ghosts:hardened_ectoplasm_helmet" /* HardenedEctoplasmHelmet */)
      continue;
    if (equippable.getEquipment(EquipmentSlot5.Feet)?.typeId != "piki_ghosts:hardened_ectoplasm_boots" /* HardenedEctoplasmBoots */)
      continue;
    return true;
  }
  return false;
}
function hasNearbyGhost(block) {
  if (!block)
    return false;
  const entities = block.dimension.getEntities({
    location: block.center(),
    families: ["ghost"],
    maxDistance: 4
  });
  return entities.length > 0;
}
function onWorldInitialze(blockComponentRegistry) {
  blockComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT4, {
    onTick: (ev) => onTick2(ev.block),
    beforeOnPlayerPlace: (ev) => setLastTarnished(ev.block),
    onPlace: (ev) => setLastTarnished(ev.block)
  });
}
function onTick2(block) {
  if (!block.hasTag(TAG_SILVER_BLOCK))
    return;
  const lastTarnished = LocationHelper.getDynamicProperty(
    block.location,
    DP_LAST_TARNISHED.getKey("", "lastTarnished"),
    true
  );
  if (lastTarnished == void 0)
    setLastTarnished(block);
  else {
    const correctTarnish = system9.currentTick - lastTarnished > TARNISH_DURATION * 20;
    const currentTarnish2 = block.permutation.getState("piki_ghosts:is_tarnished");
    if (correctTarnish && !currentTarnish2) {
      block.setPermutation(block.permutation.withState("piki_ghosts:is_tarnished", true));
    }
  }
  if (!block.hasTag(TAG_SILVER_BLOCK))
    return;
  const currentTarnish = block.permutation.getState("piki_ghosts:is_tarnished");
  const currentCollision = block.permutation.getState("piki_ghosts:has_collision");
  if (!currentTarnish && hasNearbyPhasingPlayer(block)) {
    if (currentCollision)
      block.setPermutation(block.permutation.withState("piki_ghosts:has_collision", false));
  } else if (currentTarnish && hasNearbyGhost(block)) {
    if (currentCollision)
      block.setPermutation(block.permutation.withState("piki_ghosts:has_collision", false));
  } else if (!currentCollision) {
    block.setPermutation(block.permutation.withState("piki_ghosts:has_collision", true));
  }
}
function onBlockInteract(block, itemStack) {
  if (itemStack?.typeId != "piki_ghosts:hardened_ectoplasm_shard" /* HardenedEctoplasmShard */)
    return;
  if (!block.hasTag(TAG_SILVER_BLOCK))
    return;
  if (block.typeId == "piki_ghosts:silver_grill" /* SilverGrill */)
    return;
  setLastTarnished(block);
  if (block.hasTag(TAG_CUSTOM_DOOR)) {
    const isUpper = block.permutation.getState("piki_ghosts:upper_block_bit");
    const counterPartBlock = isUpper ? block.below() : block.above();
    if (counterPartBlock) {
      setLastTarnished(counterPartBlock);
      system9.run(
        () => counterPartBlock.setPermutation(
          counterPartBlock.permutation.withState("piki_ghosts:is_tarnished", false)
        )
      );
    }
  }
  system9.run(() => block.setPermutation(block.permutation.withState("piki_ghosts:is_tarnished", false)));
}
function setLastTarnished(block) {
  LocationHelper.setDynamicProperty(
    block.location,
    DP_LAST_TARNISHED.getKey("", "lastTarnished"),
    true,
    system9.currentTick
  );
}

// scripts/modules/customWalls.ts
import {
  BlockPermutation as BlockPermutation6,
  Direction as Direction6,
  system as system11
} from "@minecraft/server";

// scripts/modules/customTrapdoors.ts
var TAG_CUSTOM_TRAPDOOR = "piki_ghosts:is_custom_trapdoor";
var CUSTOM_COMPONENT5 = "piki_ghosts:custom_trapdoors";
function onWorldInitialize5(blockComponentRegistry) {
  blockComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT5, {
    onPlayerInteract: onPlayerInteract2
  });
}
function onPlayerInteract2(ev) {
  const { block, player } = ev;
  const currentState = block.permutation.getState("piki_ghosts:open");
  const newOpenState = !currentState;
  const newPermutation = block.permutation.withState("piki_ghosts:open", newOpenState);
  block.setPermutation(newPermutation);
  player?.dimension.playSound("open_trapdoor.copper" /* OpenTrapdoorCopper */, block.location);
  blockUpdated(block);
}
function processBlockAttached2(block) {
  if (VANILLA_BUTTONS.has(block.typeId)) {
    const facing = block.permutation.getState("facing_direction");
    const blockFacing = getBlockFromFace(block, facing, facing <= 1);
    if (!blockFacing || !blockFacing.hasTag(TAG_CUSTOM_TRAPDOOR))
      return;
  } else if (VANILLA_PRESSURE_PLATES.has(block.typeId)) {
    const below = block.below();
    if (!below || !below.hasTag(TAG_CUSTOM_TRAPDOOR))
      return;
  } else
    return;
  destroy(block, true);
}

// scripts/modules/customSlabs.ts
import {
  Direction as Direction5,
  EquipmentSlot as EquipmentSlot6,
  GameMode as GameMode3,
  ItemStack as ItemStack9,
  system as system10
} from "@minecraft/server";
var TAG_CUSTOM_SLAB = "piki_ghosts:is_custom_slab";
var CUSTOM_COMPONENT6 = "piki_ghosts:custom_slabs";
function setComplete(block, permutationToPlace) {
  system10.run(() => {
    const doubleState = permutationToPlace.withState("piki_ghosts:double", true);
    block.dimension.playSound("use.stone" /* UseStone */, block.location, { volume: 1, pitch: 0.8 });
    block.setWaterlogged(false);
    block.setPermutation(doubleState);
    blockUpdated(block);
  });
}
function onWorldInitialize6(blockComponentRegistry) {
  blockComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT6, {
    beforeOnPlayerPlace
  });
}
function beforeOnPlayerPlace(ev) {
  const { block, face, player, permutationToPlace } = ev;
  const targetBlock = getBlockFromFace(block, face, true);
  if (!targetBlock)
    return;
  const itemSameAsBlock = targetBlock.typeId == permutationToPlace.type.id;
  const blockDoubleState = targetBlock.permutation.getState("piki_ghosts:double");
  const blockVerticalState = targetBlock.permutation.getState("minecraft:vertical_half");
  const correctFace = blockVerticalState == "top" && face == Direction5.Down || blockVerticalState == "bottom" && face == Direction5.Up;
  if (!itemSameAsBlock || blockDoubleState || !correctFace)
    return;
  ev.cancel = true;
  system10.run(() => {
    if (player)
      clearPlayerItem(player, EquipmentSlot6.Mainhand);
    setComplete(targetBlock, permutationToPlace);
  });
}
function onPlayerInteractBlock(ev) {
  const { block, blockFace, player, itemStack } = ev;
  if (!itemStack)
    return;
  if (!block.hasTag(TAG_CUSTOM_SLAB))
    return;
  const itemSameAsBlock = block.typeId == itemStack.typeId;
  if (itemSameAsBlock) {
    const blockDoubleState = block.permutation.getState("piki_ghosts:double");
    const blockVerticalState = block.permutation.getState("minecraft:vertical_half");
    const correctFace = blockVerticalState == "top" && blockFace == Direction5.Down || blockVerticalState == "bottom" && blockFace == Direction5.Up;
    if (!blockDoubleState && correctFace) {
      ev.cancel = true;
      system10.run(() => {
        clearPlayerItem(player, EquipmentSlot6.Mainhand);
        setComplete(block, block.permutation);
      });
      return;
    }
  }
  const targetBlock = getBlockFromFace(block, blockFace);
  const itemSameAsTarget = targetBlock?.typeId == itemStack.typeId;
  if (itemSameAsTarget) {
    const targetDoubleState = targetBlock?.permutation.getState("piki_ghosts:double");
    if (!targetDoubleState) {
      ev.cancel = true;
      system10.run(() => {
        clearPlayerItem(player, EquipmentSlot6.Mainhand);
        setComplete(targetBlock, targetBlock.permutation);
        player.playAnimation("animation.piki_ghosts.swing" /* Swing */);
      });
    }
  }
}
function dropLoot(block, player) {
  if (!block.hasTag(TAG_CUSTOM_SLAB))
    return;
  const state = block.permutation.getState("piki_ghosts:double");
  if (!state)
    return;
  if (player && player.getGameMode() == GameMode3.creative)
    return;
  system10.run(() => block.dimension.spawnItem(new ItemStack9(block.typeId), block.location));
}

// scripts/modules/customWalls.ts
var NO_WALL_PICKET_CONNECTION_TAG = "piki_ghosts:no_wall_picket_connection";
var TAG_CUSTOM_WALL = "piki_ghosts:is_custom_wall";
var requiredWeirdo1 = {
  [Direction6.West]: 0,
  [Direction6.East]: 1,
  [Direction6.North]: 2,
  [Direction6.South]: 3
};
var requiredFacingDirection1 = {
  [Direction6.West]: 5,
  [Direction6.East]: 4,
  [Direction6.North]: 3,
  [Direction6.South]: 2
};
var requiredFacingDirection2 = {
  [Direction6.West]: 4,
  [Direction6.East]: 5,
  [Direction6.North]: 2,
  [Direction6.South]: 3
};
var requiredFacingDirection3 = {
  [Direction6.West]: Direction6.East,
  [Direction6.East]: Direction6.West,
  [Direction6.North]: Direction6.South,
  [Direction6.South]: Direction6.North
};
var requiredDirection1 = {
  [Direction6.West]: [0, 2],
  [Direction6.East]: [0, 2],
  [Direction6.North]: [1, 3],
  [Direction6.South]: [1, 3]
};
var requiredWallConnection1 = {
  [Direction6.West]: "wall_connection_type_west",
  [Direction6.East]: "wall_connection_type_east",
  [Direction6.North]: "wall_connection_type_north",
  [Direction6.South]: "wall_connection_type_south"
};
var requiredWallConnection2 = {
  [Direction6.West]: "piki_ghosts:west_picket",
  [Direction6.East]: "piki_ghosts:east_picket",
  [Direction6.North]: "piki_ghosts:north_picket",
  [Direction6.South]: "piki_ghosts:south_picket"
};
function getCorrectPicketState(block, direction, blockAbove, blockAbovePermutation) {
  const picketTarget = getBlockFromFace(block, direction);
  if (!picketTarget)
    return [0, blockAbovePermutation];
  const picketBlockType = picketTarget.typeId;
  if (picketTarget.hasTag(TAG_CUSTOM_WALL) || VANILLA_WALLS.has(picketBlockType)) {
  } else if (picketTarget.hasTag(NO_WALL_PICKET_CONNECTION_TAG)) {
    return [0, blockAbovePermutation];
  } else if (hasNoPicketConnection(picketBlockType)) {
    return [0, blockAbovePermutation];
  } else if (VANILLA_STAIRS.has(picketBlockType)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["weirdo_direction"] != requiredWeirdo1[direction])
      return [0, blockAbovePermutation];
  } else if (VANILLA_TRAPDOOR.has(picketBlockType)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["direction"] != requiredFacingDirection1[direction])
      return [0, blockAbovePermutation];
    if (!picketTargetPermutation["open_bit"])
      return [0, blockAbovePermutation];
  } else if (VANILLA_FENCEGATES.has(picketBlockType)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    const blockDirection = picketTargetPermutation["direction"];
    if (!requiredDirection1[direction]?.includes(blockDirection))
      return [0, blockAbovePermutation];
  } else if (PISTON_ARMS.has(picketBlockType)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["facing_direction"] != requiredFacingDirection2[direction])
      return [0, blockAbovePermutation];
  } else if (picketBlockType == "minecraft:ladder" /* Ladder */) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["facing_direction"] != requiredFacingDirection1[direction])
      return [0, blockAbovePermutation];
  } else if (picketBlockType == "minecraft:snow_layer" /* SnowLayer */) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["height"] != 8)
      return [0, blockAbovePermutation];
  } else if (picketTarget.hasTag(TAG_CUSTOM_TRAPDOOR)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["minecraft:cardinal_direction"] != requiredFacingDirection3[direction]?.toLowerCase())
      return [0, blockAbovePermutation];
    if (!picketTargetPermutation["piki_ghosts:open"])
      return [0, blockAbovePermutation];
  } else if (picketTarget.hasTag(TAG_CUSTOM_SLAB)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (!picketTargetPermutation["piki_ghosts:double"])
      return [0, blockAbovePermutation];
  }
  if (!blockAbove)
    return [1, blockAbovePermutation];
  const blockAboveType = blockAbove.typeId;
  if (SHORT_WALL_CONNECTION.has(blockAboveType))
    return [1, blockAbovePermutation];
  else if (VANILLA_WALLS.has(blockAboveType)) {
    if (!blockAbovePermutation)
      blockAbovePermutation = blockAbove.permutation.getAllStates();
    const stateName = requiredWallConnection1[direction];
    if (!stateName)
      return [1, blockAbovePermutation];
    const blockDirection = blockAbovePermutation[stateName];
    if (blockDirection != "none")
      return [2, blockAbovePermutation];
  } else if (blockAbove.hasTag(TAG_CUSTOM_WALL)) {
    if (!blockAbovePermutation)
      blockAbovePermutation = blockAbove.permutation.getAllStates();
    const stateName = requiredWallConnection2[direction];
    if (!stateName)
      return [1, blockAbovePermutation];
    const blockDirection = blockAbovePermutation[stateName];
    if (blockDirection != 0)
      return [2, blockAbovePermutation];
  } else if (blockAboveType == "minecraft:frame" /* Frame */ || blockAboveType == "minecraft:glow_frame" /* GlowFrame */) {
    if (!blockAbovePermutation)
      blockAbovePermutation = blockAbove.permutation.getAllStates();
    if (blockAbovePermutation["facing_direction"] == 1)
      return [2, blockAbovePermutation];
  } else if (blockAboveType == "minecraft:grindstone" /* Grindstone */) {
    if (!blockAbovePermutation)
      blockAbovePermutation = blockAbove.permutation.getAllStates();
    const blockDirection = blockAbovePermutation["direction"];
    if (requiredDirection1[direction]?.includes(blockDirection))
      return [2, blockAbovePermutation];
  } else if (blockAboveType == "minecraft:wall_banner" /* WallBanner */) {
    if (!blockAbovePermutation)
      blockAbovePermutation = blockAbove.permutation.getAllStates();
    if (blockAbovePermutation["facing_direction"] == requiredFacingDirection1[direction])
      return [2, blockAbovePermutation];
  } else if (VANILLA_CAKES.has(blockAboveType)) {
    if (direction != Direction6.West)
      return [2, blockAbovePermutation];
    if (!blockAbovePermutation)
      blockAbovePermutation = blockAbove.permutation.getAllStates();
    const bites = blockAbovePermutation["bite_counter"];
    if (bites <= 1)
      return [2, blockAbovePermutation];
  } else if (VANILLA_TRAPDOOR.has(picketBlockType)) {
    if (!blockAbovePermutation)
      blockAbovePermutation = picketTarget.permutation.getAllStates();
    if (!blockAbovePermutation["open_bit"])
      return [2, blockAbovePermutation];
  } else if (SINGLE_SLABS.has(blockAboveType)) {
    if (!blockAbovePermutation)
      blockAbovePermutation = picketTarget.permutation.getAllStates();
    if (blockAbovePermutation["minecraft:vertical_half"] == "bottom")
      return [2, blockAbovePermutation];
  } else if (blockAbove.hasTag(TAG_CUSTOM_SLAB)) {
    if (!blockAbovePermutation)
      blockAbovePermutation = picketTarget.permutation.getAllStates();
    if (blockAbovePermutation["minecraft:vertical_half"] == "bottom")
      return [2, blockAbovePermutation];
    if (blockAbovePermutation["piki_ghosts:double"])
      return [2, blockAbovePermutation];
  }
  return [1, blockAbovePermutation];
}
function getCenterPost(n, s, e, w, above, blockAbovePermutation) {
  const zeroCount = (n === 0 ? 1 : 0) + (s === 0 ? 1 : 0) + (e === 0 ? 1 : 0) + (w === 0 ? 1 : 0) == 1;
  const unequalSides = n != s || w != e;
  const equalPickets = !n == !s && !s == !e && !e == !w;
  if (zeroCount || unequalSides || equalPickets)
    return true;
  if (!above)
    return false;
  const blockType = above.typeId;
  const isPostList = makesWallPost(blockType);
  if (isPostList)
    return true;
  else if (above.hasTag(TAG_CUSTOM_WALL)) {
    if (!blockAbovePermutation)
      blockAbovePermutation = above.permutation.getAllStates();
    return blockAbovePermutation["piki_ghosts:is_center_post"];
  } else if (VANILLA_WALLS.has(blockType)) {
    if (!blockAbovePermutation)
      blockAbovePermutation = above.permutation.getAllStates();
    return blockAbovePermutation["wall_post_bit"];
  } else if (TORCHES.has(blockType)) {
    if (!blockAbovePermutation)
      blockAbovePermutation = above.permutation.getAllStates();
    return blockAbovePermutation["torch_facing_direction"] == "top";
  } else if (blockType == "minecraft:chain" /* Chain */) {
    if (!blockAbovePermutation)
      blockAbovePermutation = above.permutation.getAllStates();
    return blockAbovePermutation["pillar_axis"] == "y";
  } else if (blockType == "minecraft:lantern" /* Lantern */ || blockType == "minecraft:soul_lantern" /* SoulLantern */) {
    if (!blockAbovePermutation)
      blockAbovePermutation = above.permutation.getAllStates();
    return !blockAbovePermutation["hanging"];
  } else if (VANILLA_CAKES.has(blockType)) {
    if (!blockAbovePermutation)
      blockAbovePermutation = above.permutation.getAllStates();
    const bites = blockAbovePermutation["bite_counter"];
    return bites >= 2;
  }
  return false;
}
function getPermutation(targetBlock, blockType) {
  const blockAbove = targetBlock.above();
  let [n, blockAboveStates1] = getCorrectPicketState(targetBlock, Direction6.North, blockAbove, void 0);
  let [s, blockAboveStates2] = getCorrectPicketState(targetBlock, Direction6.South, blockAbove, blockAboveStates1);
  let [e, blockAboveStates3] = getCorrectPicketState(targetBlock, Direction6.East, blockAbove, blockAboveStates2);
  let [w, blockAboveStates4] = getCorrectPicketState(targetBlock, Direction6.West, blockAbove, blockAboveStates3);
  const c = getCenterPost(n, s, e, w, blockAbove, blockAboveStates4);
  const correctPermutation = {};
  correctPermutation["piki_ghosts:north_picket"] = n;
  correctPermutation["piki_ghosts:south_picket"] = s;
  correctPermutation["piki_ghosts:east_picket"] = e;
  correctPermutation["piki_ghosts:west_picket"] = w;
  correctPermutation["piki_ghosts:is_center_post"] = c;
  correctPermutation["piki_ghosts:is_item_icon"] = false;
  return BlockPermutation6.resolve(blockType, correctPermutation);
}
function updatePermutation(block) {
  if (!block.hasTag(TAG_CUSTOM_WALL))
    return;
  system11.run(() => {
    const correctPermutation = getPermutation(block, block.typeId);
    if (correctPermutation == block.permutation)
      return;
    block.setPermutation(correctPermutation);
    blockUpdated(block);
  });
}
function processBlockAttached3(block) {
  if (VANILLA_BUTTONS.has(block.typeId)) {
    const facing = block.permutation.getState("facing_direction");
    const blockFacing = getBlockFromFace(block, facing, facing <= 1);
    if (!blockFacing || !blockFacing.hasTag(TAG_CUSTOM_WALL) && !VANILLA_WALLS.has(blockFacing.typeId))
      return;
  } else if (VANILLA_DOORS.has(block.typeId) || block.hasTag(TAG_CUSTOM_DOOR)) {
    const below = block.below();
    if (!below || !below.hasTag(TAG_CUSTOM_WALL) && !VANILLA_WALLS.has(below.typeId))
      return;
  } else
    return;
  destroy(block, true, void 0, false);
}

// scripts/modules/customFences.ts
import {
  BlockPermutation as BlockPermutation7,
  Direction as Direction7,
  system as system12
} from "@minecraft/server";
var CUSTOM_COMPONENT7 = "piki_ghosts:custom_fences";
var TAG_IS_CUSTOM_FENCE = "piki_ghosts:is_custom_fence";
var NO_FENCE_PICKET_CONNECTION_TAG = "piki_ghosts:no_fence_picket_connection";
var requiredWeirdo12 = {
  [Direction7.West]: 0,
  [Direction7.East]: 1,
  [Direction7.North]: 2,
  [Direction7.South]: 3
};
var requiredFacingDirection12 = {
  [Direction7.West]: 5,
  [Direction7.East]: 4,
  [Direction7.North]: 3,
  [Direction7.South]: 2
};
var requiredFacingDirection22 = {
  [Direction7.West]: 4,
  [Direction7.East]: 5,
  [Direction7.North]: 2,
  [Direction7.South]: 3
};
var requiredFacingDirection32 = {
  [Direction7.West]: Direction7.East,
  [Direction7.East]: Direction7.West,
  [Direction7.North]: Direction7.South,
  [Direction7.South]: Direction7.North
};
var requiredDirection12 = {
  [Direction7.West]: [0, 2],
  [Direction7.East]: [0, 2],
  [Direction7.North]: [1, 3],
  [Direction7.South]: [1, 3]
};
function getCorrectPicketState2(block, direction, blockAbovePermutation) {
  const picketTarget = getBlockFromFace(block, direction);
  if (!picketTarget)
    return [0, blockAbovePermutation];
  const picketBlockType = picketTarget.typeId;
  if (picketTarget.hasTag(TAG_IS_CUSTOM_FENCE) || VANILLA_FENCES.has(picketBlockType)) {
    return [1, blockAbovePermutation];
  } else if (picketTarget.hasTag(NO_FENCE_PICKET_CONNECTION_TAG)) {
    return [0, blockAbovePermutation];
  } else if (hasNoPicketConnection(picketBlockType)) {
    return [0, blockAbovePermutation];
  } else if (VANILLA_STAIRS.has(picketBlockType)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["weirdo_direction"] != requiredWeirdo12[direction])
      return [0, blockAbovePermutation];
  } else if (VANILLA_TRAPDOOR.has(picketBlockType)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["direction"] != requiredFacingDirection12[direction])
      return [0, blockAbovePermutation];
    if (!picketTargetPermutation["open_bit"])
      return [0, blockAbovePermutation];
  } else if (VANILLA_FENCEGATES.has(picketBlockType)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    const blockDirection = picketTargetPermutation["direction"];
    if (!requiredDirection12[direction]?.includes(blockDirection))
      return [0, blockAbovePermutation];
  } else if (PISTON_ARMS.has(picketBlockType)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["facing_direction"] != requiredFacingDirection22[direction])
      return [0, blockAbovePermutation];
  } else if (picketBlockType == "minecraft:ladder" /* Ladder */) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["facing_direction"] != requiredFacingDirection12[direction])
      return [0, blockAbovePermutation];
  } else if (picketBlockType == "minecraft:snow_layer" /* SnowLayer */) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["height"] != 8)
      return [0, blockAbovePermutation];
  } else if (picketTarget.hasTag(TAG_CUSTOM_TRAPDOOR)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (picketTargetPermutation["minecraft:cardinal_direction"] != requiredFacingDirection32[direction]?.toLowerCase())
      return [0, blockAbovePermutation];
    if (!picketTargetPermutation["piki_ghosts:open"])
      return [0, blockAbovePermutation];
  } else if (picketTarget.hasTag(TAG_CUSTOM_SLAB)) {
    const picketTargetPermutation = picketTarget.permutation.getAllStates();
    if (!picketTargetPermutation["piki_ghosts:double"])
      return [0, blockAbovePermutation];
  }
  return [1, blockAbovePermutation];
}
function getPermutation2(targetBlock, blockType) {
  let [n, blockAboveStates1] = getCorrectPicketState2(targetBlock, Direction7.North, void 0);
  let [s, blockAboveStates2] = getCorrectPicketState2(targetBlock, Direction7.South, blockAboveStates1);
  let [e, blockAboveStates3] = getCorrectPicketState2(targetBlock, Direction7.East, blockAboveStates2);
  let [w, _] = getCorrectPicketState2(targetBlock, Direction7.West, blockAboveStates3);
  const correctPermutation = {};
  correctPermutation["piki_ghosts:north_picket"] = n;
  correctPermutation["piki_ghosts:south_picket"] = s;
  correctPermutation["piki_ghosts:east_picket"] = e;
  correctPermutation["piki_ghosts:west_picket"] = w;
  correctPermutation["piki_ghosts:is_item_icon"] = false;
  return BlockPermutation7.resolve(blockType, correctPermutation);
}
function onWorldInitialize7(blockComponentRegistry) {
  blockComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT7, {
    beforeOnPlayerPlace: beforeOnPlayerPlace2
  });
}
function beforeOnPlayerPlace2(ev) {
  const { block, permutationToPlace } = ev;
  const correctPermutation = getPermutation2(block, permutationToPlace.type.id);
  ev.permutationToPlace = correctPermutation;
}
function updatePermutation2(block) {
  if (!block.hasTag(TAG_IS_CUSTOM_FENCE))
    return;
  system12.run(() => {
    const correctPermutation = getPermutation2(block, block.typeId);
    if (correctPermutation == block.permutation)
      return;
    block.setPermutation(correctPermutation);
    blockUpdated(block);
  });
}

// scripts/modules/ectoplasmWeapons.ts
var CUSTOM_COMPONENT8 = "piki_ghost:ectoplasm_weapons";
var TAG_ECTOPLASM_WEAPON = "piki_ghosts:is_ectoplasm_weapon";
var SLOWNESS_EFFECT_DURATION = 5;
var SLOWNESS_EFFECT_AMPLIFIER = 1;
function onWorldInitialize8(itemComponentRegistry) {
  itemComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT8, {
    onHitEntity: (ev) => onHitEntity(ev.itemStack, ev.hitEntity)
  });
}
function onHitEntity(itemStack, entity) {
  if (!itemStack?.hasTag(TAG_ECTOPLASM_WEAPON))
    return;
  if (!entity.matches(GHOSTS_ENTITIES2))
    return;
  entity.addEffect("minecraft:slowness" /* Slowness */, SLOWNESS_EFFECT_DURATION * 20, {
    amplifier: SLOWNESS_EFFECT_AMPLIFIER - 1,
    showParticles: true
  });
}

// scripts/modules/ectoplasmBlocks.ts
var CUSTOM_COMPONENT9 = "piki_ghosts:ectoplasm_blocks";
function onWorldInitialize9(blockComponentRegistry) {
  blockComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT9, {
    onTick: (ev) => onTick3(ev.block)
  });
}
function onTick3(block) {
  if (!block)
    return 0;
  const entities = block.dimension.getEntities({
    location: block.center(),
    families: ["ghost"],
    maxDistance: 1
  });
  for (const ghost of entities) {
    ghost.addEffect("minecraft:slowness" /* Slowness */, 20, { amplifier: 2, showParticles: false });
  }
}

// scripts/modules/spellbook.ts
import {
  EntityComponentTypes as EntityComponentTypes8,
  EquipmentSlot as EquipmentSlot7,
  ItemStack as ItemStack12
} from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
var ITEM_CUSTOM_COMPONENT = "piki_ghost:spellbook";
var forms = {
  onItemUse: new ActionFormData().title("\xA7lSPELLBOOK").body("\nChoose what you want to do.\n\n").button("\xA7l\xA7tUNLEASH GHOST \xA7r- \xA78NO COST").button("\xA7l\xA74DESTROY GHOST \xA7r- \xA785 LEVELS").button("\xA7l\xA72REVIVE GHOST \xA7r- \xA7810 LEVELS")
};
function onWorldInitialize10(itemComponentRegistry) {
  itemComponentRegistry.registerCustomComponent(ITEM_CUSTOM_COMPONENT, {
    onUse: (ev) => onUse(ev.itemStack, ev.source)
  });
}
function onUse(itemStack, player) {
  const equippable = player.getComponent(EntityComponentTypes8.Equippable);
  const leftItemStack = equippable?.getEquipment(EquipmentSlot7.Offhand);
  if (itemStack?.typeId != "piki_ghosts:spellbook" /* SpellBook */)
    return;
  if (leftItemStack?.typeId != "piki_ghosts:spirit_capsule_filled" /* SpiritCapsuleFilled */ && leftItemStack?.typeId != "piki_ghosts:silver_mirror" /* SilverMirror */)
    return;
  forms.onItemUse.show(player).then((e) => {
    const selected = e.selection;
    if (e.canceled || selected == void 0 || selected == 3)
      return;
    switch (selected) {
      case 0:
        unleashItemGhosts(leftItemStack, player);
        break;
      case 1:
        deleteItemGhosts(leftItemStack, player, true);
        break;
      case 2:
        reviveItemGhosts(leftItemStack, player, true);
        break;
    }
  });
}
function reviveItemGhosts(itemStack, player, requireXP = false) {
  if (requireXP && player.level < 10) {
    player.playSound("note.bass" /* NoteBass */);
    player.sendMessage("\xA7cYou need \xA7a10\xA7c XP levels more to revive the ghosts.");
    return;
  }
  const uniques = DP_TRAPPED_GHOSTS.getUniques(itemStack.getDynamicPropertyIds());
  for (const unqiue of uniques) {
    const typeIdKey = DP_TRAPPED_GHOSTS.getKey(unqiue, "typeId");
    const variantKey = DP_TRAPPED_GHOSTS.getKey(unqiue, "variant");
    const nameKey = DP_TRAPPED_GHOSTS.getKey(unqiue, "name");
    const typeId = itemStack.getDynamicProperty(typeIdKey);
    const vanillaId = getGhostVanillaId(typeId);
    const variantNumber = itemStack.getDynamicProperty(variantKey);
    const name = itemStack.getDynamicProperty(nameKey);
    const vanillaEvent = VARIANT_EVENTS[vanillaId]?.events?.[variantNumber];
    const entity = summon(player.dimension, vanillaId, player.location, vanillaEvent);
    if (entity)
      entity.nameTag = name ?? "";
  }
  deleteItemGhosts(itemStack, player, false);
  if (requireXP)
    player.addLevels(-10);
}
function deleteItemGhosts(itemStack, player, requireXP = false) {
  if (requireXP && player.level < 5) {
    player.playSound("note.bass" /* NoteBass */);
    player.sendMessage("\xA7cYou need \xA7a5\xA7c XP levels more to destroy the ghosts.");
    return;
  }
  const equippable = player.getComponent(EntityComponentTypes8.Equippable);
  const newItem = itemStack.typeId == "piki_ghosts:spirit_capsule_filled" /* SpiritCapsuleFilled */ ? "piki_ghosts:spirit_capsule_empty" /* SpiritCapsuleEmpty */ : "piki_ghosts:silver_mirror" /* SilverMirror */;
  equippable.setEquipment(EquipmentSlot7.Offhand, new ItemStack12(newItem));
  if (requireXP)
    player.addLevels(-5);
}
function unleashItemGhosts(itemStack, player) {
  const uniques = DP_TRAPPED_GHOSTS.getUniques(itemStack.getDynamicPropertyIds());
  for (const unqiue of uniques) {
    const typeIdKey = DP_TRAPPED_GHOSTS.getKey(unqiue, "typeId");
    const variantKey = DP_TRAPPED_GHOSTS.getKey(unqiue, "variant");
    const nameKey = DP_TRAPPED_GHOSTS.getKey(unqiue, "name");
    const typeId = itemStack.getDynamicProperty(typeIdKey);
    const variant = itemStack.getDynamicProperty(variantKey);
    const nameTag = itemStack.getDynamicProperty(nameKey);
    const entity = summon(
      player.dimension,
      typeId,
      player.location,
      variant != void 0 ? VARIANT_EVENT_PREFIX + variant : void 0
    );
    if (!entity)
      continue;
    entity.addTag("cannotCurse");
    entity.nameTag = nameTag ?? "";
  }
  deleteItemGhosts(itemStack, player, false);
}

// scripts/modules/silverArmor.ts
import { EntityComponentTypes as EntityComponentTypes9, EquipmentSlot as EquipmentSlot8 } from "@minecraft/server";
function isFullSilverArmor(player) {
  const equippable = player.getComponent(EntityComponentTypes9.Equippable);
  if (!equippable)
    return false;
  if (equippable.getEquipment(EquipmentSlot8.Chest)?.typeId != "piki_ghosts:silver_chestplate" /* SilverChestplate */)
    return false;
  if (equippable.getEquipment(EquipmentSlot8.Legs)?.typeId != "piki_ghosts:silver_leggings" /* SilverLeggings */)
    return false;
  if (equippable.getEquipment(EquipmentSlot8.Head)?.typeId != "piki_ghosts:silver_helmet" /* SilverHelmet */)
    return false;
  if (equippable.getEquipment(EquipmentSlot8.Feet)?.typeId != "piki_ghosts:silver_boots" /* SilverBoots */)
    return false;
  return true;
}
function onTick4(player) {
  const isEquipped = isFullSilverArmor(player);
  if (isEquipped)
    player.addTag("hauntProtection");
  else
    player.removeTag("hauntProtection");
}

// scripts/modules/customFenceGate.ts
import {
  Direction as Direction8
} from "@minecraft/server";
var TAG_CUSTOM_FENCEGATE = "piki_ghosts:is_custom_fencegate";
var CUSTOM_COMPONENT10 = "piki_ghosts:custom_fencegate";
function isInWallBit(block, blockPermutation) {
  if (!blockPermutation)
    blockPermutation = block.permutation;
  const cardinalDirection = toTitleCase(blockPermutation.getState("minecraft:cardinal_direction"));
  const hasWallBlockChecker = (blocks) => blocks.some((b) => b && VANILLA_WALLS.has(b.typeId));
  return cardinalDirection === Direction8.North || cardinalDirection === Direction8.South ? hasWallBlockChecker([block.east(), block.west()]) : hasWallBlockChecker([block.north(), block.south()]);
}
function onWorldInitialize11(blockComponentRegistry) {
  blockComponentRegistry.registerCustomComponent(CUSTOM_COMPONENT10, {
    onPlayerInteract: onPlayerInteract3,
    beforeOnPlayerPlace: beforeOnPlayerPlace3
  });
}
function onPlayerInteract3(ev) {
  const { block, face } = ev;
  const cardinalRotation = toTitleCase(block.permutation.getState("minecraft:cardinal_direction"));
  let newCardinalDirection;
  if (cardinalRotation == Direction8.North || cardinalRotation == Direction8.South) {
    newCardinalDirection = face == Direction8.South ? Direction8.North : Direction8.South;
  } else {
    newCardinalDirection = face == Direction8.West ? Direction8.East : Direction8.West;
  }
  const isOpen = block.permutation.getState("piki_ghosts:open");
  let newPermutation = block.permutation.withState("piki_ghosts:open", !isOpen);
  newPermutation = newPermutation.withState("minecraft:cardinal_direction", newCardinalDirection.toLowerCase());
  block.setPermutation(newPermutation);
  block.dimension.playSound(isOpen ? "open.fence_gate" /* OpenFenceGate */ : "close.fence_gate" /* CloseFenceGate */, block.location);
}
function beforeOnPlayerPlace3(ev) {
  let { permutationToPlace, block } = ev;
  permutationToPlace = permutationToPlace.withState(
    "piki_ghosts:in_wall_bit",
    isInWallBit(block, permutationToPlace)
  );
  ev.permutationToPlace = permutationToPlace;
}
function processBlockAttached4(block) {
  if (VANILLA_BUTTONS.has(block.typeId)) {
    const facing = block.permutation.getState("facing_direction");
    const blockFacing = getBlockFromFace(block, facing, facing <= 1);
    return blockFacing && blockFacing.hasTag(TAG_CUSTOM_FENCEGATE);
  } else if (VANILLA_PRESSURE_PLATES.has(block.typeId)) {
    const below = block.below();
    return below && below.hasTag(TAG_CUSTOM_FENCEGATE);
  }
}
function updatePermutation3(block) {
  if (!block.hasTag(TAG_CUSTOM_FENCEGATE))
    return;
  const permutation = block.permutation.withState("piki_ghosts:in_wall_bit", isInWallBit(block));
  block.setPermutation(permutation);
}

// scripts/main.ts
world5.afterEvents.playerBreakBlock.subscribe((ev) => {
  const { block } = ev;
  blockUpdated(block);
});
world5.beforeEvents.playerBreakBlock.subscribe((ev) => {
  const { block, dimension, itemStack, player } = ev;
  destroyDoor(block, player);
  dropLoot(block, player);
});
world5.afterEvents.entityHitEntity.subscribe((ev) => {
  const { damagingEntity, hitEntity } = ev;
  onEntityHurt(damagingEntity, hitEntity);
});
world5.afterEvents.projectileHitEntity.subscribe((ev) => {
  const { dimension, hitVector, location, projectile, source } = ev;
  const hitInformation = ev.getEntityHit();
  const hitEntity = hitInformation.entity;
  onEntityHurt(source, hitEntity);
});
world5.beforeEvents.worldInitialize.subscribe((ev) => {
  const { blockComponentRegistry, itemComponentRegistry } = ev;
  onWorldInitialize7(blockComponentRegistry);
  onWorldInitialize4(blockComponentRegistry);
  onWorldInitialize6(blockComponentRegistry);
  onWorldInitialize5(blockComponentRegistry);
  onWorldInitialze(blockComponentRegistry);
  onWorldInitialize9(blockComponentRegistry);
  onWorldInitialize2(itemComponentRegistry);
  onWorldInitialize8(itemComponentRegistry);
  onWorldInitialize3(blockComponentRegistry);
  onWorldInitialize10(itemComponentRegistry);
  onWorldInitialize(blockComponentRegistry);
  onWorldInitialize11(blockComponentRegistry);
});
world5.afterEvents.playerPlaceBlock.subscribe((ev) => {
  const { block } = ev;
  processBlockAttached(block);
  processBlockAttached2(block);
  processBlockAttached3(block);
  processBlockAttached4(block);
  blockUpdated(block);
});
world5.beforeEvents.playerInteractWithBlock.subscribe((ev) => {
  const { block, isFirstEvent, itemStack } = ev;
  if (isFirstEvent) {
    onBlockInteract(block, itemStack);
    onPlayerInteractBlock(ev);
    blockUpdated(block);
  }
});
world5.afterEvents.blockExplode.subscribe((ev) => {
  const { block } = ev;
  destroyDoor(block);
  dropLoot(block);
  blockUpdated(block);
});
world5.beforeEvents.explosion.subscribe((ev) => {
  for (const block of ev.getImpactedBlocks()) {
    destroyCapsuleBlock(block);
  }
});
world5.afterEvents.pistonActivate.subscribe((ev) => {
  const { block, isExpanding, piston } = ev;
  const blocksAttached = piston.getAttachedBlocks();
  const hasAttached = blocksAttached.length > 0;
  const rotation = block.permutation.getState("facing_direction");
  const facingBlock = getBlockFromFace(block, rotation);
  const pushedBlocks = [...blocksAttached];
  const finalBlocks = [];
  if (hasAttached) {
    for (const blockAttached of blocksAttached) {
      const targetBlock = getBlockFromFace(blockAttached, rotation, !isExpanding);
      if (!targetBlock)
        continue;
      if (pushedBlocks.some((b) => Vector3Utils.equals(b.location, targetBlock.location)))
        continue;
      finalBlocks.push(targetBlock);
    }
  } else {
    if (facingBlock && !pushedBlocks.some((b) => Vector3Utils.equals(b.location, facingBlock.location)))
      finalBlocks.push(facingBlock);
  }
  finalBlocks.push(...blocksAttached);
  for (const pushedBlock of finalBlocks) {
    const lastPositionBlock = getBlockFromFace(pushedBlock, rotation, true);
    const lastLocation = lastPositionBlock?.location;
    waitAfterMove(pushedBlock, () => {
      updatePermutation(pushedBlock);
      updatePermutation2(pushedBlock);
      onPistonPush2(pushedBlock, lastLocation);
      onPistonPush(pushedBlock, lastLocation);
      destroyDoor(pushedBlock, void 0, lastPositionBlock);
      blockUpdated(pushedBlock);
    });
  }
});
world5.afterEvents.buttonPush.subscribe((ev) => {
  const { block } = ev;
  processBlockAttached(block);
  processBlockAttached2(block);
  processBlockAttached4(block);
});
world5.afterEvents.pressurePlatePush.subscribe((ev) => {
  const { block } = ev;
  processBlockAttached(block);
  processBlockAttached2(block);
  processBlockAttached4(block);
});
world5.afterEvents.entitySpawn.subscribe((ev) => {
  const { entity } = ev;
  onEntitySpawn(entity);
});
system13.runInterval(() => {
  for (const player of world5.getAllPlayers()) {
    onTick4(player);
  }
});
function blockUpdated(block) {
  system13.runTimeout(() => {
    for (const direction of Object.keys(Direction9)) {
      const targetBlock = getBlockFromFace(block, direction);
      if (!targetBlock)
        return;
      updatePermutation(targetBlock);
      updatePermutation2(targetBlock);
      updatePermutation3(targetBlock);
    }
  }, 1);
}
export {
  blockUpdated
};

//# sourceMappingURL=../../../../dist/debug/main.js.map
