import { world, ItemStack, MinecraftEntityTypes, DynamicPropertiesDefinition, ItemTypes } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

const age1 = ["Getting Started", "Down to Basics", "Planks", "Crafting Enigma", "Firestarter §u3x", "Drying Express §u3x", "Primitive Farming §u3x", "Wooden Crucible", "Manual Sifting", "Flint Upgrades §u3x", "Paper Intermission §u4x", "Hold My Fluids §u2x", "Leather Processing §u3x", "A Needed Upgrade", "Living Luxury §u3x", "Time to Mine!", "Rock Collector §u4x", "Normal Cooking", "Crushing Results §u3x", "Hot Rocks", "Brick Maker §u2x", "Little Clay Turner §u3x", "Clay Cup", "Clay Basin", "Clay Steamer", "Porcelain Process §u3x", "Muddy Porcelain", "Primal Instincts"]
const age1image = ["textures/items/redpetal", "textures/blocks/_trees/bum_lemon_sapling", "textures/items/makeshiftaxe", "textures/blocks/crafting_table_side", "textures/items/flint", "textures/items/dried leaf", "textures/items/torchflower_seeds", "textures/items/wooden_shavings", "textures/items/makeshiftsieve", "textures/items/flint", "textures/items/paper", "textures/items/fluidbladder", "textures/items/leather", "textures/items/parts/stone/stone_blueprint", "textures/items/diamond_shard", "textures/items/wood_pickaxe", "textures/items/pebble", "textures/blocks/furnace_front_on", "textures/items/obsidianpestle", "textures/items/flint_and_steel", "textures/items/brick", "textures/items/clay_ball", "textures/items/bum_mug", "textures/items/brewer_pottery_sherd", "textures/items/burn_pottery_sherd", "textures/items/dye_powder_white_new", "textures/items/plantfiber", "textures/items/bone"]
const age1desc = [
    "§fWelcome to Progression Craft! Start by exploring your nearby surroundings and start getting familiar with your environment! (Also with the lack of crafting recipes :) \nReturn Quest items to the offering box! §qBring back any colored petal or Cactus!"
    , "Go ahead, chop a tree and craft some planks! Or try to at least. :) Ok, now you'll have to put some more work into it. Create a Chopping Block! \nReturn Quest items to the offering box! Bring back a §qChopping Block"
    , "Now with your chopping block, strip your logs, place them on the chopping block, and then chop it using your axe! \nReturn Quest items to the offering box! Bring back any §qvanilla planks!"
    , "Create a crafting table! Specifically a Makeshift one. You will be able to create less but at least you'll have a crafting table!Return the §qMakeshift Table§r to the offering box! §hThe Next 4 Quests have been unlocked!"
    , "Create a Wooden Crucible! Perfect for holding liquids and can be used to wash and tan hides! Return the §qWooden Crucible§r to the Offering Box!"
    , "Tired of old primal tools, with a sifter you cant get flint and salt efficiently and effectively. Return the §qmakeshift sieve§r to the Offering Box. §hThe Next 5 Quests have been unlocked!"
    , "Finally, you have enough materials to upgrade your crafting table! Make an §qAdvanced Makeshift Crafting Table§r and return it to the Offering Box!"
    , "Time to go mining! This time no stone pickaxe immediately. Grab your wooden pickaxe and go scavenging! Return the §qWooden Pickaxe§r to the Offering Box!"
    , "Make a Furnace! (I can't make the furnace recipe that hard, due to natural gen. :( ) Return the §qFurnace§r back to the Offering Box."
    , "Combine previously gathered materials to create the perfect cooking surface, Hot Rocks! With this you can cook clay items on this! Return the §qHot Rocks§r back to the Offering Box."
    , "Make a mug. Perfect for tea and coffee! Return the §qMug§r back to the Offering Box!"
    , "Onto the Clay Basin! Create the basin for our future clay steamer! It'll have the perfect cooking environment for porcelain! To create terracotta just place a clay block ontop of the hot rocks! Return the §qClay Basin§r back to the Offering Box!"
    , "Now you will create the Clay Steamer itself. Once made place the Clay Steamer on the Clay Basin. Make sure the Clay Basin is put on Hot Rocks. Fill the Clay Basin with water using your full fluid bladder. The basin will slowly run out of water while creating steam. During this time the Steamer will be active and can cook both bricks and porcelain! Return the §qClay Steamer§r back to the Offering Box"
    , "Create the muddy version of Porcelain Bricks! Good for makeshift ages. Return the §qThatch Porcelain Bricks§r to the offering box!"
    , "Tired of your wooden tools and being stuck in the pre metals ages? Upgrade your table to get access to stone tools! Return the §qPrimal Table§r to the offering box!"]
