minetest.register_craft {
	type = "shapeless";
	recipe = {
		"group:water_bucket",
		"vessels:glass_bottle",
		"vessels:glass_bottle",
		"vessels:glass_bottle"
	};
	output = "sorcery:potion_water 3";
	replacements = {
		{ "group:water_bucket", "bucket:bucket_empty" }
	};
}

minetest.register_craft {
	type = "shapeless";
	recipe = {
		"bucket:bucket_empty";
		"sorcery:potion_water";
		"sorcery:potion_water";
		"sorcery:potion_water";
	};
	output = "bucket:bucket_water";
	replacements = {
		{ "sorcery:potion_water", "vessels:glass_bottle" };
		{ "sorcery:potion_water", "vessels:glass_bottle" };
		{ "sorcery:potion_water", "vessels:glass_bottle" };
	};
}

--[[
minetest.register_craft {
	type = "shapeless";
	recipe = {
		"farming:mortar_pestle",
		"farming:sugar",
		"group:food_blueberries",
		"group:food_raspberries",
		"sorcery:extract_wheat",
		"sorcery:extract_wheat",
		"xdecor:bowl"
	};
	output = "sorcery:oil_mystic";
	replacements = {
		{ "farming:mortar_pestle", "farming:mortar_pestle" },
		{ "sorcery:extract_wheat", "vessels:glass_bottle" },
		{ "sorcery:extract_wheat", "vessels:glass_bottle" }
	};
}

minetest.register_craft {
	type = "shapeless";
	recipe = {
		"farming:mortar_pestle",
		"group:food_berry",
		"group:food_berry",
		"group:food_berry",
		"xdecor:bowl"
	};
	output = "sorcery:oil_berry";
	replacements = {
		{ "farming:mortar_pestle", "farming:mortar_pestle" }
	};
}

minetest.register_craft {
	type = "shapeless";
	recipe = {
		"farming:mortar_pestle",
		"group:food_mushroom",
		"group:food_mushroom",
		"group:food_mushroom",
		"xdecor:bowl"
	};
	output = "sorcery:oil_mushroom";
	replacements = {
		{ "farming:mortar_pestle", "farming:mortar_pestle" }
	};
}
]]
--[[
minetest.register_craft {
	type = "shapeless";
	recipe = {
		"farming:mixing_bowl",
		"sorcery:grease_pine",
		"sorcery:extract_cotton",
		"sorcery:extract_cotton",
		"sorcery:extract_cotton"
	};
	output = "sorcery:oil_whisper";
	replacements = {
		{'farming:mixing_bowl', 'farming:mixing_bowl'};
		{'sorcery:extract_cotton', 'vessels:glass_bottle'};
		{'sorcery:extract_cotton', 'vessels:glass_bottle'};
		{'sorcery:extract_cotton', 'vessels:glass_bottle'};
	};
}

minetest.register_craft {
	type = "shapeless";
	recipe = {
		"farming:mixing_bowl";
		"sorcery:oil_whisper";
		"sorcery:pine_grease";
		"sorcery:extract_rye";
		"sorcery:extract_rye";
		"sorcery:extract_barley";
		"farming:salt";
	};
	output = "sorcery:oil_wind 2";
	replacements = {
		{'farming:mixing_bowl', 'farming:mixing_bowl'};
		{'sorcery:extract_rye', 'vessels:glass_bottle'};
		{'sorcery:extract_rye', 'vessels:glass_bottle'};
		{'sorcery:extract_barley', 'vessels:glass_bottle'};
	};
}

minetest.register_craft {
	type = 'shapeless';
	recipe = {
		"farming:mixing_bowl";
		'sorcery:oil_fog';
		'sorcery:oil_wind';
		'sorcery:blood';
		'sorcery:blood';
		'sorcery:blood';
	};
	output = 'sorcery:grease_storm 2';
	replacements = {
		{'farming:mixing_bowl', 'farming:mixing_bowl'};
		{'sorcery:blood', 'vessels:glass_bottle' }
	}
}

minetest.register_craft {
	type = "shapeless";
	recipe = {
		"farming:mixing_bowl";
		'sorcery:extract_rice',
		'sorcery:oil_berry',
	};
	output = 'sorcery:oil_fog';
	replacements = {
		{'farming:mixing_bowl', 'farming:mixing_bowl'};
		{ 'sorcery:extract_rice', 'vessels:glass_bottle' }
	};
}
]]

minetest.register_craft {
	recipe = {
		{"", "default:gold_ingot"},
		{"default:bronze_ingot",""}
	};
	output = "sorcery:dagger";
}

---- magitech

-- infuser
minetest.register_craftitem('sorcery:infuser_tube', {
	inventory_image = 'sorcery_infuser_tube.png';
	description = 'Infusion Tube';
	groups = {
		sorcery_magitech = 1; metal = 1;
	};
})
minetest.register_craft {
	recipe = {
		{"basic_materials:copper_strip",'sorcery:infuser_concentrator', "basic_materials:copper_strip"};
		{"", "basic_materials:copper_strip", "basic_materials:gold_wire"};
		{"", "basic_materials:copper_strip", ""};
	};
	replacements = {
		{"basic_materials:gold_wire", "basic_materials:empty_spool"}
	};
	output = "sorcery:infuser_tube";
}

