sorcery  Diff

Differences From Artifact [1bf06d7139]:

To Artifact [bc084489e5]:


    42     42   
    43     43   local slot3x3 = {
    44     44   	{0,0}, {1,0}, {2,0};
    45     45   	{0,1}, {1,1}, {2,1};
    46     46   	{0,2}, {1,2}, {2,2};
    47     47   }
    48     48   local props_builtin = function(item)
    49         -	local props = minetest.registered_items[item]._sorcery
           49  +	local props = minetest.registered_items[ItemStack(item):get_name()]._sorcery
    50     50   	if props and props.recipe then
    51     51   		return props.recipe
    52     52   	end
    53     53   	return {}
    54     54   end
    55     55   local modofname = function(id)
    56     56   	local item = minetest.registered_nodes[id]
................................................................................
   149    149   		return i
   150    150   	end
   151    151   	return i
   152    152   end
   153    153   local function desc_builtin(i)
   154    154   	local desc
   155    155   	i, desc = group_eval(i)
   156         -	-- print('describing ',i,dump(minetest.registered_items[i]))
   157    156   	local s = ItemStack(i)
   158    157   	if not minetest.registered_items[s:get_name()] then
   159         -		minetest.log('WARNING: unknown item in recipe ' .. i)
          158  +		log.warn('unknown item in recipe',i)
   160    159   		return 'Unknown Item'
   161    160   	end
   162    161   	if not desc then desc = minetest.registered_items[s:get_name()].description end
   163    162   	if not desc then return 'Peculiar Item' end
   164    163   
   165    164   	local eol = string.find(desc,'\n')
   166    165   	if eol then desc = string.sub(desc,1,eol-1) end
................................................................................
   193    192   			for k,v in pairs(minetest.registered_items) do
   194    193   				if sorcery.itemclass.get(k, 'grindable') then
   195    194   					cache.grindables[#cache.grindables+1] = k
   196    195   				end
   197    196   			end
   198    197   		end
   199    198   	end;
          199  +
          200  +	populate_lathe = function(cache)
          201  +		if cache.lathe then return end
          202  +		cache.lathe = { tools = {} }
          203  +		for k in pairs(sorcery.lathe.techs) do cache.lathe.tools[k] = {} end
          204  +
          205  +		for id, item in pairs(minetest.registered_tools) do
          206  +			for group, tech in pairs(sorcery.lathe.tools) do
          207  +				if minetest.get_item_group(id, group) ~= 0 then
          208  +					local tt = cache.lathe.tools[tech]
          209  +					local mat = sorcery.itemclass.get(id, 'material')
          210  +					tt[#tt+1] = {
          211  +						id = id;
          212  +						ptr = item;
          213  +						level = mat and mat.data and (mat.data.maxlevel or mat.data.level) or nil;
          214  +					}
          215  +				end
          216  +			end
          217  +		end
          218  +		for _, tech in pairs(sorcery.lathe.tools) do
          219  +			table.sort(cache.lathe.tools[tech], function(a,b)
          220  +				return (a.level or 0) < (b.level or 0)
          221  +			end)
          222  +		end
          223  +	end;
   200    224   }
   201    225   sorcery.cookbook.classes = {
   202    226   	craft = {
   203    227   		name = 'Crafting Guide';
   204    228   		node = 'xdecor:workbench';
   205    229   		booksuf = 'Codex';
   206    230   		w = 3, h = 3;
................................................................................
   327    351   							return {v, 'sorcery:mill_grindhead_' .. metal}
   328    352   						end
   329    353   					end
   330    354   					return {v,''} -- !!
   331    355   				end
   332    356   			end
   333    357   		end;
          358  +	};
          359  +	lathe = {
          360  +		name = 'Lathe';
          361  +		chance = 1;
          362  +		node = 'sorcery:lathe';
          363  +		booksuf = 'Compendium';
          364  +		w = 2, h = 1;
          365  +		slots = { {1,0}, {0,0} };
          366  +		apply_exclusions = true;
          367  +		props = props_builtin;
          368  +		find = function(out)
          369  +			cache:populate_lathe()
          370  +			local mat = sorcery.itemclass.get(out, 'material')
          371  +			local level = 0
          372  +			if mat and mat.data and mat.data.level then
          373  +				level = mat.data.level
          374  +			end
          375  +			for input,tqs in pairs(sorcery.lathe.recipes) do
          376  +				for tech, defs in pairs(tqs) do
          377  +					for _, def in pairs(defs) do
          378  +						if ItemStack(def.output):get_name() == out then
          379  +							local tool
          380  +							if level > 0 then
          381  +								for _,t in pairs(cache.lathe.tools[tech]) do
          382  +									if (t.level or 0) >= level then
          383  +										tool = t.id
          384  +										break
          385  +									end
          386  +								end
          387  +							else
          388  +								tool = cache.lathe.tools[tech][1].id
          389  +							end
          390  +							if def.mass then input = input .. ' ' .. tostring(def.mass) end
          391  +							local rec = {input, tool or ''}
          392  +							return rec, {count = ItemStack(def.output):get_count()}
          393  +						end
          394  +					end
          395  +				end
          396  +			end
          397  +		end;
          398  +		pick = function(restrict)
          399  +			local p = {}
          400  +			for input,tqs in pairs(sorcery.lathe.recipes) do
          401  +				for tech, defs in pairs(tqs) do
          402  +					for _, def in pairs(defs) do
          403  +						local nm = ItemStack(def.output):get_name()
          404  +						if item_restrict_eval(nm, restrict) then
          405  +							p[#p+1] = nm
          406  +						end
          407  +					end
          408  +				end
          409  +			end
          410  +			return select(2, sorcery.lib.tbl.pick(p))
          411  +		end;
   334    412   	};
   335    413   	enchant = {
   336    414   		name = 'Enchantment Matrix';
   337    415   		node = 'sorcery:enchanter';
   338    416   		booksuf = 'Grimoire';
   339    417   		drawslots = false;
   340    418   		chance = 4;
................................................................................
   504    582   		img and 'image' or 'item_image',
   505    583   			k.w+1.1, k.h/2 - 0.5, minetest.formspec_escape(img or result),
   506    584   			k.w+1.1, k.h/2 - 0.5, minetest.formspec_escape(ot))
   507    585   end;
   508    586   
   509    587   local retrieve_recipe = function(kind,out,notes_right)
   510    588   	local rec = recipe_kinds[kind]
   511         -	local ing = rec.find(out)
          589  +	local ing, props = rec.find(out)
          590  +	if props then
          591  +		if props.count then
          592  +			out = out .. ' ' .. tostring(props.count)
          593  +		end
          594  +	end
   512    595   	return render_recipe(kind,ing,out,notes_right), rec.w, rec.h
   513    596   end
   514    597   
   515    598   sorcery.cookbook.setrecipe = function(stack,k,r,restrict)
   516    599   	local meta = stack:get_meta()
   517    600   	if not r then r,k = sorcery.cookbook.pickrecipe(k,restrict) end
   518    601   	if not r then return false end