// Item Functions

import crafttweaker.api.util.ActionResultType;
import mods.contenttweaker.functions.IItemRightClick;
import crafttweaker.api.util.text.MCTextComponent;
import crafttweaker.api.util.text.MCStyle;

// Item Functions, the Starter Kits
// ---------------------------------------------------------------------------------------------------------------------------------------------
/*
advancedItemBuilder
    .build("");
advancedItemBuilder
    .build("kit_cursed");
advancedItemBuilder
    .build("kit_living");
*/
<advanceditem:kit_ancient>.setOnItemRightClick((item, playerEntity, world, hand) => {
    if world.remote {
        return ActionResultType.SUCCESS;
    }
    playerEntity.give(<item:astralsorcery:tome>);
    playerEntity.give(<item:patchouli:guide_book>.withTag({"patchouli:book": "elementalcraft:element_book" as string}));
    playerEntity.give(<item:ars_nouveau:worn_notebook>);
    
    playerEntity.give(<item:astralsorcery:aquamarine> * 8);
    playerEntity.give(<item:elementalcraft:inertcrystal> * 8);
    playerEntity.give(<item:ars_nouveau:magic_clay> * 4);
    // playerEntity.give(<item:ars_nouveau:mana_bloom_crop> * 4);
    playerEntity.give(<item:ars_nouveau:mana_berry> * 4);
    
    item.shrink();
    
    return ActionResultType.SUCCESS;
});

<advanceditem:kit_cursed>.setOnItemRightClick((item, playerEntity, world, hand) => {
    if world.remote {
        return ActionResultType.SUCCESS;
    }
    playerEntity.give(<item:patchouli:guide_book>.withTag({"patchouli:book": "bloodmagic:guide" as string}));
    playerEntity.give(<item:occultism:dictionary_of_spirits>);
    playerEntity.give(<item:eidolon:codex>);
    
    playerEntity.give(<item:bloodmagic:altar>);
    playerEntity.give(<item:bloodmagic:sacrificialdagger>);
    playerEntity.give(<item:occultism:datura_seeds> * 4);
    playerEntity.give(<item:eidolon:soul_shard> * 8);
    // playerEntity.give(<item:minecraft:flint_and_steel>);
    
    item.shrink();
    
    return ActionResultType.SUCCESS;
});

<advanceditem:kit_living>.setOnItemRightClick((item, playerEntity, world, hand) => {
    if world.remote {
        return ActionResultType.SUCCESS;
    }
    playerEntity.give(<item:botania:lexicon>);
    playerEntity.give(<item:patchouli:guide_book>.withTag({"patchouli:book": "naturesaura:book" as string}));
    playerEntity.give(<item:rootsclassic:runic_tablet>);
    
    playerEntity.give(<item:botania:flower_bag>);
    playerEntity.give(<item:botania:fertilizer> * 4);
    playerEntity.give(<item:rootsclassic:bark_knife>);
    // playerEntity.give(<item:rootsclassic:healing_poultice> * 4);
    playerEntity.give(<item:naturesaura:gold_fiber>);
    
    item.shrink();
    
    return ActionResultType.SUCCESS;
});

// ---------------------------------------------------------------------------------------------------------------------------------------------



// Item Functions, the Various Endings.
// ---------------------------------------------------------------------------------------------------------------------------------------------

<advanceditem:ending_ancient>.setOnItemRightClick((item, playerEntity, world, hand) => {
    if world.remote {
        return ActionResultType.SUCCESS;
    }
    var bodyStyle = new MCStyle;
    bodyStyle = bodyStyle.setColor(0x5555FF).setItalic(true);
    var bodyText = MCTextComponent.createStringTextComponent("As look into the numerous facets of your crystal, light dancing off of the intricate structure within, you know that your superiors will be satisfied with your results.").setStyle(bodyStyle);
    playerEntity.sendMessage(bodyText);

    var messageStyle = new MCStyle;
    messageStyle = messageStyle.setColor(0x55FFFF);
    var messageText = MCTextComponent.createStringTextComponent("You got the Ancient Ending! Can you get all the others?").setStyle(messageStyle);
    playerEntity.sendMessage(messageText);
    return ActionResultType.SUCCESS;
});

<advanceditem:ending_cursed>.setOnItemRightClick((item, playerEntity, world, hand) => {
    if world.remote {
        return ActionResultType.SUCCESS;
    }
    var bodyStyle = new MCStyle;
    bodyStyle = bodyStyle.setColor(0xAA0000).setItalic(true);
    var bodyText = MCTextComponent.createStringTextComponent("Poring over the knowledge contained within each page of this tome, the power and sacrifice necessary to create such an artifact is apparent.").setStyle(bodyStyle);
    playerEntity.sendMessage(bodyText);

    var messageStyle = new MCStyle;
    messageStyle = messageStyle.setColor(0xFF5555);
    var messageText = MCTextComponent.createStringTextComponent("You got the Cursed Ending! Can you get all the others?").setStyle(messageStyle);
    playerEntity.sendMessage(messageText);
    return ActionResultType.SUCCESS;
});

