//Crafting Eidolon Stuff

import crafttweaker.api.item.IItemStack;
import crafttweaker.api.data.IData;
import crafttweaker.api.data.MapData;




// Most of the custom Eidolon Recipes are found in the datapacks

// Ediolon Ruined a Vanilla Recipe >:(
// ---------------------------------------------------------------------------------------------------------------------------------------------
furnace.removeRecipe(<item:eidolon:smooth_stone_bricks>);
// ---------------------------------------------------------------------------------------------------------------------------------------------


// And then they didn't add a recipe for Polished Wood Stairs >:((((
// ---------------------------------------------------------------------------------------------------------------------------------------------
craftingTable.addShapedMirrored("polished_wood_stairs", <item:eidolon:polished_planks_stairs> * 4, [
    [<item:eidolon:polished_planks>, <item:minecraft:air>, <item:minecraft:air>],
    [<item:eidolon:polished_planks>, <item:eidolon:polished_planks>, <item:minecraft:air>],
    [<item:eidolon:polished_planks>, <item:eidolon:polished_planks>, <item:eidolon:polished_planks>]]);
// ---------------------------------------------------------------------------------------------------------------------------------------------


// Remaking Conjuring
// ---------------------------------------------------------------------------------------------------------------------------------------------
// The Conjuring Enchiridon
craftingTable.removeRecipe(<item:conjuring:enchiridion>);
craftingTable.addShapeless("new_enchiridion", <item:conjuring:enchiridion>, 
[<item:minecraft:book>, <item:eidolon:soul_shard>]);

// Removing Conjuring's Machine Recipes, check the datapacks
craftingTable.removeRecipe(<item:conjuring:soulfire_forge>);
craftingTable.removeRecipe(<item:conjuring:soul_weaver>);
craftingTable.removeRecipe(<item:conjuring:gem_tinkerer>);
stoneCutter.removeRecipe(<item:conjuring:soul_funnel>);

// This One's Complex. Filling the Conjuring Focus via crafting, since the Ritual of Extraction is Unreliable.
// Seriously, this was a nightmare to figure out.
// I hope you enjoy it.

craftingTable.addShapeless("filling_conjuring_focus", 
    <item:conjuring:conjuring_focus>.withTag({display: {Lore: ["{\"text\":\"Inherits the Soul from the Gem,\"}", "{\"text\":\"More Reliable than the Ritual of Extraction.\"}"]}}), 
    [
        <item:conjuring:conjuring_focus>, <item:occultism:soul_gem>.transformReplace(<item:occultism:soul_gem>)
    ], (usualOut as IItemStack, inputs as IItemStack[]) => {
        var focus = inputs[0];
        var gem = inputs[1];
        // Focus doesn't have a tag, or if it does have a tag, it doesn't have an Entity
        if !focus.hasTag || !("Entity" in (focus.tag as MapData)) {
            // Focus is all setup, lets check the gem
            if gem.hasTag {
                var gemTag = gem.tag as MapData;
                // Check if the gem has an entity
                if "entityData" in gemTag {
                    var entityData = (gemTag.entityData as IData) as MapData;
                    return inputs[0].withTag({Entity: {id: entityData.id}});
                }
            }

        }
    return <item:minecraft:air>;
});

craftingTable.addShapeless("filling_stabilized_conjuring_focus", 
    <item:conjuring:stabilized_conjuring_focus>.withTag({display: {Lore: ["{\"text\":\"Inherits the Soul from the Gem,\"}", "{\"text\":\"More Reliable than the Ritual of Extraction.\"}"]}}), 
    [
        <item:conjuring:stabilized_conjuring_focus>, <item:occultism:soul_gem>.transformReplace(<item:occultism:soul_gem>)
    ], (usualOut as IItemStack, inputs as IItemStack[]) => {
        var focus = inputs[0];
        var gem = inputs[1];
        // Focus doesn't have a tag, or if it does have a tag, it doesn't have an Entity
        if !focus.hasTag || !("Entity" in (focus.tag as MapData)) {
            // Focus is all setup, lets check the gem
            if gem.hasTag {
                var gemTag = gem.tag as MapData;
                // Check if the gem has an entity
                if "entityData" in gemTag {
                    var entityData = (gemTag.entityData as IData) as MapData;
                    return inputs[0].withTag({Entity: {id: entityData.id}});
                }
            }

        }
    return <item:minecraft:air>;
});


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