const rewards = ["Lemon", "Grapes", "Pebble", "XP", "XP", "Dropper (For storage)", "Roasted Stuffed Beegroot!", "XP", "Coal", "Obsidian Dagger", "Coffee Beans", "Light Blue Terracotta", "Red Terracotta", "Rock Salt Lamp", "Cake!"]
const splitquests = ["Campfire Base", "Charcoal", "Lit", "Drying Rack", "Crunchy Cattails", "Drying Challenge", "A hoe?", "Grown or Pillaged", "Thatch", "Basic Flint", "Flint Scraper", "Durability Increase", "Sugarcane", "Paper", "Writtable Books!", "Paper: Challenge", "Fluid Bladder", "Full", "Scraping Hide", "A Tanned Wash", "Leather!", "Upgrade: Wood Tools", "Upgrade: Drying Rack", "Upgrade: Inventory Space", "Andesite", "Deepslate", "Tuff", "Hot Stuff", "Pressing Matters", "Powdered Salt", "Dyeing", "Muddy Frames", "Brick", "Rope", "Mechanical Working", "Turntable", "Amethyst", "Porcelain", "Porcelain Bricks"]
const splitquestsimage = ["textures/items/campfireitem", "textures/items/charcoal", "textures/items/apple_charcoal", "textures/blocks/ladder", "textures/items/cattail", "textures/items/kelp", "textures/items/stone_hoe", "textures/items/wheat", "textures/items/thatch", "textures/items/flint", "textures/items/flintscraper", "textures/items/flintaxe", "textures/items/reeds", "textures/items/paperpulp", "textures/items/book_portfolio", "textures/items/lantern", "textures/items/fluidbladder", "textures/items/fullfluidbladder", "textures/skins/scraped", "textures/skins/tanned", "textures/items/leather", "textures/items/wood_sword", "textures/items/dryingrackupgrade", "textures/bp/backpack", "textures/blocks/stone_andesite", "textures/blocks/deepslate/cobbled_deepslate", "textures/blocks/tuff", "textures/items/magma_cream", "textures/items/pestle", "textures/items/pinksalt", "textures/items/dye_powder_purple", "textures/items/wheat", "textures/items/brick", "textures/items/rope", "textures/items/woodgear", "textures/items/bum_coffee_brew", "textures/items/amethyst_shard", "textures/items/porcleinclay", "textures/items/porclein"]
const splitquestsdesc = ["You need to bring some heat into this situation! Fire is good. A permanent fire is also really good! Start off by creating the campfire base! Return the §qcampfire base§r to the offering box!"
    , "To start this fire place some more logs inside! You need charcoal to help keep the kindling permanently burning. In order to get charcoal, set a block of Woodchips or Pine Needles on fire using a fire starter flint in your offhand and tinder in your main hand! Return the §qmini charcoal§r to the offering box!",
    "Now pile on 3 logs, add kindling, and light with a torch! Now you've got the fire started, quick cook an apple beyond eating! Return the §qCharcoal Apple§r to the offering box!",
    "Create a drying rack in order to 'sunbake' some of your items. Its a way to apply heat when you don't have any. Return the §qDrying Rack§r to the offering box!",
    "Put that Drying Rack to good use; Create Dried Cattails! Durable and waterproof, perfect for holding liquids! Return a §qDried Cattail§r to the offering box!",
    "Challenge Time! Hopefully you are near an ocean. Drying Racks are especially useful for drying things that you probably don't want to waste fuel on in other drying methods. §qDry a piece of Kelp§r and bring it back to the offering box!",
    "Start Farming you will be needing some wheat! Primitive Humans do not know how to make a hoe yet, you will have to create some farmland manually! Return the §qfarmland§r to the offering box!",
    "Grow Some Wheat, you'll probably need more than 1. Or you could go pillage a village. Return the §qwheat§r to the offering box!",
    "Thatch! Create some thatch with your acquired wheat and dried cattails from the previous questlines! Return the §qthatch§r to the offering box!",
    "Gather Flint to upgrade from your makeshift items. You can gather flint traditionally or through the sieve! Return the §qflint§r to the offering box! §hIf this quest has not unlocked complete the Firestarter quest set!",
    "Make the flint scraper! This tool allows the stripping of bark without using durability and is neccessary in making certain items! Return the §qflint scraper§r to the offering box! ",
    "Tired of your makeshift axe breaking? Create a flint one! Return the §qFlint Axe§r to the offering box!",
    "Sugarcanes important for paper, gather some! Return the §qSugarcane§r to the offering box! §hIf this quest has not unlocked complete the Drying Express quest set!",
    "Dry the paper pulp made from Sugarcane! Return the §qPaper§r to the offering box!",
    "Where are you going to store all the recipe you will learn and have learned? In a imaginary book of course. Return a §qbook and quill§r to the offering box!",
    "Create a Paper Lantern! It should be significantly easier to create than that book and quill! Return a §qpaper lantern§r to the offering box!",
    "You don't quite have access to iron or a bucket yet so we will have to do with primitive containers. Create a fluid bladder capable of holding water! Return the §qfluid bladder§r to the offering box! (Whales will drop blubber!) §hIf this quest has not unlocked complete the Primitive Farming quest set!",
    "Now fill the fluid bladder up with squeezed liquids of the cattail! (This is my alternative since we don't actually have custom bucket features yet...) Return the §qfull fluid bladder§r to the offering box!",
    "Scrape that hide! Use flint as easy and disposable scrapers! Return the §qscraped hide§r to the offering box! §hIf this quest has not unlocked complete the Flint Upgrades quest set!",
    "Using the Scrape hide wash it! Fill your wooden crucible with your full fluid bladder. Then either in a separate crucible or after you've washed all your hide, craft tannis, the component capable of tanning the hide. Then dip the washed hide into the tannis water! Return a §qtanned hide§r to the offering box!",
    "Finally Salt your hide and leave out to dry! Return the §qleather§r to the offering box!",
    "Tired of creating flint tools? Create some wooden ones! Return a §qWooden Sword§r to the offering box! §hIf this quest has not unlocked complete the Paper Intermission quest set!",
    "Drying Rack taking too long? Create a drying rack upgrade! Supply it with powdered pink salt to cut drying time in half! Return the §qDrying Rack Upgrade§r to the offering box!",
    "Have you ran out of inventory space? Create a backpack to hold some of that stuff! Return the §qSmall Backpack§r to the offering box!",
    "Grab some Andesite! A crucial component to many of our stone contraptions! Find in your nearest cave! Return the §qAndesite§r to the offering box! §hIf this quest has not unlocked complete the Hold My Fluids quest set!",
    "Grab some Deepslate! Found lower in the world, you're bound to find plenty of other things as well! Return the §qCobbled Deepslate§r to the offering box!",
    "Grab some Tuff! Found alongside deepslate! Return the §qTuff§r to the offering box!",
    "Grab some Magma Block! Found in either ruined nether portals or in your nearest ocean. Return the §qMagma Block§r to the offering box!",
    "Create an Andesite Mortar. For the mortar to work you will also need the pestle. Create either the normal pestle or an obsidian tipped one. Return the §qAndesite Mortar§r to the Offering Box! §hIf this quest has not unlocked complete the Leather Processing quest set!",
    "You will appreciate the salt. Crush some Rock Salt into powdered salt using the Andesite Mortar! Return the §qPowdered Pink Salt§r to the offering box!",
    "Finally access to dyes! Create colorful combinations! Return §qPurple Dye§r to the offering box!",
    "You'll need to mold the clay first. First make a Packed Mud Frame! Return the §qPacked Mud Frame§r to the offering box! §hIf this quest has not unlocked complete the Living Luxury quest set!",
    "Place your frame ontop of the hot rocks and then place clay inside. Soon bricks will pop out! Return the §qBrick§r to the offering box!",
    "Create a rope! Something that can withold some force and can turn some gears! I know how much you love twine! Return the §qRope§r to the offering box! §hIf this quest has not unlocked complete the Rock Collector quest set!",
    "Make a Mechanical Crank. Create a gear from glue, by smelting leather, and the rope in order to start your first manual power source! Return the §qMechanical Crank§r to the offering box!",
    "Finally create a turntable! The Turntabel is used to make smaller clay items! You will have to cook those items on the hot rocks! To use the the Turntable put a block of clay on top of the Turntable and put the mechanical crank next to the Turntable. Return the §qTurnTable§r to the offering box!",
    "The main component to porcelain is Amethyst. Hopefully you find some in the underground! Otherwise, craft it using some dyes. Return the §qAmethyst Shard§r to the offering box! §hIf this quest has not unlocked complete the Crushing Results quest set!",
    "Now that you have Amethyst, gather the rest of the materials and create porcelain clay! Return the §qPorcelain Clay§r to the offering box!",
    "Using your porcelain clay, cook it in your basin/steamer combo! Then combine together with white cement to create the bricks! Return the §qPorcelain Bricks§r to the offering box!"]
