//------------------------------------------------------------------------------------------------------------------------------------------------
// PA2 Extras - Extra Recipes
//------------------------------------------------------------------------------------------------------------------------------------------------
// Author: RicTheCoder
//
// A script that adds extra recipes with the ability to turn them on and off, just set the property 'enable' to false and the recipe won't
// be registered.
//
// Recipes have a simplified way of being created, so no need to provide a specific pattern for shaped recipes, it will be assumed.
//
// When using the advance recipes to add custom ones, all required fields need to be provided.
//------------------------------------------------------------------------------------------------------------------------------------------------

// Shaped Recipes
// - 'output' is required, the item to output, follows the normal kubejs rules
// - 'inputs' is required, the input items to make the recipe, follows the normal kubejs rules
// - 'enable' is required, if true the recipe will register, if false it will not
//
// The patterns are assumed from the input items, just set an item to "" to ignore the slot
const shapedRecipes = [
	{
		// Reinforced Deepslate (I don't get why a good building block isn't obtainable or craftable in vanilla...)
		// - Sculk Bones from 'Deeper and Darker's Dimension' (gives more uses to the dimension)
		// - Deepslate as it makes sense
		output: "minecraft:reinforced_deepslate",
		inputs: [
			"deeperdarker:sculk_bone", "#forge:cobblestone/deepslate", "deeperdarker:sculk_bone",
			"deeperdarker:sculk_bone", "#forge:cobblestone/deepslate", "deeperdarker:sculk_bone",
			"deeperdarker:sculk_bone", "#forge:cobblestone/deepslate", "deeperdarker:sculk_bone"
		],
		enable: false
	},
	{
		// Infinity Pipe Upgrade (With all creative things this made sense, and it is not that overpowered due to the way the recipe is)
		// - 4x Final Star Shards
		// - 2x Fading Matter Blocks
		// - 2x Magnum Omega Star
		// - 1x Ultimate Pipe Upgrade
		output: "pipez:infinity_upgrade",
		inputs: [
			"projectexpansion:final_star_shard", "projectexpansion:magnum_star_omega", "projectexpansion:final_star_shard",
			"projectexpansion:fading_matter_block", "pipez:ultimate_upgrade", "projectexpansion:fading_matter_block",
			"projectexpansion:final_star_shard", "projectexpansion:magnum_star_omega", "projectexpansion:final_star_shard"
		],
		enable: true
	},
	{
		// Max Storage Upgrade (With all creative things this also made sense, and it is not that overpowered due to the way the recipe is)
		// - 4x Final Star Shards
		// - 2x Fading Matter Blocks
		// - 2x Magnum Omega Star
		// - 1x Netherite Upgrade
		output: "functionalstorage:max_storage_upgrade",
		inputs: [
			"projectexpansion:final_star_shard", "projectexpansion:magnum_star_omega", "projectexpansion:final_star_shard",
			"projectexpansion:fading_matter_block", "functionalstorage:netherite_upgrade", "projectexpansion:fading_matter_block",
			"projectexpansion:final_star_shard", "projectexpansion:magnum_star_omega", "projectexpansion:final_star_shard"
		],
		enable: true
	}
];

// Shapeless Recipes
// - Same as above without the 'pattern' field.
const shapelessRecipes = []

// Advanced Recipes
// - This will use the 'custom' recipe builder from kubejs, check the documention of kubejs for more info on it.
// - Has the 'enable' field for the same reason as the rest
const advRecipes = [
	// Anti-Lag Alternatives 
	// - To the In-World transformation, but make it balanced so that In-World is still more favourable
	// - Uses Dissolution Chamber from Industrial Foregoing because it seemed to be the more logical one
	// - Only makes alternatives for the more used ones, Final Star Shard and similar will stay as is
	{
		// Redstone Crytal (outputs only 1)
		// - 1B of Water
		// - 2x Redstone Blocks
		// - 2x Fluix Dust
		// - 2x Sky Stone Dust
		// - 2x Charged Certus Quartz Crystal
		type: "industrialforegoing:dissolution_chamber",
		output: { item: "appflux:redstone_crystal", count: 1 },
		processingTime: 300,
		inputFluid: "{FluidName:\"minecraft:water\",Amount:1000}",
		input: [
			{ item: "minecraft:redstone_block" },
			{ item: "minecraft:redstone_block" },
			{ item: "ae2:fluix_dust" },
			{ item: "ae2:fluix_dust" },
			{ item: "ae2:sky_dust" },
			{ item: "ae2:sky_dust" },
			{ item: "ae2:charged_certus_quartz_crystal" },
			{ item: "ae2:charged_certus_quartz_crystal" }
		],
		enable: true
	},
	{
		// Sky Steel Ingot (outputs 2)
		// - 1B of Lava
		// - 3x Iron Ingot
		// - 3x Sky Stone Block
		// - 2x Charged Certus Quartz Crystal
		type: "industrialforegoing:dissolution_chamber",
		output: { item: "megacells:sky_steel_ingot", count: 1 },
		processingTime: 400,
		inputFluid: "{FluidName:\"minecraft:lava\",Amount:1000}",
		input: [
			{ item: "minecraft:iron_ingot" },
			{ item: "minecraft:iron_ingot" },
			{ item: "minecraft:iron_ingot" },
			{ item: "ae2:sky_stone_block" },
			{ item: "ae2:sky_stone_block" },
			{ item: "ae2:sky_stone_block" },
			{ item: "ae2:charged_certus_quartz_crystal" },
			{ item: "ae2:charged_certus_quartz_crystal" }
		],
		enable: true
	}
]

//---[CODE]---------------------------------------------------------------------------------------------------------------------------------------

// Simple recipe registration
ServerEvents.recipes(event => {
	// Applies Shapeless recipes
	shapelessRecipes.forEach(recipe => {
		if (recipe.enable)
			event.shapeless(recipe.output, recipe.inputs);
	});
	
	// Applies Shaped Recipes
	shapedRecipes.forEach(recipe => {
		if (recipe.enable)
		{
			event.shaped(recipe.output, ["012", "345", "678"], {
				"0": recipe.inputs[0],
				"1": recipe.inputs[1],
				"2": recipe.inputs[2],
				"3": recipe.inputs[3],
				"4": recipe.inputs[4],
				"5": recipe.inputs[5],
				"6": recipe.inputs[6],
				"7": recipe.inputs[7],
				"8": recipe.inputs[8],
			});
		}
	});
	
	// Applies Custom Recipes
	advRecipes.forEach(recipe => {
		if (recipe.enable)
			event.custom(recipe);
	});
});

// Simple function to help making recipes
function createShaped(event, output, input) {
    event.shaped(output, [
        '012',
        '345',
        '678'
    ], 
    {
        '0':input[0],
        '1':input[1],
        '2':input[2],
        '3':input[3],
        '4':input[4],
        '5':input[5],
        '6':input[6],
        '7':input[7],
        '8':input[8]
    });
}