// Graveyard of code that didn't work
// Abandon all hope, ye who enter here


/*
soulgem
{
 entityData: {
  id: "minecraft:creeper"
 }
}


focus
<item:conjuring:conjuring_focus>.withTag({Entity: {id: "minecraft:creeper" as string}})
{
 Entity: {
  id: "minecraft:creeper"
 }
}
*/


/*
var temp = ((<item:occultism:soul_gem>.withTag({entityData: {Brain: {memories: {}}, HurtByTimestamp: 139 as int, ForgeData: {alreadyAppliedAttributes: 1 as byte}, Attributes: [{Base: 0.25 as double, Name: "minecraft:generic.movement_speed" as string}, {Base: 0.08 as double, Name: "forge:entity_gravity" as string}, {Base: 0.0 as double, Name: "minecraft:generic.knockback_resistance" as string}, {Base: 16.0 as double, Modifiers: [{Operation: 1 as int, UUID: [-291268567, -2131210445, -2038820976, 716303890], Amount: 0.04003813516053662 as double, Name: "Random spawn bonus" as string}], Name: "minecraft:generic.follow_range" as string}], Invulnerable: 0 as byte, FallFlying: 0 as byte, PortalCooldown: 0 as int, AbsorptionAmount: 0.0 as float, FallDistance: 0.0 as float, CanUpdate: 1 as byte, DeathTime: 0 as short, ForgeCaps: {"twilightforest:cap_shield": {permshields: 0 as int, tempshields: 0 as int}, "eidolon:knowledge": {facts: [], signs: []}}, HandDropChances: [0.085 as float, 0.085 as float], PersistenceRequired: 0 as byte, id: "minecraft:creeper" as string, UUID: [-1993308414, -1266594659, -1719272361, 572989701], Fuse: 30 as short, Motion: [0.0 as double, -0.0784000015258789 as double, 0.0 as double], Health: 19.0 as float, LeftHanded: 0 as byte, Air: 300 as short, OnGround: 1 as byte, ignited: 0 as byte, Rotation: [0.0 as float, 0.0 as float], HandItems: [{}, {}], ArmorDropChances: [0.085 as float, 0.085 as float, 0.085 as float, 0.085 as float], Pos: [-125.5 as double, 36.0 as double, -140.5 as double], Fire: -1 as short, ArmorItems: [{}, {}, {}, {}], CanPickUpLoot: 0 as byte, HurtTime: 0 as short, ExplosionRadius: 3 as byte}})).tag as IData).asString();
var start = (temp.indexOf("id: \"") as int  + 5) as usize;
print(start);
var end = (temp.indexOf("\"", start) as int) as usize;
print(end);
print(temp[start .. end]);
*/

// return usualOut.withTag(<item:conjuring:conjuring_focus>.withTag({Entity: {id: temp[start .. end] as string}}));

// .tag as IData).contains({entityData: {}})

// id:\"
// .asString().contains("")




/*
return usualOut.withTag({Entity: {id: 
"minecraft:creeper"
 as string}})

{Hello : "World", Somewhere: "Over the rainbow"}.put("Hello", "Goodbye");
{Hello : "World", Somewhere: "Over the rainbow"}.put("id", "minecraft:creeper");
*/

// <item:minecraft:dirt>.withoutTag();

/*
craftingTable.addShapeless("filling_conjuring_focus", <item:conjuring:conjuring_focus>.withTag({display: {Lore: ["{\"text\":\"Inherits the Soul from the Gem,\"}" as string, "{\"text\":\"More Reliable than the Ritual of Extraction.\"}" as string]}}), [<item:conjuring:conjuring_focus>, <item:occultism:soul_gem>.transformReplace(<item:occultism:soul_gem>)], (usualOut as IItemStack, inputs as IItemStack[]) => {
    if (!(inputs[0].tag as IData).contains({Entity: {}}) && (inputs[1].tag as IData).contains({entityData: {}})) {
        var temp = (inputs[1].tag as IData).asString();
        var start = (temp.indexOf("id: \"") as int  + 5) as usize;
        var end = (temp.indexOf("\"", start) as int) as usize;
        return usualOut.withTag(<item:conjuring:conjuring_focus>.withTag({Entity: {id: temp[start .. end]}}));
    }
    return <item:minecraft:air>;
});
*/