const splitquestsreward = ["Oak Log", "Mini Charcoal", "Apple", "XP", "Apple Chip", "Sun Hat", "Flint", "Pepper Seeds", "XP", "Flint", "XP", "Slime Berserker Helmet", "Wooden Spear", "XP", "Washed Hide", "Slime Boots", "XP", "Potted Cattail", "Chili", "Makeshift Sieve", "Leather", "XP", "Pink Rock Salt", "Traveller's Backpack (Cosmetic)", "XP", "XP", "Torch", "Torch", "Sweet Berry", "Glow Berry", "Nimberry", "XP", "Popcorn", "Twine", "Twine", "Clay", "Budding Amethyst", "Bone", "Calcite"]


world.afterEvents.itemUse.subscribe((eventData) => {

    const itemTypeId = eventData.itemStack.typeId
    if (itemTypeId == "pcr:questbook") {
        eventData.source.runCommandAsync('scoreboard objectives add quests dummy')
        eventData.source.runCommandAsync('scoreboard objectives add questfin dummy')
        eventData.source.runCommandAsync('scoreboard objectives add quest1 dummy')
        eventData.source.runCommandAsync('scoreboard objectives add quest2 dummy')
        eventData.source.runCommandAsync('scoreboard objectives add quest3 dummy')
        eventData.source.runCommandAsync('scoreboard players add @s quests 0')
        eventData.source.runCommandAsync('scoreboard players add @s questfin 1')
        eventData.source.runCommandAsync('scoreboard players add @s quest1 0')
        eventData.source.runCommandAsync('scoreboard players add @s quest2 0')
        eventData.source.runCommandAsync('scoreboard players add @s quest3 0')
        questmenu(eventData.source)

    }
})

