sorcery  Artifact [e866e2741b]

Artifact e866e2741b655a7b50fc27d8538d55de8bc416ecb29bbb5edba39f4ff7b145b2:

  • File gems.lua — part of check-in [96c5289a2a] at 2020-10-21 03:35:35 on branch trunk — add rune forges, runes, amulet frames, write sacrifice spell, touch up amulet graphics, enable enchantment of amulets (though spells cannot yet be cast), defuckulate syncresis core icon, unfuckitize sneaky leycalc bug that's probably been the cause of some long-standing wackiness, add item classes, add some more textures, disbungle various other asstastrophes, remove sneaky old debug code, improve library code, add utility for uploading merge requests (user: lexi, size: 7479) [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
		local img = sorcery.lib.image
		local img_stone = img('sorcery_amulet.png'):multiply(sorcery.lib.color(gem.tone))
		local img_sparkle = img('sorcery_amulet_sparkle.png')
		minetest.register_craftitem(amuletname, {
			description = sorcery.lib.str.capitalize(name) .. ' amulet';
			inventory_image = img_sparkle:blit(img_stone):render();
			wield_scale = { x = 0.6, y = 0.6, z = 0.6 };
			groups = { sorcery_amulet = 1 };
			_sorcery = {
				material = {
					gem = true, id = name, data = gem;
					value = (5 * shards_per_gem) + 4;
				};
				amulet = { base = name };
			};
		}) 
		sorcery.register.metals.foreach('sorcery:mk-amulet-frames-'..name,{'sorcery:generate'}, function(metalid,metal)
			if not metal.amulet then return end
			local framedid = string.format("%s_frame_%s", amuletname, metalid)
			local img_frame = img(string.format('sorcery_amulet_frame_%s.png',metalid))
			minetest.register_craftitem(framedid, {
				description = string.format("%s-framed %s amulet",sorcery.lib.str.capitalize(metalid), name);
				inventory_image = img_sparkle:blit(img_frame):blit(img_stone):render();
				wield_scale = { x = 0.6, y = 0.6, z = 0.6 };
				groups = { sorcery_amulet = 1 };
				_sorcery = {
					amulet = { base = name, frame = metalid };
				};
			})
			local frag = metal.parts.fragment
			minetest.register_craft {
				output = framedid;
				recipe = {
					{'',  frag,''};
					{frag,amuletname,frag};
					{'',  frag,''};
				};
			}
		end)
	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.