import * as mc from "@minecraft/server";
import * as ui from "@minecraft/server-ui";

const SOUND_TURN_PAGE = "item.book.page_turn";
const SOUND_OPTIONS = { pitch: 1.0, volume: 5.0, };

export const animalList = [
    {
        ID: "sgs_farm:cow",
        egg: "sgs_farm:spawn_egg_cow",
        type: "Cow",
        sex: "Female",
        variants: 5,
        names: [
            "Holstein Friesian Cow",
            "Ankole Watusi Cow",
            "Abondance Cow",
            "Highland Cow",
            "Water Buffalo Cow"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle"
        ],
        food: [
            "Maize",
            "Rye",
            "Sweetcorn",
            "Wheat",
            "Carrot",
            "Turnip"
        ],
        food_id: [
            "sgs_farm:maize_crop",
            "sgs_farm:rye_crop",
            "sgs_farm:sweetcorn_crop",
            "minecraft:wheat",
            "minecraft:carrot",
            "sgs_farm:turnip_crop"
        ]
    },
    {
        ID: "sgs_farm:sheep",
        egg: "sgs_farm:spawn_egg_sheep",
        type: "Sheep",
        sex: "Female",
        variants: 5,
        names: [
            "Panama Ewe",
            "Desert Bighorn Ewe",
            "Mountain Bighorn Ewe",
            "Herdwick Ewe",
            "Garole Ewe"
        ],
        biomes: [
            "Plains",
            "Desert",
            "Taiga",
            "Snowy Biomes"
        ],
        food: [
            "Maize",
            "Rye",
            "Sweetcorn",
            "Wheat",
            "Carrot",
            "Turnip"
        ],
        food_id: [
            "sgs_farm:maize_crop",
            "sgs_farm:rye_crop",
            "sgs_farm:sweetcorn_crop",
            "minecraft:wheat",
            "minecraft:carrot",
            "sgs_farm:turnip_crop"
        ]
    },
    {
        ID: "sgs_farm:pig",
        egg: "sgs_farm:spawn_egg_pig",
        type: "Pig",
        sex: "Female",
        variants: 7,
        names: [
            "Large White Sow",
            "Warthog Sow",
            "Black Alpine Sow",
            "Mangalitsa Sow",
            "Wild Brown Sow",
            "Feral Sow",
            "Desert Sow"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle",
            "Swamp",
            "Desert"
        ],
        food: [
            "Potato",
            "Carrot",
            "Wheat",
            "Turnip",
            "Radish",
            "Green Cabbage",
            "Red Cabbage",
            "Bread Crumbs",
            "Boiled Egg"
        ],
        food_id: [
            "minecraft:potato",
            "minecraft:carrot",
            "minecraft:beetroot",
            "minecraft:wheat",
            "sgs_farm:turnip_crop",
            "sgs_farm:radish_crop",
            "sgs_farm:cabbage_green_crop",
            "sgs_farm:cabbage_red_crop",
            "sgs_farm:bread_slice",
            "sgs_farm:breadcrumbs",
            "sgs_farm:egg_boiled"
        ]
    },
    {
        ID: "sgs_farm:goat",
        egg: "sgs_farm:spawn_egg_goat",
        type: "Goat",
        sex: "Female",
        variants: 5,
        names: [
            "Rove Nanny",
            "Nubian Ibex Nanny",
            "Boer Nanny",
            "Alpine Nanny",
            "Rocky Mountain Nanny"
        ],
        biomes: [
            "Plains",
            "Desert",
            "Savanna",
            "Taiga",
            "Snowy Biomes"
        ],
        food: [
            "Maize",
            "Rye",
            "Sweetcorn",
            "Wheat",
            "Carrot",
            "Turnip"
        ],
        food_id: [
            "sgs_farm:maize_crop",
            "sgs_farm:rye_crop",
            "sgs_farm:sweetcorn_crop",
            "minecraft:wheat",
            "minecraft:carrot",
            "sgs_farm:turnip_crop"
        ]
    },
    {
        ID: "sgs_farm:chicken",
        egg: "sgs_farm:spawn_egg_chicken",
        type: "Chicken",
        sex: "Female",
        variants: 6,
        names: [
            "American Bresse Hen",
            "Lesser Prairie Hen",
            "Western Capercaille Hen",
            "Cochin Hen",
            "Green Junglefowl Hen",
            "Purple Gallinule Hen"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle",
            "Swamp"
        ],
        food: [
            "Wheat Seeds",
            "Beetroot Seeds",
            "Melon Seeds",
            "Pumpkin Seeds",
            "Wild Seeds",
            "Breadcrumbs",
            "Maize"
        ],
        food_id: [
            "minecraft:wheat_seeds",
            "minecraft:beetroot_seeds",
            "minecraft:melon_seeds",
            "minecraft:pumpkin_seeds",
            "minecraft:pitcher_pod",
            "sgs_farm:wild_seed",
            "sgs_farm:breadcrumbs",
            "sgs_farm:maize_crop"
        ]
    },
    {
        ID: "sgs_farm:duck",
        egg: "sgs_farm:spawn_egg_duck",
        type: "Duck",
        sex: "Female",
        suffix: "Hen",
        variants: 6,
        names: [
            "Mallard Hen",
            "Cape Shelduck Hen",
            "Wood Hen",
            "King Eider Hen",
            "Lesser Whistling Hen",
            "Ruddy Hen"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle",
            "Swamp"
        ],
        food: [
            "Wheat Seeds",
            "Beetroot Seeds",
            "Melon Seeds",
            "Pumpkin Seeds",
            "Wild Seeds",
            "Breadcrumbs",
            "Maize"
        ],
        food_id: [
            "minecraft:wheat_seeds",
            "minecraft:beetroot_seeds",
            "minecraft:melon_seeds",
            "minecraft:pumpkin_seeds",
            "sgs_farm:wild_seed",
            "sgs_farm:breadcrumbs",
            "sgs_farm:maize_crop"
        ]
    },
    {
        ID: "sgs_farm:hare",
        egg: "sgs_farm:spawn_egg_hare",
        type: "Hare",
        sex: "Female",
        variants: 6,
        names: [
            "White Tailed Jill",
            "Cape Hare Jill",
            "Antelope Jill",
            "Mountain Jill",
            "Arctic Jill"
        ],
        biomes: [
            "Plains",
            "Desert",
            "Savanna",
            "Taiga",
            "Snowy Biomes"
        ],
        food: [
            "Green Cabbage",
            "Red Cabbage",
            "Lettuce",
            "Pak Choic",
            "Leek",
            "Spinach",
            "Carrot",
            "Golden Carrot",
            "Dandelion",
            "Maize"
        ],
        food_id: [
            "sgs_farm:cabbage_green_crop",
            "sgs_farm:cabbage_red_crop",
            "sgs_farm:lettuce_crop",
            "sgs_farm:pak_choi_crop",
            "sgs_farm:turnip_crop",
            "sgs_farm:leeks_crop",
            "sgs_farm:spinach_crop",
            "minecraft:carrot",
            "minecraft:golden_carrot",
            "minecraft:dandelion",
            "sgs_farm:maize_crop"
        ]
    },
    {
        ID: "sgs_farm:turkey",
        egg: "sgs_farm:spawn_egg_turkey",
        type: "Turkey",
        sex: "Female",
        variants: 1,
        names: [
            "Wild  Hen"
        ],
        biomes: [
            "Plains, Taiga, Jungle"
        ],
        food: [
            "Wheat Seeds",
            "Beetroot Seeds",
            "Melon Seeds",
            "Pumpkin Seeds",
            "Wild Seeds",
            "Breadcrumbs",
            "Maize"
        ],
        food_id: [
            "minecraft:wheat_seeds",
            "minecraft:beetroot_seeds",
            "minecraft:melon_seeds",
            "minecraft:pumpkin_seeds",
            "sgs_farm:wild_seed",
            "sgs_farm:breadcrumbs",
            "sgs_farm:maize_crop"
        ]
    },

    {
        ID: "sgs_farm:cow",
        egg: "sgs_farm:spawn_egg_cow",
        type: "Cow",
        sex: "Female",
        variants: 5,
        names: [
            "Holstein Friesian Cow",
            "Ankole Watusi Cow",
            "Abondance Cow",
            "Highland Cow",
            "Water Buffalo Cow"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle"
        ],
        food: [
            "Maize",
            "Rye",
            "Sweetcorn",
            "Wheat",
            "Carrot",
            "Turnip"
        ],
        food_id: [
            "sgs_farm:maize_crop",
            "sgs_farm:rye_crop",
            "sgs_farm:sweetcorn_crop",
            "minecraft:wheat",
            "minecraft:carrot",
            "sgs_farm:turnip_crop"
        ]
    },
    {
        ID: "sgs_farm:sheep",
        egg: "sgs_farm:spawn_egg_sheep",
        type: "Sheep",
        sex: "Female",
        variants: 5,
        names: [
            "Panama Ewe",
            "Desert Bighorn Ewe",
            "Mountain Bighorn Ewe",
            "Herdwick Ewe",
            "Garole Ewe"
        ],
        biomes: [
            "Plains",
            "Desert",
            "Taiga",
            "Snowy Biomes"
        ],
        food: [
            "Maize",
            "Rye",
            "Sweetcorn",
            "Wheat",
            "Carrot",
            "Turnip"
        ],
        food_id: [
            "sgs_farm:maize_crop",
            "sgs_farm:rye_crop",
            "sgs_farm:sweetcorn_crop",
            "minecraft:wheat",
            "minecraft:carrot",
            "sgs_farm:turnip_crop"
        ]
    },
    {
        ID: "sgs_farm:pig",
        egg: "sgs_farm:spawn_egg_pig",
        type: "Pig",
        sex: "Female",
        variants: 7,
        names: [
            "Large White Sow",
            "Warthog Sow",
            "Black Alpine Sow",
            "Mangalitsa Sow",
            "Wild Brown Sow",
            "Feral Sow",
            "Desert Sow"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle",
            "Swamp",
            "Desert"
        ],
        food: [
            "Potato",
            "Carrot",
            "Wheat",
            "Turnip",
            "Radish",
            "Green Cabbage",
            "Red Cabbage",
            "Bread Crumbs",
            "Boiled Egg"
        ],
        food_id: [
            "minecraft:potato",
            "minecraft:carrot",
            "minecraft:beetroot",
            "minecraft:wheat",
            "sgs_farm:turnip_crop",
            "sgs_farm:radish_crop",
            "sgs_farm:cabbage_green_crop",
            "sgs_farm:cabbage_red_crop",
            "sgs_farm:bread_slice",
            "sgs_farm:breadcrumbs",
            "sgs_farm:egg_boiled"
        ]
    },
    {
        ID: "sgs_farm:goat",
        egg: "sgs_farm:spawn_egg_goat",
        type: "Goat",
        sex: "Female",
        variants: 5,
        names: [
            "Rove Nanny",
            "Nubian Ibex Nanny",
            "Boer Nanny",
            "Alpine Nanny",
            "Rocky Mountain Nanny"
        ],
        biomes: [
            "Plains",
            "Desert",
            "Savanna",
            "Taiga",
            "Snowy Biomes"
        ],
        food: [
            "Maize",
            "Rye",
            "Sweetcorn",
            "Wheat",
            "Carrot",
            "Turnip"
        ],
        food_id: [
            "sgs_farm:maize_crop",
            "sgs_farm:rye_crop",
            "sgs_farm:sweetcorn_crop",
            "minecraft:wheat",
            "minecraft:carrot",
            "sgs_farm:turnip_crop"
        ]
    },
    {
        ID: "sgs_farm:chicken",
        egg: "sgs_farm:spawn_egg_chicken",
        type: "Chicken",
        sex: "Female",
        variants: 6,
        names: [
            "American Bresse Hen",
            "Lesser Prairie Hen",
            "Western Capercaille Hen",
            "Cochin Hen",
            "Green Junglefowl Hen",
            "Purple Gallinule Hen"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle",
            "Swamp"
        ],
        food: [
            "Wheat Seeds",
            "Beetroot Seeds",
            "Melon Seeds",
            "Pumpkin Seeds",
            "Wild Seeds",
            "Breadcrumbs",
            "Maize"
        ],
        food_id: [
            "minecraft:wheat_seeds",
            "minecraft:beetroot_seeds",
            "minecraft:melon_seeds",
            "minecraft:pumpkin_seeds",
            "minecraft:pitcher_pod",
            "sgs_farm:wild_seed",
            "sgs_farm:breadcrumbs",
            "sgs_farm:maize_crop"
        ]
    },
    {
        ID: "sgs_farm:duck",
        egg: "sgs_farm:spawn_egg_duck",
        type: "Duck",
        sex: "Female",
        suffix: "Hen",
        variants: 6,
        names: [
            "Mallard Hen",
            "Cape Shelduck Hen",
            "Wood Hen",
            "King Eider Hen",
            "Lesser Whistling Hen",
            "Ruddy Hen"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle",
            "Swamp"
        ],
        food: [
            "Wheat Seeds",
            "Beetroot Seeds",
            "Melon Seeds",
            "Pumpkin Seeds",
            "Wild Seeds",
            "Breadcrumbs",
            "Maize"
        ],
        food_id: [
            "minecraft:wheat_seeds",
            "minecraft:beetroot_seeds",
            "minecraft:melon_seeds",
            "minecraft:pumpkin_seeds",
            "sgs_farm:wild_seed",
            "sgs_farm:breadcrumbs",
            "sgs_farm:maize_crop"
        ]
    },
    {
        ID: "sgs_farm:hare",
        egg: "sgs_farm:spawn_egg_hare",
        type: "Hare",
        sex: "Female",
        variants: 6,
        names: [
            "White Tailed Jill",
            "Cape Hare Jill",
            "Antelope Jill",
            "Mountain Jill",
            "Arctic Jill"
        ],
        biomes: [
            "Plains",
            "Desert",
            "Savanna",
            "Taiga",
            "Snowy Biomes"
        ],
        food: [
            "Green Cabbage",
            "Red Cabbage",
            "Lettuce",
            "Pak Choic",
            "Leek",
            "Spinach",
            "Carrot",
            "Golden Carrot",
            "Dandelion",
            "Maize"
        ],
        food_id: [
            "sgs_farm:cabbage_green_crop",
            "sgs_farm:cabbage_red_crop",
            "sgs_farm:lettuce_crop",
            "sgs_farm:pak_choi_crop",
            "sgs_farm:turnip_crop",
            "sgs_farm:leeks_crop",
            "sgs_farm:spinach_crop",
            "minecraft:carrot",
            "minecraft:golden_carrot",
            "minecraft:dandelion",
            "sgs_farm:maize_crop"
        ]
    },
    {
        ID: "sgs_farm:turkey",
        egg: "sgs_farm:spawn_egg_turkey",
        type: "Turkey",
        sex: "Female",
        variants: 1,
        names: [
            "Wild  Hen"
        ],
        biomes: [
            "Plains, Taiga, Jungle"
        ],
        food: [
            "Wheat Seeds",
            "Beetroot Seeds",
            "Melon Seeds",
            "Pumpkin Seeds",
            "Wild Seeds",
            "Breadcrumbs",
            "Maize"
        ],
        food_id: [
            "minecraft:wheat_seeds",
            "minecraft:beetroot_seeds",
            "minecraft:melon_seeds",
            "minecraft:pumpkin_seeds",
            "sgs_farm:wild_seed",
            "sgs_farm:breadcrumbs",
            "sgs_farm:maize_crop"
        ]
    },

    //Male
    {
        ID: "sgs_farm:cow_m",
        egg: "sgs_farm:spawn_egg_cow_m",
        type: "Cow",
        sex: "Male",
        variants: 5,
        names: [
            "Holstein Friesian Bull",
            "Ankole Watusi Bull",
            "Abondance Bull",
            "Highland Bull",
            "Water Buffalo Bull"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle"
        ],
        food: [
            "Maize",
            "Rye",
            "Sweetcorn",
            "Wheat",
            "Carrot",
            "Turnip"
        ],
        food_id: [
            "sgs_farm:maize_crop",
            "sgs_farm:rye_crop",
            "sgs_farm:sweetcorn_crop",
            "minecraft:wheat",
            "minecraft:carrot",
            "sgs_farm:turnip_crop"
        ]
    },
    {
        ID: "sgs_farm:sheep_m",
        egg: "sgs_farm:spawn_egg_sheep_m",
        type: "Sheep",
        sex: "Male",
        variants: 5,
        names: [
            "Panama Ram",
            "Desert Bighorn Ram",
            "Mountain Bighorn Ram",
            "Herdwick Ram",
            "Garole Ram"
        ],
        biomes: [
            "Plains",
            "Desert",
            "Taiga",
            "Snowy Biomes"
        ],
        food: [
            "Maize",
            "Rye",
            "Sweetcorn",
            "Wheat",
            "Carrot",
            "Turnip"
        ],
        food_id: [
            "sgs_farm:maize_crop",
            "sgs_farm:rye_crop",
            "sgs_farm:sweetcorn_crop",
            "minecraft:wheat",
            "minecraft:carrot",
            "sgs_farm:turnip_crop"
        ]
    },
    {
        ID: "sgs_farm:pig_m",
        egg: "sgs_farm:spawn_egg_pig_m",
        type: "Pig",
        sex: "Male",
        variants: 7,
        names: [
            "Large White Boar",
            "Warthog Boar",
            "Black Alpine Boar",
            "Mangalitsa Boar",
            "Wild Brown Boar",
            "Feral Boar",
            "Desert Boar"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle",
            "Swamp",
            "Desert"
        ],
        food: [
            "Potato",
            "Carrot",
            "Wheat",
            "Turnip",
            "Radish",
            "Green Cabbage",
            "Red Cabbage",
            "Bread Crumbs",
            "Boiled Egg"
        ],
        food_id: [
            "minecraft:potato",
            "minecraft:carrot",
            "minecraft:beetroot",
            "minecraft:wheat",
            "sgs_farm:turnip_crop",
            "sgs_farm:radish_crop",
            "sgs_farm:cabbage_green_crop",
            "sgs_farm:cabbage_red_crop",
            "sgs_farm:bread_slice",
            "sgs_farm:breadcrumbs",
            "sgs_farm:egg_boiled"
        ]
    },
    {
        ID: "sgs_farm:goat_m",
        egg: "sgs_farm:spawn_egg_goat_m",
        type: "Goat",
        sex: "Male",
        variants: 5,
        names: [
            "Rove Billy",
            "Nubian Ibex Billy",
            "Boer Billy",
            "Alpine Billy",
            "Rocky Mountain Billy"
        ],
        biomes: [
            "Plains",
            "Desert",
            "Savanna",
            "Taiga",
            "Snowy Biomes"
        ],
        food: [
            "Maize",
            "Rye",
            "Sweetcorn",
            "Wheat",
            "Carrot",
            "Turnip"
        ],
        food_id: [
            "sgs_farm:maize_crop",
            "sgs_farm:rye_crop",
            "sgs_farm:sweetcorn_crop",
            "minecraft:wheat",
            "minecraft:carrot",
            "sgs_farm:turnip_crop"
        ]
    },
    {
        ID: "sgs_farm:chicken_m",
        egg: "sgs_farm:spawn_egg_chicken_m",
        type: "Chicken",
        sex: "Male",
        variants: 6,
        names: [
            "American Bresse Rooster",
            "Lesser Prairie Rooster",
            "Western Capercaille Rooster",
            "Cochin Rooster",
            "Green Junglefowl Rooster",
            "Purple Gallinule Rooster"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle",
            "Swamp"
        ],
        food: [
            "Wheat Seeds",
            "Beetroot Seeds",
            "Melon Seeds",
            "Pumpkin Seeds",
            "Wild Seeds",
            "Breadcrumbs",
            "Maize"
        ],
        food_id: [
            "minecraft:wheat_seeds",
            "minecraft:beetroot_seeds",
            "minecraft:melon_seeds",
            "minecraft:pumpkin_seeds",
            "minecraft:pitcher_pod",
            "sgs_farm:wild_seed",
            "sgs_farm:breadcrumbs",
            "sgs_farm:maize_crop"
        ]
    },
    {
        ID: "sgs_farm:duck_m",
        egg: "sgs_farm:spawn_egg_duck_m",
        type: "Duck",
        sex: "Male",
        suffix: "Hen",
        variants: 6,
        names: [
            "Mallard Drake",
            "Cape Shelduck Drake",
            "Wood Drake",
            "King Eider Drake",
            "Lesser Whistling Drake",
            "Ruddy Drake"
        ],
        biomes: [
            "Plains",
            "Savanna",
            "Taiga",
            "Snowy Biomes",
            "Jungle",
            "Swamp"
        ],
        food: [
            "Wheat Seeds",
            "Beetroot Seeds",
            "Melon Seeds",
            "Pumpkin Seeds",
            "Wild Seeds",
            "Breadcrumbs",
            "Maize"
        ],
        food_id: [
            "minecraft:wheat_seeds",
            "minecraft:beetroot_seeds",
            "minecraft:melon_seeds",
            "minecraft:pumpkin_seeds",
            "sgs_farm:wild_seed",
            "sgs_farm:breadcrumbs",
            "sgs_farm:maize_crop"
        ]
    },
    {
        ID: "sgs_farm:hare_m",
        egg: "sgs_farm:spawn_egg_hare_m",
        type: "Hare",
        sex: "Male",
        variants: 6,
        names: [
            "White Tailed Jack",
            "Cape Hare Jack",
            "Antelope Jackrabbit",
            "Mountain Jack",
            "Arctic Jack"
        ],
        biomes: [
            "Plains",
            "Desert",
            "Savanna",
            "Taiga",
            "Snowy Biomes"
        ],
        food: [
            "Green Cabbage",
            "Red Cabbage",
            "Lettuce",
            "Pak Choic",
            "Leek",
            "Spinach",
            "Carrot",
            "Golden Carrot",
            "Dandelion",
            "Maize"
        ],
        food_id: [
            "sgs_farm:cabbage_green_crop",
            "sgs_farm:cabbage_red_crop",
            "sgs_farm:lettuce_crop",
            "sgs_farm:pak_choi_crop",
            "sgs_farm:turnip_crop",
            "sgs_farm:leeks_crop",
            "sgs_farm:spinach_crop",
            "minecraft:carrot",
            "minecraft:golden_carrot",
            "minecraft:dandelion",
            "sgs_farm:maize_crop"
        ]
    },
    {
        ID: "sgs_farm:turkey_m",
        egg: "sgs_farm:spawn_egg_turkey_m",
        type: "Turkey",
        sex: "Male",
        variants: 1,
        names: [
            "Wild  Gobbler"
        ],
        biomes: [
            "Plains, Taiga, Jungle"
        ],
        food: [
            "Wheat Seeds",
            "Beetroot Seeds",
            "Melon Seeds",
            "Pumpkin Seeds",
            "Wild Seeds",
            "Breadcrumbs",
            "Maize"
        ],
        food_id: [
            "minecraft:wheat_seeds",
            "minecraft:beetroot_seeds",
            "minecraft:melon_seeds",
            "minecraft:pumpkin_seeds",
            "sgs_farm:wild_seed",
            "sgs_farm:breadcrumbs",
            "sgs_farm:maize_crop"
        ]
    }
]