function questmenu(player) {
    const form = new ActionFormData()
    form.title("Quest Book!")
    form.body("Select an Age!")
    form.button("Age 1", "textures/items/redbook")
    form.button("Age 2 WIP", "textures/items/yellowbook")
    form.show(player).then((response) => {
        if (response?.selection === 0) {
            showquestlist(player)
        }
        else if (response?.selection === 1) {
            player.runCommandAsync('say Still in Progress!')
        }
    })
}

function showquestlist(player) {
    const form = new ActionFormData()
    form.title("Age 1")
    for (let quests in age1) {
        form.button(age1[quests], age1image[quests])
    }
    form.show(player).then((response) => {
        if (response?.selection === 0) {
            const questnum = 0
            const form = new ActionFormData()
            form.title(age1[questnum])
            form.body(age1desc[questnum] + "\n§gRewards: " + rewards[questnum])
            if (world.scoreboard.getObjective('quests').getScore(player) == 0) {
                form.button("Claim Quests")
                form.show(player).then((response) => {
                    if (response?.selection === 0) {
                        player.runCommandAsync('scoreboard players add @s quests 1')
                        player.runCommandAsync('give @s pcr:offeringbox')
                    }
                })
            }
            else if (world.scoreboard.getObjective('quests').getScore(player) == 1) {
                form.button("In Progress")
                form.show(player)
            }
            else if (world.scoreboard.getObjective('quests').getScore(player) == 2) {
                form.button("Claim Rewards")
                form.show(player).then((response) => {
                    if (response?.selection === 0) {
                        player.runCommandAsync('scoreboard players add @s quests 1')
                        givecom("bumble:lemon", 1, player)
                        player.runCommandAsync('scoreboard players add @s questfin 1')
                    }
                })
            }
            else if (world.scoreboard.getObjective('quests').getScore(player) > 2) {
                form.button("Finished!")
                form.show(player)
            }
        }
        else if (response?.selection === 1) {
            questlabel(1, 1, player, "bumble:grapes")
        }
        else if (response?.selection === 2) {
            questlabel(2, 2, player, "rns:pebble")
        }
        else if (response?.selection === 3) {
            questlabel(3, 3, player, "air")
        }
        else if (response?.selection === 4) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(0, 2, player, 1, 4)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 5) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(3, 5, player, 2, 5)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 6) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(6, 8, player, 3, 6)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 7) {
            questlabel(7, 4, player, "air")
        }
        else if (response?.selection === 8) {
            questlabel(8, 5, player, "dropper")
        }
        else if (response?.selection === 9) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(9, 11, player, 4, 9)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 10) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(12, 15, player, 5, 10)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 11) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(16, 17, player, 6, 11)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 12) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(18, 20, player, 7, 12)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 13) {
            questlabel(13, 6, player, "rns:roastedstuffedbeetroot")
        }
        else if (response?.selection === 14) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(21, 23, player, 8, 14)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 15) {
            questlabel(15, 7, player, "air")
        }
        else if (response?.selection === 16) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(24, 27, player, 9, 16)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 17) {
            questlabel(17, 8, player, "coal")
        }
        else if (response?.selection === 18) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(28, 30, player, 10, 18)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 19) {
            questlabel(19, 9, player, "hax:obsidian_dagger")
        }
        else if (response?.selection === 20) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(31, 32, player, 11, 20)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 21) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(33, 35, player, 12, 21)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 22) {
            questlabel(22, 10, player, "bumble:coffee_beans")
        }
        else if (response?.selection === 23) {
            questlabel(23, 11, player, "light_blue_glazed_terracotta")
        }
        else if (response?.selection === 24) {
            questlabel(24, 12, player, "red_glazed_terracotta")
        }
        else if (response?.selection === 25) {
            if (world.scoreboard.getObjective('questfin').getScore(player) >= 4) {
                showsplitquest(36, 38, player, 13, 25)
            }
            else {
                player.runCommandAsync('say Locked!')
            }
        }
        else if (response?.selection === 26) {
            questlabel(26, 13, player, "rns:rocksaltlamp")
        }
        else if (response?.selection === 27) {
            questlabel(27, 14, player, "cake")
        }
    })
}