minetest.register_craftitem('sorcery:infuser_chamber', {
	inventory_image = 'sorcery_infuser_chamber.png';
	description = 'Infusion Chamber';
	groups = {
		sorcery_magitech = 1;
	};
})
minetest.register_craft {
	recipe = {
		{'default:clay_brick','sorcery:grease_sealant','default:clay_brick'};
		{'default:clay_brick','stairs:slab_steelblock','default:clay_brick'};
	};
	replacements = {
		{'sorcery:grease_sealant','xdecor:bowl'};
	};
	output = "sorcery:infuser_chamber";
}

minetest.register_craftitem('sorcery:infuser_concentrator', {
	inventory_image = 'sorcery_infuser_concentrator.png';
	description = 'Infusion Concentrator';
	groups = {
		sorcery_magitech = 1;
	};
})

minetest.register_craft {
	recipe = {
		{'basic_materials:steel_wire'};
		{'default:obsidian_shard'};
		{'basic_materials:copper_wire'};
	};
	replacements = {
		{'basic_materials:steel_wire', 'basic_materials:empty_spool'};
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
	};
	output = "sorcery:infuser_concentrator";
}

minetest.register_craft {
	type = 'shapeless';
	recipe = {
		'basic_materials:empty_spool';
		'basic_materials:empty_spool';
		'sorcery:infuser_concentrator';
	};
	replacements = {
		{'basic_materials:empty_spool', 'basic_materials:steel_wire'};
		{'basic_materials:empty_spool', 'basic_materials:copper_wire'};
	};
	output = "default:obsidian_shard";
}

minetest.register_craft {
	type = 'shapeless';
	recipe = {
		'xdecor:honey';
		'xdecor:bowl';
		'basic_materials:oil_extract';
	};
	output = "sorcery:grease_sealant";
}

minetest.register_craft {
	recipe = {
		{ 'default:tin_ingot', 'bucket:bucket_empty', 'default:tin_ingot'};
		{ 'default:bronze_ingot', 'sorcery:infuser_chamber', 'default:copper_ingot'};
		{ 'sorcery:infuser_tube', 'sorcery:infuser_tube', 'sorcery:infuser_tube' };
	};
	output = "sorcery:infuser";
}


---- altar
-- candles
minetest.register_craftitem('sorcery:core_counterpraxic',{
	description = 'Counterpraxis Core';
	inventory_image = 'sorcery_core_counterpraxic.png';
});
--
minetest.register_craftitem('sorcery:suppression_matrix',{
	description = 'Suppression Matrix';
	inventory_image = 'sorcery_suppression_matrix.png';
});

minetest.register_craftitem('sorcery:inverter_coil',{
	description = 'Inverter Coil';
	inventory_image = 'sorcery_inverter_coil.png';
});

minetest.register_craftitem('sorcery:beam_generator',{
	description = 'Beam Generator';
	inventory_image = 'sorcery_beam_generator.png';
});

minetest.register_craftitem('sorcery:leyline_stabilizer',{
	description = 'Leyline Stabilizer';
	inventory_image = 'sorcery_leyline_stabilizer.png';
});

minetest.register_craftitem('sorcery:field_emitter',{
	description = 'Field Emitter';
	inventory_image = 'sorcery_field_emitter.png';
})

minetest.register_craft {
	output = 'sorcery:leyline_stabilizer';
	recipe = {
		{'basic_materials:copper_wire','group:sorcery_ley_cable','basic_materials:copper_wire'};
		{'sorcery:grease_neutralizing','group:sorcery_ley_cable','sorcery:grease_neutralizing'};
		{'basic_materials:copper_wire','group:sorcery_ley_cable','basic_materials:copper_wire'};
	};
	replacements = {
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
		{'sorcery:grease_neutralizing', 'xdecor:bowl'};
		{'sorcery:grease_neutralizing', 'xdecor:bowl'};
	};
}

minetest.register_craft {
	output = 'sorcery:beam_generator';
	recipe = {
		{'xpanes:bar_flat','xpanes:pane_flat','xpanes:bar_flat'};
		{'sorcery:screw_aluminum','sorcery:gem_sapphire','sorcery:screw_aluminum'};
		{'xpanes:bar_flat','sorcery:gem_luxite','xpanes:bar_flat'};
	};
}

minetest.register_craft {
	output = 'sorcery:suppression_matrix';
	recipe = {
		{'sorcery:fragment_electrum','basic_materials:steel_strip','sorcery:fragment_cobalt'};
		{'basic_materials:copper_strip','xpanes:bar_flat','basic_materials:copper_strip'};
		{'sorcery:fragment_cobalt','basic_materials:steel_strip','sorcery:fragment_electrum'};
	};
}