animalInteract();
transformMale();
spawnControl();

function animalInteract() {

    mc.world.beforeEvents.playerInteractWithEntity.subscribe((data) => {
        const entity = data.target;
        const player = data.player;

        const mainhand = player.getComponent(mc.EntityEquippableComponent.componentId).getEquipmentSlot(mc.EquipmentSlot.Mainhand);
        const heldItem = mainhand.getItem();
        if (heldItem == undefined) return;
        if (heldItem.typeId == "minecraft:debug_stick") {

            const entityData = animalList.find((f) => f.ID == entity.typeId);
            if (entityData == undefined) return;

            const currentVariant = entity.getProperty("sgs_farm:climate_variant");
            let variant = currentVariant + 1;
            if (variant > (entityData.names.length - 1)) variant = 0;

            mc.system.runTimeout(() => {
                //entity.setProperty("sgs_farm:climate_variant", variant);
                entity.triggerEvent("sgs_farm:variant_" + (variant + 1));

                player.onScreenDisplay.setActionBar("§a" + entityData.names[variant]);
                player.dimension.playSound("block.decorated_pot.insert", entity.location);
            }, 2)
            data.cancel = true;
            return;
        };
        if (heldItem.hasTag("sgs_farm:spawn_egg")) {

            const entityData = animalList.find((f) => f.ID == entity.typeId);
            if (entityData == undefined) return;

            if (entityData.egg != heldItem.typeId) return;

            const currentVariant = entity.getProperty("sgs_farm:climate_variant");
            let variant = currentVariant + 1;
            if (variant > (entityData.names.length - 1)) variant = 0;

            mc.system.runTimeout(() => {
                //entity.setProperty("sgs_farm:climate_variant", variant);
                entity.triggerEvent("sgs_farm:variant_" + (variant + 1));

                player.onScreenDisplay.setActionBar("§a" + entityData.names[variant]);
                player.dimension.playSound("block.decorated_pot.insert", entity.location);
            }, 2)
            data.cancel = true;
            return;
        };
        if (heldItem.typeId == "sgs_farm:guidebook") {
            const entityData = animalList.find((f) => f.ID == entity.typeId);
            if (entityData == undefined) return;
            data.cancel = true;

            const variant = entity.getProperty("sgs_farm:climate_variant");
            const fed = entity.getProperty("sgs_farm:well_fed");

            let animal_info_string = "";
            animal_info_string += "Type: §a" + entityData.type + "§r\n";
            animal_info_string += "Variant: §a" + entityData.names[variant] + " " + (entityData.sex == "Male" ? "§3[Male]" : "§3[Female]") + "§r\n";
            animal_info_string += "Home Biome: §n" + entityData.biomes[variant] + "§r\n";
            animal_info_string += "Well Fed: " + (fed == true ? "§aYes" : "§cNo") + "§r\n\n";

            let food_string = "§n[";
            for (let index = 0; index < entityData.food.length; index++) {
                food_string = food_string + entityData.food[index] + ", ";
            }
            food_string = food_string.substring(0, food_string.length - 2) + "]§r";
            animal_info_string += "Food Options: " + food_string + "§r\n";


            mc.system.runTimeout(() => {
                player.playSound(SOUND_TURN_PAGE, SOUND_OPTIONS);

                const menu = new ui.ActionFormData();
                menu.title("Animal Info");
                menu.body(animal_info_string);

                menu.show(player).then(result => {
                    if (result.canceled) return;
                });

            }, 0)
            return;
        }
    });
}