function questlabel(questnum, amount, player, reward) {
    const form = new ActionFormData()
    form.title(age1[questnum])
    form.body(age1desc[amount] + "\n§gRewards: " + rewards[amount])
    if (world.scoreboard.getObjective('quests').getScore(player) == amount * 3 && world.scoreboard.getObjective('questfin').getScore(player) > 0) {
        form.button("Claim Quests")
    }
    else if (world.scoreboard.getObjective('quests').getScore(player) == amount * 3 + 1 && world.scoreboard.getObjective('questfin').getScore(player) > 0) {
        form.button("In Progress")
    }
    else if (world.scoreboard.getObjective('quests').getScore(player) == amount * 3 + 2 && world.scoreboard.getObjective('questfin').getScore(player) > 0) {
        form.button("Claim Rewards")
    }
    else if (world.scoreboard.getObjective('quests').getScore(player) > 3 * amount) {
        form.button("Finished!")
    }
    else {
        form.button("Locked")
    }
    form.button("Back")
    form.show(player).then((response) => {
        if (world.scoreboard.getObjective('quests').getScore(player) == amount * 3 && world.scoreboard.getObjective('questfin').getScore(player) > 0 && response?.selection === 0) {
            player.runCommandAsync('scoreboard players add @s quests 1')
            showquestlist(player)
        }
        if (world.scoreboard.getObjective('quests').getScore(player) == amount * 3 + 2 && world.scoreboard.getObjective('questfin').getScore(player) > 0 && response?.selection === 0) {
            player.runCommandAsync('scoreboard players add @s quests 1')
            givecom(reward, 1, player)
            player.runCommandAsync('scoreboard players add @s questfin 1')
        }
        else if (response?.selection === 1) {
            showquestlist(player)
        }
    })
}