minetest.register_craft {
	output = 'sorcery:core_counterpraxic';
	recipe = {
		{'sorcery:gem_ruby_shard','sorcery:tungsten_ingot','sorcery:gem_ruby_shard'};
		{'sorcery:tungsten_ingot','sorcery:gem_emerald','sorcery:tungsten_ingot'};
		{'sorcery:gem_ruby_shard','sorcery:tungsten_ingot','sorcery:gem_ruby_shard'};
	};
}

minetest.register_craft {
	output = 'sorcery:inverter_coil';
	recipe = {
		{'sorcery:screw_platinum','basic_materials:steel_wire','sorcery:screw_platinum'};
		{'basic_materials:copper_wire','default:tin_ingot','basic_materials:copper_wire'};
		{'sorcery:screw_platinum','basic_materials:steel_wire','sorcery:screw_platinum'};
	};
	replacements = {
		{'basic_materials:steel_wire', 'basic_materials:empty_spool'};
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
		{'basic_materials:steel_wire', 'basic_materials:empty_spool'};
	};
}

minetest.register_craft {
	output = 'sorcery:field_emitter';
	recipe = {
		{'basic_materials:steel_bar','xpanes:pane_flat','basic_materials:steel_bar'};
		{'sorcery:beam_generator','sorcery:leyline_stabilizer','sorcery:beam_generator'};
		{'sorcery:beam_generator','basic_materials:copper_wire','sorcery:beam_generator'};
	};
	replacements = {
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
	};
}

minetest.register_craft {
	output = 'sorcery:emitter_barrier';
	recipe = {
		{'sorcery:suppression_matrix','sorcery:suppression_matrix','sorcery:suppression_matrix'};
		{'sorcery:field_emitter','sorcery:core_counterpraxic','sorcery:inverter_coil'};
		{'default:tin_ingot','default:tin_ingot','default:tin_ingot'};
	};
}

minetest.register_craft {
	output = 'sorcery:generator';
	recipe = {
		{'sorcery:aluminum_ingot','sorcery:aluminum_ingot','sorcery:aluminum_ingot'};
		{'default:bronze_ingot','basic_materials:copper_wire','default:bronze_ingot'};
		{'default:steel_ingot','default:furnace','default:steel_ingot'};
	};
	replacements = {
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
	};
}

minetest.register_craftitem('sorcery:candle', {
	-- TODO make candle node
	inventory_image = 'sorcery_candle.png';
	description = 'Votive Candle';
	groups = {
		candle = 1;
	};
})

minetest.register_craft {
	recipe = {
		{'farming:string'};
		{'basic_materials:paraffin'};
		{'basic_materials:paraffin'};
	};
	output = "sorcery:candle";
}

minetest.register_craft {
	recipe = {
		{'sorcery:candle','sorcery:candle','sorcery:candle'};
		{'sorcery:coin_gold','stairs:slab_stone','sorcery:coin_bronze'};
		{'','sorcery:coin_tin',''};
	};
	output = "sorcery:altar";
}
minetest.clear_craft { output = 'morelights:bulb'; }
minetest.register_craft {
	recipe = {
		{'xpanes:pane_flat', 'sorcery:gem_luxite_shard', 'xpanes:pane_flat'};
		{'sorcery:gem_luxite_shard', 'default:mese_crystal_fragment','sorcery:gem_luxite_shard'};
		{'xpanes:pane_flat', 'basic_materials:copper_wire', 'xpanes:pane_flat'};
	};
	replacements = {
		{'basic_materials:copper_wire', 'basic_materials:empty_spool'};
	};
	output = 'morelights:bulb 4';
}

local potion_auto_recipe = function(id, substance, tools, container)
	local recipe = tools
	local replace = {}
	local batches = 1
	for _,v in pairs(tools) do
		replace[#replace + 1] = {v,v}
	end

	if substance.core and #substance.core > 0 then
		batches = #substance.core
		recipe = sorcery.lib.tbl.append(recipe, substance.core)
	elseif container then
		recipe[#recipe + 1] = container
	end
	if substance.mix and #substance.mix > 0 then
		recipe = sorcery.lib.tbl.append(recipe, substance.mix)
		for _,r in pairs(substance.mix) do
			if sorcery.data.infusion_leftovers[r] then
				replace[#replace + 1] = {
					r, sorcery.data.infusion_leftovers[r]
				}
			end
		end
	end

	minetest.register_craft {
		type = 'shapeless';
		recipe = recipe;
		replacements = replace;
		output = id .. ' ' .. batches;
	}
end
-- auto-generate recipes for potionmaking oils
for n,v in pairs(sorcery.data.oils) do
	if (v.core and #v.core > 0) or (v.mix and #v.mix > 0) then
		local id = 'sorcery:oil_' .. n
		potion_auto_recipe(id,v,{'farming:mortar_pestle'},'xdecor:bowl')
	end
end

for n,v in pairs(sorcery.data.greases) do
	if (v.core and #v.core > 0) or (v.mix and #v.mix > 0) then
		local id = 'sorcery:grease_' .. n
		potion_auto_recipe(id,v,{'farming:mixing_bowl'},'xdecor:bowl')
	end
end