function transformMale() {
    mc.system.afterEvents.scriptEventReceive.subscribe((eventData) => {
        const { id, sourceEntity, message } = eventData;
        if (sourceEntity == undefined) return;

        if (id == "sgs_farm:baby_male") {

            const location = sourceEntity.location;
            const dimension = sourceEntity.dimension.id;

            const entityData = animalList.find((f) => f.ID == sourceEntity.typeId);
            if (entityData == undefined) return;

            const currentVariant = sourceEntity.getProperty("sgs_farm:climate_variant");
            sourceEntity.triggerEvent("evt:transform_male_" + currentVariant);
            return;
        };

        if (id == "sgs_farm:rooster_morning") {
            sourceEntity.dimension.playSound("sgs_farm.rooster_call", sourceEntity.location);
            return;
        };
    })
}

function spawnControl() {
    //seed trader spawn
    mc.world.afterEvents.entitySpawn.subscribe((eventData) => {
        const { entity, cause } = eventData;

        if (entity.typeId == "sgs_farm:seed_trader") {
            if (cause != "Spawned") return;
            if (mc.world.scoreboard.getObjective("sgs_farm_settings").getScore("TRADER_SPAWN") == 0) {
                entity.triggerEvent("sgs_farm:despawn");
                return;

            }
        }

        const entityData = animalList.find((f) => f.ID == entity.typeId);
        if (entityData != undefined) {

            if (mc.world.scoreboard.getObjective("sgs_farm_animals").getScore("ANIMAL_SPAWN") == 0) {
                try {
                    if (cause != "Spawned") return;
                    if (entity.hasTag("sgs_farm_transformed")) return;
                    entity.remove();
                } catch (error) { }

            }
        }
    })
}