function givecom(item, amount, player) {
    player.runCommandAsync('give @s ' + item + " " + amount)
    player.runCommandAsync('summon xp_orb')
}

//Amount should stack up with the same quest set lines!!

function showsplitquest(start, end, player, questset, settitle) {
    const form = new ActionFormData()
    form.title(age1[settitle])
    let backamount = 0
    for (let i = start; i < end + 1; i++) {
        form.button(splitquests[i], splitquestsimage[i])
        backamount += 1
    }
    form.button("Back")
    form.show(player).then((response) => {
        if (response?.selection === backamount) {
            showquestlist(player)
        }
        if (questset === 1) {
            if (response?.selection === 0) {
                splitquest(1, 1, player, "log", 12, 1, 1, 0, 2, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(2, 2, player, "fuelov:mini_charcoal", 12, 1, 1, 0, 2, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(3, 3, player, "apple", 12, 1, 1, 0, 2, settitle)
            }
        }
        else if (questset === 2) {
            if (response?.selection === 0) {
                splitquest(4, 1, player, "air", 12, 2, 2, 3, 5, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(5, 2, player, "rns:applechip", 12, 2, 2, 3, 5, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(6, 3, player, "c8164:hat_sun", 12, 2, 2, 3, 5, settitle)
            }
        }
        else if (questset === 3) {
            if (response?.selection === 0) {
                splitquest(7, 1, player, "air", 12, 3, 3, 6, 8, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(8, 2, player, "air", 12, 3, 3, 6, 8, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(9, 3, player, "air", 12, 3, 3, 6, 8, settitle)
            }
        }
        else if (questset === 4) {
            if (response?.selection === 0) {
                splitquest(10, 4, player, "flint", 18, 1, 4, 9, 11, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(11, 5, player, "air", 18, 1, 4, 9, 11, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(12, 6, player, "hax:slime_berserker_helmet", 18, 1, 4, 9, 11, settitle)
            }
        }
        else if (questset === 5) {
            if (response?.selection === 0) {
                splitquest(13, 4, player, "hax:wood_spear", 18, 2, 5, 12, 15, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(14, 5, player, "air", 18, 2, 5, 12, 15, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(15, 6, player, "add:washed_hide", 18, 2, 5, 12, 15, settitle)
            }
            else if (response?.selection === 3) {
                splitquest(16, 7, player, "hax:slime_boots", 18, 2, 5, 12, 15, settitle)
            }
        }
        else if (questset === 6) {
            if (response?.selection === 0) {
                splitquest(17, 4, player, "air", 18, 3, 6, 16, 17, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(18, 5, player, "bumble:potted_cattail", 18, 3, 6, 16, 17, settitle)
            }
        }
        else if (questset === 7) {
            if (response?.selection === 0) {
                splitquest(19, 7, player, "bumble:chili", 18, 1, 7, 18, 20, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(20, 8, player, "btb:makeshiftsieve", 18, 1, 7, 18, 20, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(21, 9, player, "leather", 18, 1, 7, 18, 20, settitle)
            }
        }
        else if (questset === 8) {
            if (response?.selection === 0) {
                splitquest(22, 8, player, "air", 21, 2, 8, 21, 23, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(23, 9, player, "rns:pinkrocksalt", 21, 2, 8, 21, 23, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(24, 10, player, "c8164:backpack_travelling", 21, 2, 8, 21, 23, settitle)
            }
        }
        else if (questset === 9) {
            if (response?.selection === 0) {
                splitquest(25, 6, player, "air", 24, 3, 9, 24, 27, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(26, 7, player, "air", 24, 3, 9, 24, 27, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(27, 8, player, "torch", 24, 3, 9, 24, 27, settitle)
            }
            else if (response?.selection === 3) {
                splitquest(28, 9, player, "torch", 24, 3, 9, 24, 27, settitle)
            }
        }
        else if (questset === 10) {
            if (response?.selection === 0) {
                splitquest(29, 10, player, "sweet_berries", 27, 1, 10, 28, 30, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(30, 11, player, "glow_berries", 27, 1, 10, 28, 30, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(31, 12, player, "rns:nimberry", 27, 1, 10, 28, 30, settitle)
            }
        }
        else if (questset === 11) {
            if (response?.selection === 0) {
                splitquest(32, 11, player, "air", 30, 2, 11, 31, 32, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(33, 12, player, "bumble:popcorn", 30, 2, 11, 31, 32, settitle)
            }
        }
        else if (questset === 12) {
            if (response?.selection === 0) {
                splitquest(34, 10, player, "sev:twine", 30, 3, 12, 33, 35, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(35, 11, player, "sev:twine", 30, 3, 12, 33, 35, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(36, 12, player, "clay", 30, 3, 12, 33, 35, settitle)
            }
        }
        else if (questset === 13) {
            if (response?.selection === 0) {
                splitquest(37, 13, player, "budding_amethyst", 39, 1, 13, 36, 38, settitle)
            }
            else if (response?.selection === 1) {
                splitquest(38, 14, player, "bone", 39, 1, 13, 36, 38, settitle)
            }
            else if (response?.selection === 2) {
                splitquest(39, 15, player, "calcite", 39, 1, 13, 36, 38, settitle)
            }
        }
    })
}

function splitquest(questnum, amount, player, reward, requirement, questset, returnquestset, start, end, settitle) {
    const form = new ActionFormData()
    form.title(splitquests[questnum - 1])
    form.body(splitquestsdesc[questnum - 1] + "\n§gRewards: " + splitquestsreward[questnum - 1])
    if (questset === 1) {
        if (world.scoreboard.getObjective('quest1').getScore(player) == amount * 3 - 3 && world.scoreboard.getObjective('quests').getScore(player) >= requirement) {
            form.button("Claim Quests")
        }
        else if (world.scoreboard.getObjective('quest1').getScore(player) == amount * 3 - 2 && world.scoreboard.getObjective('quests').getScore(player) >= requirement) {
            form.button("In Progress")
        }
        else if (world.scoreboard.getObjective('quest1').getScore(player) == amount * 3 - 1 && world.scoreboard.getObjective('quests').getScore(player) >= requirement) {
            form.button("Claim Rewards")
        }
        else if (world.scoreboard.getObjective('quest1').getScore(player) > 3 * amount - 3) {
            form.button("Finished!")
        }
        else {
            form.button("Locked")
        }
        form.button("Back")
        form.show(player).then((response) => {
            if (world.scoreboard.getObjective('quest1').getScore(player) == amount * 3 - 3 && world.scoreboard.getObjective('quests').getScore(player) >= requirement && response?.selection === 0) {
                player.runCommandAsync('scoreboard players add @s quest1 1')
                showsplitquest(start, end, player, returnquestset, settitle)
            }
            if (world.scoreboard.getObjective('quest1').getScore(player) == amount * 3 - 1 && world.scoreboard.getObjective('quests').getScore(player) >= requirement && response?.selection === 0) {
                player.runCommandAsync('scoreboard players add @s quest1 1')
                givecom(reward, 1, player)
                player.runCommandAsync('scoreboard players add @s questfin 1')
                showsplitquest(start, end, player, returnquestset, settitle)
            }
            else if (response?.selection === 1) {
                showsplitquest(start, end, player, returnquestset, settitle)
            }
        })
    }
    else if (questset === 2) {
        if (world.scoreboard.getObjective('quest2').getScore(player) == amount * 3 - 3 && world.scoreboard.getObjective('quests').getScore(player) >= requirement) {
            form.button("Claim Quests")
        }
        else if (world.scoreboard.getObjective('quest2').getScore(player) == amount * 3 - 2 && world.scoreboard.getObjective('quests').getScore(player) >= requirement) {
            form.button("In Progress")
        }
        else if (world.scoreboard.getObjective('quest2').getScore(player) == amount * 3 - 1 && world.scoreboard.getObjective('quests').getScore(player) >= requirement) {
            form.button("Claim Rewards")
        }
        else if (world.scoreboard.getObjective('quest2').getScore(player) > 3 * amount - 3) {
            form.button("Finished!")
        }
        else {
            form.button("Locked")
        }
        form.button("Back")
        form.show(player).then((response) => {
            if (world.scoreboard.getObjective('quest2').getScore(player) == amount * 3 - 3 && world.scoreboard.getObjective('quests').getScore(player) >= requirement && response?.selection === 0) {
                player.runCommandAsync('scoreboard players add @s quest2 1')
                showsplitquest(start, end, player, returnquestset, settitle)
            }
            if (world.scoreboard.getObjective('quest2').getScore(player) == amount * 3 - 1 && world.scoreboard.getObjective('quests').getScore(player) >= requirement && response?.selection === 0) {
                player.runCommandAsync('scoreboard players add @s quest2 1')
                givecom(reward, 1, player)
                player.runCommandAsync('scoreboard players add @s questfin 1')
                showsplitquest(start, end, player, returnquestset, settitle)
            }
            else if (response?.selection === 1) {
                showsplitquest(start, end, player, returnquestset, settitle)
            }
        })
    }
    else if (questset === 3) {
        if (world.scoreboard.getObjective('quest3').getScore(player) == amount * 3 - 3 && world.scoreboard.getObjective('quests').getScore(player) >= requirement) {
            form.button("Claim Quests")
        }
        else if (world.scoreboard.getObjective('quest3').getScore(player) == amount * 3 - 2 && world.scoreboard.getObjective('quests').getScore(player) >= requirement) {
            form.button("In Progress")
        }
        else if (world.scoreboard.getObjective('quest3').getScore(player) == amount * 3 - 1 && world.scoreboard.getObjective('quests').getScore(player) >= requirement) {
            form.button("Claim Rewards")
        }
        else if (world.scoreboard.getObjective('quest3').getScore(player) > 3 * amount - 3) {
            form.button("Finished!")
        }
        else {
            form.button("Locked")
        }
        form.button("Back")
        form.show(player).then((response) => {
            if (world.scoreboard.getObjective('quest3').getScore(player) == amount * 3 - 3 && world.scoreboard.getObjective('quests').getScore(player) >= requirement && response?.selection === 0) {
                player.runCommandAsync('scoreboard players add @s quest3 1')
                showsplitquest(start, end, player, returnquestset, settitle)
            }
            if (world.scoreboard.getObjective('quest3').getScore(player) == amount * 3 - 1 && world.scoreboard.getObjective('quests').getScore(player) >= requirement && response?.selection === 0) {
                player.runCommandAsync('scoreboard players add @s quest3 1')
                givecom(reward, 1, player)
                player.runCommandAsync('scoreboard players add @s questfin 1')
                showsplitquest(start, end, player, returnquestset, settitle)
            }
            else if (response?.selection === 1) {
                showsplitquest(start, end, player, returnquestset, settitle)
            }
        })
    }
}