sorcery  Artifact [378fef1f36]

Artifact 378fef1f3626d12a7588ad767a33a8228e64fb0027302889bb7391038d50fb4b:

  • File gems.lua — part of check-in [3f6a913e4e] at 2020-09-29 12:40:28 on branch trunk — * remove former hacky registration system, replace with consistent and flexible API; rewrite metal/gem generation to take advantage of this new API; tweaks to init system to enable world-local tweaks to lore and sorcery behavior * initial documentation commit * initial steps towards calendar - add default date format, astrolabe; prepare infra for division/melding/transmutation spells, various tweaks and fixes (user: lexi, size: 6366) [annotate] [blame] [check-ins using]

--- gemstones
local shards_per_gem = 9

local register_gem = function(name,gem)
	local itemname = gem.foreign or 'sorcery:gem_' .. name
	local shardname = gem.foreign_shard or 'sorcery:gem_' .. name .. '_shard'
	local amuletname = gem.foreign_amulet or 'sorcery:gem_' .. name .. '_amulet'

	sorcery.data.gems[name].parts = {
		item = itemname;
		shard = shardname;
		amulet = amuletname;
	}

	local tools, armors = sorcery.matreg.tools, sorcery.matreg.armors
	if gem.tools then for t,c in pairs(tools) do
		sorcery.matreg.lookup[(gem.items and gem.items[t]) or ('sorcery:' .. t .. '_' .. name)] = {
			gem = true;
			id = name; data = gem;
			value = c.cost*shards_per_gem;
		}
	end end
	if gem.armor then for a,c in pairs(armors) do
		sorcery.matreg.lookup[(gem.items and gem.items[a]) or ('sorcery:' .. a .. '_' .. name)] = {
			gem = true;
			id = name; data = gem;
			value = c.cost*shards_per_gem;
		}
	end end

	if gem.foreign_shard then
		minetest.clear_craft {output=shardname}
	else
		minetest.register_craftitem(shardname, {
			description = sorcery.lib.str.capitalize(name) .. ' shard';
			inventory_image = 'sorcery_gem_' .. name .. '_shard.png';
			groups = { gemshard = 1; crystalshard = 1; sorcery_shard = 1; };
			_sorcery = {
				material = {
					gem = true;
					id = name, data = gem;
					raw = true, value = 1;
				};
				recipe = {
					canonical = {
						craft = {
							{'','xdecor:hammer',''};
							{'',itemname,''};
						};
					}
				};
			};
		})
	end
	if not gem.foreign_amulet then
		minetest.register_craftitem(amuletname, {
			description = sorcery.lib.str.capitalize(name) .. ' amulet';
			inventory_image = sorcery.lib.image('sorcery_amulet.png'):multiply(sorcery.lib.color(gem.tone)):render();
			_sorcery = {
				material = {
					gem = true, id = name, data = gem;
					value = (5 * shards_per_gem) + 4;
				};
			};
		}) 
	end
	minetest.register_craft {
		type = 'shapeless';
		recipe = (minetest.get_modpath('xdecor') and {
			'xdecor:hammer', itemname;
		}) or { itemname };
		output = shardname .. ' 9';
		replacements = {
			{'xdecor:hammer','xdecor:hammer'};
		};
	}
	minetest.register_craft {
		type = 'shapeless';
		recipe = {
			shardname, shardname, shardname;
			shardname, shardname, shardname;
			shardname, shardname, shardname;
		};
		output = itemname;
	};
	minetest.register_craft {
		recipe = {
			{shardname,itemname,shardname};
			{itemname,itemname,itemname};
			{shardname,itemname,shardname};
		};
		output = amuletname;
	};

	-- generate lenses and crafting recipes
	for _, kind in pairs { 'amplifier','rectifier','concave','convex' } do
		local id = 'sorcery:lens_' .. kind .. '_' .. name
		minetest.register_tool(id, {
			inventory_image = sorcery.lib.image('sorcery_lens_overlay_gold.png'):
				blit(sorcery.lib.image('sorcery_lens_' .. kind .. '.png'):
					multiply(sorcery.lib.color(gem.tone):brighten(1.1))):
				render();
			description = sorcery.lib.str.capitalize(name) .. ' ' .. sorcery.lib.str.capitalize(kind) .. ' Lens';
			groups = { sorcery_enchanting_lens = 1 };
			_proto = {
				gem = name;
				kind = kind;
			};
		})
	end
	do local casing = 'sorcery:fragment_gold'
		minetest.register_craft {
			output = 'sorcery:lens_convex_' .. name;
			recipe = {
				{'',       casing, ''};
				{itemname, casing, itemname};
				{'',       casing, ''};
			};
		}
		minetest.register_craft {
			output = 'sorcery:lens_concave_' .. name;
			recipe = {
				{itemname, casing, itemname};
				{'',       casing, ''};
				{itemname, casing, itemname};
			};
		}
		minetest.register_craft {
			output = 'sorcery:lens_amplifier_' .. name;
			recipe = {
				{itemname, casing, itemname};
				{shardname,casing, shardname};
				{shardname,casing, shardname};
			};
		}
		minetest.register_craft {
			output = 'sorcery:lens_rectifier_' .. name;
			recipe = {
				{shardname,casing, shardname};
				{'basic_materials:silver_wire',casing,'basic_materials:silver_wire'};
				{itemname, casing, itemname};
			};
			replacements = {
				{'basic_materials:silver_wire', 'basic_materials:empty_spool'};
				{'basic_materials:silver_wire', 'basic_materials:empty_spool'};
			};
		}
	end

	if gem.foreign then return false end
	minetest.register_craftitem(itemname, {
		description = sorcery.lib.str.capitalize(name);
		inventory_image = 'sorcery_gem_' .. name .. '.png';
		groups = { gem = 1; crystal = 1; sorcery_gem = 1; };
		_sorcery = {
			material = {
				id = name, data = gem;
				raw = true, value = shards_per_gem;
			};
		};
	})
	local tools = gem.tools
	if tools == nil then tools = {
		'group:pickaxe';
		'group:pick'; -- FUCK YOU INSTANT_ORES
		'~default:enchanted_pick_'; -- FUCK YOU XDECOR
	} end

	local ores = gem.ores
	if ores == nil then ores = {
		['default:stone_with_coal'] = 1.0;
		['default:stone_with_iron'] = 0.7;
		['default:stone_with_copper'] = 0.6;
		['default:stone_with_tin'] = 0.8;
		['default:stone_with_gold'] = 1.5;
		--
		['sorcery:stone_with_cobalt'] = 0.9;
		['sorcery:stone_with_tungsten'] = 0.3;
		['sorcery:stone_with_platinum'] = 0.6;
		['sorcery:stone_with_iridium'] = 1.6;
		['sorcery:stone_with_lithium'] = 1.4;
	} end

	for ore,fac in pairs(ores) do
		local drops = minetest.registered_nodes[ore].drop
		local newdrops
		if type(drops) == 'string' then
			newdrops = {
				max_items = 1;
				items = {
					{ rarity = 1; items = { drops }; };
				};
			}
		else newdrops = sorcery.lib.tbl.copy(drops) end
		
		newdrops.max_items = newdrops.max_items + 1
		newdrops.items[#newdrops.items + 1] = {
			rarity = gem.rarity * fac;
			items = { itemname };
		};

		minetest.override_item(ore, {drop = newdrops})
		-- might be possible to just edit it in place, since we're
		-- referring to registered_nodes anyway, but i don't want
		-- to chance it; god knows what's going on under the hood
	end
end

-- for g,v in pairs(sorcery.data.gems) do sorcery.register_gem(g,v) end
sorcery.register.gems.foreach('sorcery:generate',{},register_gem)

sorcery.gem = {
	getdrops = function(fac)
		items = {}
		for g,v in pairs(sorcery.data.gems) do
			items[#items + 1] = {
				rarity = gem.rarity * fac;
				items = { itemname };
			};
		end
		return items
	end;
};
-- register gem cutting tools
--   - abrasive powder
--   - hand-drill

-- register gem cuts (cube, sphere, circlet, triangle, rod)
-- cube, sphere, and triangle are used in enchanting. all are used in crafting.