<advanceditem:ending_living>.setOnItemRightClick((item, playerEntity, world, hand) => {
    if world.remote {
        return ActionResultType.SUCCESS;
    }
    var bodyStyle = new MCStyle;
    bodyStyle = bodyStyle.setColor(0x00AA00).setItalic(true);
    var bodyText = MCTextComponent.createStringTextComponent("You run your fingers along the edges of the rune, noticing details too fine to be made out by the untrained eye. This much natural energy proves without a doubt that this forest is viable.").setStyle(bodyStyle);
    playerEntity.sendMessage(bodyText);

    var messageStyle = new MCStyle;
    messageStyle = messageStyle.setColor(0x55FF55);
    var messageText = MCTextComponent.createStringTextComponent("You got the Living Ending! Can you get all the others?").setStyle(messageStyle);
    playerEntity.sendMessage(messageText);
    return ActionResultType.SUCCESS;
});

<advanceditem:ending_true>.setOnItemRightClick((item, playerEntity, world, hand) => {
    if world.remote {
        return ActionResultType.SUCCESS;
    }
    var bodyStyle = new MCStyle;
    bodyStyle = bodyStyle.setColor(0xFFAA00).setItalic(true);
    var bodyText = MCTextComponent.createStringTextComponent("You've toppled beings of great power, and you assembled the arsenals to rival them. You've mastered the arcane arts, beyond what could have ever been possible in your home world. After all that you've done, those fools wish to enter this dimension too, just to tarnish your work? Why should you let them in at all? You activate the seal, ensuring this world remains yours forever.").setStyle(bodyStyle);
    playerEntity.sendMessage(bodyText);

    var messageStyle = new MCStyle;
    messageStyle = messageStyle.setColor(0xFFFF55);
    var messageText = MCTextComponent.createStringTextComponent("You got the True Ending! Congratulations, and thank you for playing.").setStyle(messageStyle);
    playerEntity.sendMessage(messageText);
    return ActionResultType.SUCCESS;
});


// "As look into the numerous facets of your crystal, light dancing off of the intricate structure within, you know that your superiors will be satisfied with your results."
// "Poring over the knowledge contained within each page of this tome, the power and sacrifice necessary to create such an object is apparent."
// "You run your fingers along the edges of the rune, noticing details too fine to be made out by the naked eye. This much natural energy proves without a doubt that this forest is viable."
// "You've toppled beings of great power, and you assembled the arsenals to rival them. You've mastered the arcane arts, beyond what could have ever been possible in your home world. After all that you've done, those fools wish to enter this dimension too, just to tarnish your work? Why should you let them in at all? You activate the seal, ensuring this world remains yours forever."

// ---------------------------------------------------------------------------------------------------------------------------------------------


// Item Functions, the Antique Astrolabe
// ---------------------------------------------------------------------------------------------------------------------------------------------
<advanceditem:astrolabe>.setOnItemRightClick((item, playerEntity, world, hand) => {
    if world.remote {
        return ActionResultType.SUCCESS; 
    }
    world.asServerWorld().server.executeCommand("execute as " + playerEntity.getName().getString() + " run astralsorcery constellation discover astralsorcery:horologium", true);
    return ActionResultType.SUCCESS;
});
//
// ---------------------------------------------------------------------------------------------------------------------------------------------


// Item Functions, the Creator's Notes
// ---------------------------------------------------------------------------------------------------------------------------------------------
<advanceditem:readme>.setOnItemRightClick((item, playerEntity, world, hand) => {
    if world.remote {
        return ActionResultType.SUCCESS; 
    }
    var bodyStyle = new MCStyle;
    bodyStyle = bodyStyle.setColor(0xFFFFFF);
    var bodyText = MCTextComponent.createStringTextComponent("It appears to be a note from a mysterious \"Pun Crafter\".").setStyle(bodyStyle);
    playerEntity.sendMessage(bodyText);

    var messageStyle = new MCStyle;
    messageStyle = messageStyle.setColor(0xAAAAAA).setItalic(true);
    var messageText = MCTextComponent.createStringTextComponent("Hello! If you want to have the most fun in Arcane Twilight, you should probably stick with the mods inside of your starter kit, as well as the mods listed in the Rainbow Magic section of the book.\n---\nUnless you're playing singleplayer, then feel free to do whatever.").setStyle(messageStyle);
    playerEntity.sendMessage(messageText);

    return ActionResultType.SUCCESS;
});
//
// ---------------------------------------------------------------------------------------------------------------------------------------------






