mirror of
				https://github.com/minetest-mods/craftguide.git
				synced 2025-11-04 15:05:30 +01:00 
			
		
		
		
	Compare commits
	
		
			5 Commits
		
	
	
		
			1.11.4
			...
			aa47a70e12
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| aa47a70e12 | |||
| 0463712cbb | |||
| 1745cc0ba3 | |||
| 66fc47a1c3 | |||
| 
						 | 
					d6542a2697 | 
							
								
								
									
										361
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										361
									
								
								init.lua
									
									
									
									
									
								
							@@ -1,5 +1,12 @@
 | 
				
			|||||||
craftguide = {}
 | 
					craftguide = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local p = 0
 | 
				
			||||||
 | 
					local CORE_VERSION = core.get_version().string:match("[^%-]*"):gsub("%.", function(a)
 | 
				
			||||||
 | 
						p = p + 1
 | 
				
			||||||
 | 
						return p == 3 and a or ""
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
 | 
					CORE_VERSION = tonumber(CORE_VERSION)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Caches
 | 
					-- Caches
 | 
				
			||||||
local pdata         = {}
 | 
					local pdata         = {}
 | 
				
			||||||
local init_items    = {}
 | 
					local init_items    = {}
 | 
				
			||||||
@@ -37,11 +44,18 @@ local get_player_by_name = core.get_player_by_name
 | 
				
			|||||||
local slz, dslz = core.serialize, core.deserialize
 | 
					local slz, dslz = core.serialize, core.deserialize
 | 
				
			||||||
local on_mods_loaded = core.register_on_mods_loaded
 | 
					local on_mods_loaded = core.register_on_mods_loaded
 | 
				
			||||||
local on_leaveplayer = core.register_on_leaveplayer
 | 
					local on_leaveplayer = core.register_on_leaveplayer
 | 
				
			||||||
local get_player_info = core.get_player_information
 | 
					 | 
				
			||||||
local on_receive_fields = core.register_on_player_receive_fields
 | 
					local on_receive_fields = core.register_on_player_receive_fields
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local ESC = core.formspec_escape
 | 
					local ESC = core.formspec_escape
 | 
				
			||||||
local S = core.get_translator("craftguide")
 | 
					local S = CORE_VERSION >= 500 and core.get_translator("craftguide") or
 | 
				
			||||||
 | 
						function(...)
 | 
				
			||||||
 | 
							local args, i = {...}, 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return args[1]:gsub("@%d+", function()
 | 
				
			||||||
 | 
								i = i + 1
 | 
				
			||||||
 | 
								return args[i]
 | 
				
			||||||
 | 
							end)
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local ES = function(...)
 | 
					local ES = function(...)
 | 
				
			||||||
	return ESC(S(...))
 | 
						return ESC(S(...))
 | 
				
			||||||
@@ -76,11 +90,9 @@ local PNG = {
 | 
				
			|||||||
	next     = "craftguide_next_icon.png",
 | 
						next     = "craftguide_next_icon.png",
 | 
				
			||||||
	arrow    = "craftguide_arrow.png",
 | 
						arrow    = "craftguide_arrow.png",
 | 
				
			||||||
	fire     = "craftguide_fire.png",
 | 
						fire     = "craftguide_fire.png",
 | 
				
			||||||
	fire_anim = "craftguide_fire_anim.png",
 | 
					 | 
				
			||||||
	book     = "craftguide_book.png",
 | 
						book     = "craftguide_book.png",
 | 
				
			||||||
	sign     = "craftguide_sign.png",
 | 
						sign     = "craftguide_sign.png",
 | 
				
			||||||
	selected = "craftguide_selected.png",
 | 
						selected = "craftguide_selected.png",
 | 
				
			||||||
	furnace_anim = "craftguide_furnace_anim.png",
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	search_hover = "craftguide_search_icon_hover.png",
 | 
						search_hover = "craftguide_search_icon_hover.png",
 | 
				
			||||||
	clear_hover  = "craftguide_clear_icon_hover.png",
 | 
						clear_hover  = "craftguide_clear_icon_hover.png",
 | 
				
			||||||
@@ -96,7 +108,6 @@ local FMT = {
 | 
				
			|||||||
	tooltip = "tooltip[%f,%f;%f,%f;%s]",
 | 
						tooltip = "tooltip[%f,%f;%f,%f;%s]",
 | 
				
			||||||
	item_image = "item_image[%f,%f;%f,%f;%s]",
 | 
						item_image = "item_image[%f,%f;%f,%f;%s]",
 | 
				
			||||||
	image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]",
 | 
						image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]",
 | 
				
			||||||
	animated_image = "animated_image[%f,%f;%f,%f;%s:%u,%u]",
 | 
					 | 
				
			||||||
	item_image_button = "item_image_button[%f,%f;%f,%f;%s;%s;%s]",
 | 
						item_image_button = "item_image_button[%f,%f;%f,%f;%s;%s;%s]",
 | 
				
			||||||
	arrow = "image_button[%f,%f;0.8,0.8;%s;%s;;;false;%s]",
 | 
						arrow = "image_button[%f,%f;0.8,0.8;%s;%s;;;false;%s]",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -545,7 +556,7 @@ local function get_usages(item)
 | 
				
			|||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function get_burntime(item)
 | 
					local function get_burntime(item)
 | 
				
			||||||
	return get_craft_result{method = "fuel", items = {item}}.time
 | 
						return get_craft_result({method = "fuel", items = {item}}).time
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function cache_fuel(item)
 | 
					local function cache_fuel(item)
 | 
				
			||||||
@@ -579,15 +590,10 @@ local function get_recipes(item, data, player)
 | 
				
			|||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local no_recipes = not recipes or #recipes == 0
 | 
						local no_recipes = not recipes or #recipes == 0
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if no_recipes and not usages then
 | 
						if no_recipes and not usages then
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	elseif sfinv_only then
 | 
						elseif sfinv_only and usages and no_recipes then
 | 
				
			||||||
		if usages and no_recipes then
 | 
					 | 
				
			||||||
		data.show_usages = true
 | 
							data.show_usages = true
 | 
				
			||||||
		elseif recipes and not usages then
 | 
					 | 
				
			||||||
			data.show_usages = nil
 | 
					 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if not sfinv_only or (sfinv_only and data.show_usages) then
 | 
						if not sfinv_only or (sfinv_only and data.show_usages) then
 | 
				
			||||||
@@ -633,24 +639,7 @@ local function repairable(tool)
 | 
				
			|||||||
	return toolrepair and def and def.groups and def.groups.disable_repair ~= 1
 | 
						return toolrepair and def and def.groups and def.groups.disable_repair ~= 1
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function is_fav(data)
 | 
					 | 
				
			||||||
	local fav, i
 | 
					 | 
				
			||||||
	for j = 1, #data.favs do
 | 
					 | 
				
			||||||
		if data.favs[j] == data.query_item then
 | 
					 | 
				
			||||||
			fav = true
 | 
					 | 
				
			||||||
			i = j
 | 
					 | 
				
			||||||
			break
 | 
					 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
	end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return fav, i
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
local function get_desc(name)
 | 
					local function get_desc(name)
 | 
				
			||||||
	if sub(name, 1, 1) == "_" then
 | 
					 | 
				
			||||||
		name = sub(name, 2)
 | 
					 | 
				
			||||||
	end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	local def = reg_items[name]
 | 
						local def = reg_items[name]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return def and (match(def.description, "%)([%w%s]*)") or def.description) or
 | 
						return def and (match(def.description, "%)([%w%s]*)") or def.description) or
 | 
				
			||||||
@@ -711,7 +700,7 @@ local function get_tooltip(name, info)
 | 
				
			|||||||
	return fmt("tooltip[%s;%s]", name, ESC(tooltip))
 | 
						return fmt("tooltip[%s;%s]", name, ESC(tooltip))
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function get_output_fs(data, fs, L)
 | 
					local function get_output_fs(fs, L)
 | 
				
			||||||
	local custom_recipe = craft_types[L.recipe.type]
 | 
						local custom_recipe = craft_types[L.recipe.type]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if custom_recipe or L.shapeless or L.recipe.type == "cooking" then
 | 
						if custom_recipe or L.shapeless or L.recipe.type == "cooking" then
 | 
				
			||||||
@@ -725,18 +714,15 @@ local function get_output_fs(data, fs, L)
 | 
				
			|||||||
		local pos_x = L.rightest + L.btn_size + 0.1
 | 
							local pos_x = L.rightest + L.btn_size + 0.1
 | 
				
			||||||
		local pos_y = YOFFSET + (sfinv_only and 0.25 or -0.45)
 | 
							local pos_y = YOFFSET + (sfinv_only and 0.25 or -0.45)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if data.fs_version >= 3 and sub(icon, 1, 18) == "craftguide_furnace" then
 | 
					 | 
				
			||||||
			fs[#fs + 1] = fmt(FMT.animated_image,
 | 
					 | 
				
			||||||
				pos_x, pos_y + L.spacing, 0.5, 0.5, PNG.furnace_anim, 8, 180)
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
		fs[#fs + 1] = fmt(FMT.image, pos_x, pos_y + L.spacing, 0.5, 0.5, icon)
 | 
							fs[#fs + 1] = fmt(FMT.image, pos_x, pos_y + L.spacing, 0.5, 0.5, icon)
 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local tooltip = custom_recipe and custom_recipe.description or
 | 
							local tooltip = custom_recipe and custom_recipe.description or
 | 
				
			||||||
				L.shapeless and S"Shapeless" or S"Cooking"
 | 
									L.shapeless and S"Shapeless" or S"Cooking"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if CORE_VERSION >= 500 then
 | 
				
			||||||
			fs[#fs + 1] = fmt(FMT.tooltip, pos_x, pos_y + L.spacing, 0.5, 0.5, ESC(tooltip))
 | 
								fs[#fs + 1] = fmt(FMT.tooltip, pos_x, pos_y + L.spacing, 0.5, 0.5, ESC(tooltip))
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local arrow_X = L.rightest + (L._btn_size or 1.1)
 | 
						local arrow_X = L.rightest + (L._btn_size or 1.1)
 | 
				
			||||||
	local output_X = arrow_X + 0.9
 | 
						local output_X = arrow_X + 0.9
 | 
				
			||||||
@@ -746,31 +732,23 @@ local function get_output_fs(data, fs, L)
 | 
				
			|||||||
		0.9, 0.7, PNG.arrow)
 | 
							0.9, 0.7, PNG.arrow)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if L.recipe.type == "fuel" then
 | 
						if L.recipe.type == "fuel" then
 | 
				
			||||||
		if data.fs_version >= 3 then
 | 
					 | 
				
			||||||
			fs[#fs + 1] = fmt(FMT.animated_image,
 | 
					 | 
				
			||||||
				output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
 | 
					 | 
				
			||||||
				1.1, 1.1, PNG.fire_anim, 8, 180)
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
		fs[#fs + 1] = fmt(FMT.image,
 | 
							fs[#fs + 1] = fmt(FMT.image,
 | 
				
			||||||
			output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
 | 
								output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
 | 
				
			||||||
			1.1, 1.1, PNG.fire)
 | 
								1.1, 1.1, PNG.fire)
 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		local item = L.recipe.output
 | 
							local item = L.recipe.output
 | 
				
			||||||
		item = clean_name(item)
 | 
							item = clean_name(item)
 | 
				
			||||||
		local name = match(item, "%S*")
 | 
							local name = match(item, "%S*")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if data.fs_version >= 3 then
 | 
							if CORE_VERSION >= 510 then
 | 
				
			||||||
			fs[#fs + 1] = fmt(FMT.image,
 | 
								fs[#fs + 1] = fmt(FMT.image,
 | 
				
			||||||
				output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
 | 
									output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
 | 
				
			||||||
				1.1, 1.1, PNG.selected)
 | 
									1.1, 1.1, PNG.selected)
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local _name = sfinv_only and name or fmt("_%s", name)
 | 
							fs[#fs + 1] = fmt(FMT.item_image_button,
 | 
				
			||||||
 | 
					 | 
				
			||||||
		fs[#fs + 1] = fmt("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
 | 
					 | 
				
			||||||
			output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
 | 
								output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
 | 
				
			||||||
			1.1, 1.1, item, _name, "")
 | 
								1.1, 1.1, item, name, "")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local infos = {
 | 
							local infos = {
 | 
				
			||||||
			unknown  = not reg_items[name] or nil,
 | 
								unknown  = not reg_items[name] or nil,
 | 
				
			||||||
@@ -780,7 +758,7 @@ local function get_output_fs(data, fs, L)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if next(infos) then
 | 
							if next(infos) then
 | 
				
			||||||
			fs[#fs + 1] = get_tooltip(_name, infos)
 | 
								fs[#fs + 1] = get_tooltip(name, infos)
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if infos.burntime then
 | 
							if infos.burntime then
 | 
				
			||||||
@@ -788,20 +766,14 @@ local function get_output_fs(data, fs, L)
 | 
				
			|||||||
				output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1) + L.spacing,
 | 
									output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1) + L.spacing,
 | 
				
			||||||
				0.6, 0.4, PNG.arrow)
 | 
									0.6, 0.4, PNG.arrow)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if data.fs_version >= 3 then
 | 
					 | 
				
			||||||
				fs[#fs + 1] = fmt(FMT.animated_image,
 | 
					 | 
				
			||||||
					output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0) + L.spacing,
 | 
					 | 
				
			||||||
					0.6, 0.6, PNG.fire_anim, 8, 180)
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
			fs[#fs + 1] = fmt(FMT.image,
 | 
								fs[#fs + 1] = fmt(FMT.image,
 | 
				
			||||||
				output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0) + L.spacing,
 | 
									output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0) + L.spacing,
 | 
				
			||||||
				0.6, 0.6, PNG.fire)
 | 
									0.6, 0.6, PNG.fire)
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function get_grid_fs(data, fs, rcp, spacing)
 | 
					local function get_grid_fs(fs, rcp, spacing)
 | 
				
			||||||
	local width = rcp.width or 1
 | 
						local width = rcp.width or 1
 | 
				
			||||||
	local replacements = rcp.replacements
 | 
						local replacements = rcp.replacements
 | 
				
			||||||
	local rarity = rcp.rarity
 | 
						local rarity = rcp.rarity
 | 
				
			||||||
@@ -880,9 +852,10 @@ local function get_grid_fs(data, fs, rcp, spacing)
 | 
				
			|||||||
			end
 | 
								end
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if data.fs_version >= 3 and not large_recipe then
 | 
							if CORE_VERSION >= 510 and not large_recipe then
 | 
				
			||||||
			fs[#fs + 1] = fmt(FMT.image,
 | 
								fs[#fs + 1] = fmt(FMT.image,
 | 
				
			||||||
				X, Y + (sfinv_only and 0.7 or 0), btn_size, btn_size, PNG.selected)
 | 
									X, Y + (sfinv_only and 0.7 or 0),
 | 
				
			||||||
 | 
									btn_size, btn_size, PNG.selected)
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fs[#fs + 1] = fmt(FMT.item_image_button,
 | 
							fs[#fs + 1] = fmt(FMT.item_image_button,
 | 
				
			||||||
@@ -906,7 +879,7 @@ local function get_grid_fs(data, fs, rcp, spacing)
 | 
				
			|||||||
		fs[#fs + 1] = "style_type[item_image_button;border=false]"
 | 
							fs[#fs + 1] = "style_type[item_image_button;border=false]"
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	get_output_fs(data, fs, {
 | 
						get_output_fs(fs, {
 | 
				
			||||||
		recipe    = rcp,
 | 
							recipe    = rcp,
 | 
				
			||||||
		shapeless = shapeless,
 | 
							shapeless = shapeless,
 | 
				
			||||||
		rightest  = rightest,
 | 
							rightest  = rightest,
 | 
				
			||||||
@@ -918,57 +891,33 @@ local function get_grid_fs(data, fs, rcp, spacing)
 | 
				
			|||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function get_panels(data, fs)
 | 
					local function get_panels(data, fs)
 | 
				
			||||||
	local start_y = data.fs_version >= 3 and (sfinv_only and 0.33 or 0) or 0.33
 | 
						local panels = {recipes = data.recipes or {}, usages = data.usages or {}}
 | 
				
			||||||
 | 
						local x = 0.33
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local panels = {
 | 
						if sfinv_only then
 | 
				
			||||||
		{dat = data.usages or {}, height = 3.5},
 | 
							panels = data.show_usages and {usages = data.usages} or {recipes = data.recipes}
 | 
				
			||||||
		{dat = data.recipes or {}, height = 3.5},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if data.fs_version >= 3 and not sfinv_only then
 | 
					 | 
				
			||||||
		panels.favs = {dat = {}, height = 2.19}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	elseif sfinv_only then
 | 
					 | 
				
			||||||
		panels = data.show_usages and
 | 
					 | 
				
			||||||
			{{dat = data.usages}} or {{dat = data.recipes}}
 | 
					 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for k, v in pairs(panels) do
 | 
						for k, v in pairs(panels) do
 | 
				
			||||||
		start_y = start_y + 1
 | 
							x = x + 1
 | 
				
			||||||
		local spacing = (start_y - 1) * 3.6
 | 
							local spacing = (x - 1) * 3.6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if not sfinv_only then
 | 
							if not sfinv_only then
 | 
				
			||||||
			fs[#fs + 1] = fmt("background9[8.1,%f;6.6,%f;%s;false;%d]",
 | 
								fs[#fs + 1] = CORE_VERSION >= 510 and
 | 
				
			||||||
				-0.2 + spacing, v.height, PNG.bg_full, 10)
 | 
									fmt("background9[8.1,%f;6.6,3.5;%s;false;%d]",
 | 
				
			||||||
 | 
										-0.2 + spacing, PNG.bg_full, 10) or
 | 
				
			||||||
			if data.fs_version >= 3 and k == 2 then
 | 
									fmt("background[8.1,%f;6.6,3.5;%s;false]",
 | 
				
			||||||
				local fav = is_fav(data)
 | 
										-0.2 + spacing, PNG.bg_full)
 | 
				
			||||||
				local nfavs = #data.favs
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				fs[#fs + 1] = fmt(
 | 
					 | 
				
			||||||
					"style[fav;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]",
 | 
					 | 
				
			||||||
					fmt("craftguide_fav%s.png", fav and "" or "_off"),
 | 
					 | 
				
			||||||
					fmt("craftguide_fav%s.png", fav and "_off" or ""),
 | 
					 | 
				
			||||||
					fmt("craftguide_fav%s.png", fav and "_off" or ""))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if nfavs < 6 or (nfavs >= 6 and fav) then
 | 
					 | 
				
			||||||
					fs[#fs + 1] = fmt(FMT.image_button,
 | 
					 | 
				
			||||||
						14, spacing, 0.5, 0.45, "", "fav", "")
 | 
					 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				fs[#fs + 1] = fmt("tooltip[fav;%s]",
 | 
							local rn = #v
 | 
				
			||||||
					fav and ES"Unmark this item" or ES"Mark this item")
 | 
					 | 
				
			||||||
			end
 | 
					 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		local rn = #v.dat
 | 
					 | 
				
			||||||
		local _rn = tostring(rn)
 | 
							local _rn = tostring(rn)
 | 
				
			||||||
		local xu = tostring(data.unum) .. _rn
 | 
							local xu = tostring(data.unum) .. _rn
 | 
				
			||||||
		local xr = tostring(data.rnum) .. _rn
 | 
							local xr = tostring(data.rnum) .. _rn
 | 
				
			||||||
		xu = max(-0.3, -((#xu - 3) * 0.05))
 | 
							xu = max(-0.3, -((#xu - 3) * 0.15))
 | 
				
			||||||
		xr = max(-0.3, -((#xr - 3) * 0.05))
 | 
							xr = max(-0.3, -((#xr - 3) * 0.15))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local is_recipe = sfinv_only and not data.show_usages or k == 2
 | 
							local is_recipe = k == "recipes"
 | 
				
			||||||
		local lbl
 | 
							local lbl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if not sfinv_only and rn == 0 then
 | 
							if not sfinv_only and rn == 0 then
 | 
				
			||||||
@@ -989,16 +938,16 @@ local function get_panels(data, fs)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		fs[#fs + 1] = fmt(FMT.label,
 | 
							fs[#fs + 1] = fmt(FMT.label,
 | 
				
			||||||
			XOFFSET + (sfinv_only and 2.3 or 1.6) + (is_recipe and xr or xu),
 | 
								XOFFSET + (sfinv_only and 2.3 or 1.6) + (is_recipe and xr or xu),
 | 
				
			||||||
			YOFFSET + (sfinv_only and 3.4 or 1.5 + spacing), lbl)
 | 
								YOFFSET + (sfinv_only and 3.35 or 1.5 + spacing), lbl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if rn > 1 then
 | 
							if rn > 1 then
 | 
				
			||||||
			local btn_suffix = is_recipe and "recipe" or "usage"
 | 
								local btn_suffix = is_recipe and "recipe" or "usage"
 | 
				
			||||||
			local prev_name = fmt("prev_%s", btn_suffix)
 | 
								local prev_name = fmt("prev_%s", btn_suffix)
 | 
				
			||||||
			local next_name = fmt("next_%s", btn_suffix)
 | 
								local next_name = fmt("next_%s", btn_suffix)
 | 
				
			||||||
			local x_arrow = XOFFSET + (sfinv_only and 1.7 or 1)
 | 
								local x_arrow = XOFFSET + (sfinv_only and 1.7 or 1)
 | 
				
			||||||
			local y_arrow = YOFFSET + (sfinv_only and 3.3 or 1.4 + spacing)
 | 
								local y_arrow = YOFFSET + (sfinv_only and 3.25 or 1.4 + spacing)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if data.fs_version >= 3 then
 | 
								if CORE_VERSION >= 520 then
 | 
				
			||||||
				fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
 | 
									fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
 | 
				
			||||||
					x_arrow + (is_recipe and xr or xu), y_arrow,
 | 
										x_arrow + (is_recipe and xr or xu), y_arrow,
 | 
				
			||||||
						PNG.prev, prev_name, "",
 | 
											PNG.prev, prev_name, "",
 | 
				
			||||||
@@ -1011,68 +960,51 @@ local function get_panels(data, fs)
 | 
				
			|||||||
			end
 | 
								end
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local rcp = is_recipe and v.dat[data.rnum] or v.dat[data.unum]
 | 
							local rcp = is_recipe and v[data.rnum] or v[data.unum]
 | 
				
			||||||
		if rcp then
 | 
							if rcp then
 | 
				
			||||||
			get_grid_fs(data, fs, rcp, spacing)
 | 
								get_grid_fs(fs, rcp, spacing)
 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if k == "favs" and data.fs_version >= 3 and not sfinv_only then
 | 
					 | 
				
			||||||
			fs[#fs + 1] = fmt(FMT.label, 8.3, spacing - 0.1, ES"Bookmarks")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			for i = 1, #data.favs do
 | 
					 | 
				
			||||||
				local item = data.favs[i]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if data.query_item == item then
 | 
					 | 
				
			||||||
					fs[#fs + 1] = fmt(FMT.image,
 | 
					 | 
				
			||||||
						7.85 + (i - 0.5), spacing + 0.45,
 | 
					 | 
				
			||||||
						1.1, 1.1, PNG.selected)
 | 
					 | 
				
			||||||
				end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				fs[#fs + 1] = fmt(FMT.item_image_button,
 | 
					 | 
				
			||||||
					7.85 + (i - 0.5), spacing + 0.45,
 | 
					 | 
				
			||||||
					1.1, 1.1, item, item, "")
 | 
					 | 
				
			||||||
			end
 | 
					 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function make_fs(data)
 | 
					local function make_formspec(name)
 | 
				
			||||||
 | 
						local data = pdata[name]
 | 
				
			||||||
	local fs = {}
 | 
						local fs = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if not sfinv_only then
 | 
				
			||||||
		fs[#fs + 1] = fmt([[
 | 
							fs[#fs + 1] = fmt([[
 | 
				
			||||||
			size[%f,%f]
 | 
								size[%f,%f]
 | 
				
			||||||
			no_prepend[]
 | 
								no_prepend[]
 | 
				
			||||||
			bgcolor[#0000]
 | 
								bgcolor[#0000]
 | 
				
			||||||
 | 
								style_type[image_button;border=false]
 | 
				
			||||||
 | 
								style_type[item_image_button;border=false;bgimg_hovered=%s]
 | 
				
			||||||
		]],
 | 
							]],
 | 
				
			||||||
	ROWS + (data.query_item and 6.7 or 0) - 1.2, LINES - 0.3)
 | 
							ROWS + (data.query_item and 6.7 or 0) - 1.2, LINES - 0.3, PNG.selected)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if not sfinv_only then
 | 
							fs[#fs + 1] = CORE_VERSION >= 510 and
 | 
				
			||||||
		fs[#fs + 1] = fmt("background9[-0.15,-0.2;%f,%f;%s;false;%d]",
 | 
								fmt("background9[-0.15,-0.2;%f,%f;%s;false;%d]",
 | 
				
			||||||
			ROWS - 0.9, LINES + 0.4, PNG.bg_full, 10)
 | 
									ROWS - 0.9, LINES + 0.4, PNG.bg_full, 10) or
 | 
				
			||||||
 | 
								fmt("background[-0.15,-0.2;%f,%f;%s;false]",
 | 
				
			||||||
 | 
									ROWS - 0.9, LINES + 0.4, PNG.bg_full)
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fs[#fs + 1] = fmt([[
 | 
						fs[#fs + 1] = fmt([[
 | 
				
			||||||
		style[filter;border=false]
 | 
							field[0.25,0.2;%f,1;filter;;%s]
 | 
				
			||||||
		field[0.4,0.2;2.5,1;filter;;%s]
 | 
					 | 
				
			||||||
		field_close_on_enter[filter;false]
 | 
							field_close_on_enter[filter;false]
 | 
				
			||||||
		box[0,0;2.4,0.6;#ffffff25]
 | 
					 | 
				
			||||||
	]],
 | 
						]],
 | 
				
			||||||
	ESC(data.filter))
 | 
						sfinv_only and 2.76 or 2.72, ESC(data.filter))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if data.fs_version >= 3 then
 | 
						if CORE_VERSION >= 520 then
 | 
				
			||||||
		fs[#fs + 1] = fmt([[
 | 
							fs[#fs + 1] = fmt([[
 | 
				
			||||||
			style_type[image_button;border=false]
 | 
					 | 
				
			||||||
			style_type[item_image_button;border=false;bgimg_hovered=%s;bgimg_pressed=%s]
 | 
					 | 
				
			||||||
			style[search;fgimg=%s;fgimg_hovered=%s]
 | 
								style[search;fgimg=%s;fgimg_hovered=%s]
 | 
				
			||||||
			style[clear;fgimg=%s;fgimg_hovered=%s]
 | 
								style[clear;fgimg=%s;fgimg_hovered=%s]
 | 
				
			||||||
			style[prev_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
 | 
								style[prev_page;fgimg=%s;fgimg_hovered=%s]
 | 
				
			||||||
			style[next_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
 | 
								style[next_page;fgimg=%s;fgimg_hovered=%s]
 | 
				
			||||||
		]],
 | 
							]],
 | 
				
			||||||
		PNG.selected, PNG.selected,
 | 
					 | 
				
			||||||
		PNG.search, PNG.search_hover,
 | 
							PNG.search, PNG.search_hover,
 | 
				
			||||||
		PNG.clear,  PNG.clear_hover,
 | 
							PNG.clear,  PNG.clear_hover,
 | 
				
			||||||
		PNG.prev, PNG.prev_hover, PNG.prev_hover,
 | 
							PNG.prev,   PNG.prev_hover,
 | 
				
			||||||
		PNG.next, PNG.next_hover, PNG.next_hover)
 | 
							PNG.next,   PNG.next_hover)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fs[#fs + 1] = fmt(mul_elem(FMT.image_button, 4),
 | 
							fs[#fs + 1] = fmt(mul_elem(FMT.image_button, 4),
 | 
				
			||||||
			sfinv_only and 2.6 or 2.54, -0.06, 0.85, 0.85, "", "search", "",
 | 
								sfinv_only and 2.6 or 2.54, -0.06, 0.85, 0.85, "", "search", "",
 | 
				
			||||||
@@ -1089,9 +1021,9 @@ local function make_fs(data)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
 | 
							fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
 | 
				
			||||||
			sfinv_only and 5.45 or (ROWS * 6.83) / 11, -0.05,
 | 
								sfinv_only and 5.45 or (ROWS * 6.83) / 11, -0.05,
 | 
				
			||||||
				PNG.prev, "prev_page", PNG.prev_hover,
 | 
									PNG.prev, "prev_page", PNG.prev,
 | 
				
			||||||
			sfinv_only and 7.2 or (ROWS * 8.75) / 11, -0.05,
 | 
								sfinv_only and 7.2 or (ROWS * 8.75) / 11, -0.05,
 | 
				
			||||||
				PNG.next, "next_page", PNG.next_hover)
 | 
									PNG.next, "next_page", PNG.next)
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	data.pagemax = max(1, ceil(#data.items / IPP))
 | 
						data.pagemax = max(1, ceil(#data.items / IPP))
 | 
				
			||||||
@@ -1121,7 +1053,7 @@ local function make_fs(data)
 | 
				
			|||||||
		local X = i % ROWS
 | 
							local X = i % ROWS
 | 
				
			||||||
		local Y = (i % IPP - X) / ROWS + 1
 | 
							local Y = (i % IPP - X) / ROWS + 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if data.fs_version >= 3 and data.query_item == item then
 | 
							if CORE_VERSION >= 510 and data.query_item == item then
 | 
				
			||||||
			fs[#fs + 1] = fmt(FMT.image,
 | 
								fs[#fs + 1] = fmt(FMT.image,
 | 
				
			||||||
				X - (X * (sfinv_only and 0.12 or 0.14)) - 0.05,
 | 
									X - (X * (sfinv_only and 0.12 or 0.14)) - 0.05,
 | 
				
			||||||
				Y - (Y * 0.1) - 0.1,
 | 
									Y - (Y * 0.1) - 0.1,
 | 
				
			||||||
@@ -1142,11 +1074,10 @@ local function make_fs(data)
 | 
				
			|||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local show_fs = function(player, name)
 | 
					local show_fs = function(player, name)
 | 
				
			||||||
	local data = pdata[name]
 | 
					 | 
				
			||||||
	if sfinv_only then
 | 
						if sfinv_only then
 | 
				
			||||||
		sfinv.set_player_inventory_formspec(player)
 | 
							sfinv.set_player_inventory_formspec(player)
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		show_formspec(name, "craftguide", make_fs(data))
 | 
							show_formspec(name, "craftguide", make_formspec(name))
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1160,6 +1091,16 @@ craftguide.register_craft_type("digging_chance", {
 | 
				
			|||||||
	icon = "default_tool_mesepick.png",
 | 
						icon = "default_tool_mesepick.png",
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local function sfind(str, filter)
 | 
				
			||||||
 | 
						if filter == "" then
 | 
				
			||||||
 | 
							return 0
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if find(str, filter, 1, true) then
 | 
				
			||||||
 | 
							return #str - #filter
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function search(data)
 | 
					local function search(data)
 | 
				
			||||||
	local filter = data.filter
 | 
						local filter = data.filter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1181,30 +1122,28 @@ local function search(data)
 | 
				
			|||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local filtered_list, c = {}, 0
 | 
						local filtered_list, order, c = {}, {}, 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i = 1, #data.items_raw do
 | 
						for i = 1, #data.items_raw do
 | 
				
			||||||
		local item = data.items_raw[i]
 | 
							local item = data.items_raw[i]
 | 
				
			||||||
		local def  = reg_items[item]
 | 
							local def  = reg_items[item]
 | 
				
			||||||
		local desc = (def and def.description) and lower(def.description) or ""
 | 
							local desc = (def and def.description) and lower(def.description) or ""
 | 
				
			||||||
		local search_in = fmt("%s %s", item, desc)
 | 
					 | 
				
			||||||
		local to_add
 | 
							local to_add
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if search_filter then
 | 
							if search_filter then
 | 
				
			||||||
			for filter_name, values in pairs(filters) do
 | 
								for filter_name, values in pairs(filters) do
 | 
				
			||||||
				if values then
 | 
					 | 
				
			||||||
				local func = search_filters[filter_name]
 | 
									local func = search_filters[filter_name]
 | 
				
			||||||
				to_add = func(item, values) and (search_filter == "" or
 | 
									to_add = func(item, values) and (search_filter == "" or
 | 
				
			||||||
						find(search_in, search_filter, 1, true))
 | 
										(sfind(item, search_filter) or sfind(desc, search_filter)))
 | 
				
			||||||
				end
 | 
					 | 
				
			||||||
			end
 | 
								end
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			to_add = find(search_in, filter, 1, true)
 | 
								to_add = sfind(item, filter) or sfind(desc, filter)
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if to_add then
 | 
							if to_add then
 | 
				
			||||||
			c = c + 1
 | 
								c = c + 1
 | 
				
			||||||
			filtered_list[c] = item
 | 
								filtered_list[c] = item
 | 
				
			||||||
 | 
								order[item] = to_add
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1217,6 +1156,10 @@ local function search(data)
 | 
				
			|||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sort(filtered_list, function(a, b)
 | 
				
			||||||
 | 
							return order[a] < order[b]
 | 
				
			||||||
 | 
						end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	data.items = filtered_list
 | 
						data.items = filtered_list
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1377,20 +1320,20 @@ local function handle_drops_table(name, drop)
 | 
				
			|||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for item, count in pairs(drop_sure) do
 | 
						for item, count in pairs(drop_sure) do
 | 
				
			||||||
		craftguide.register_craft{
 | 
							craftguide.register_craft({
 | 
				
			||||||
			type = "digging",
 | 
								type = "digging",
 | 
				
			||||||
			items = {name},
 | 
								items = {name},
 | 
				
			||||||
			output = fmt("%s %u", item, count),
 | 
								output = fmt("%s %u", item, count),
 | 
				
			||||||
		}
 | 
							})
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for item, data in pairs(drop_maybe) do
 | 
						for item, data in pairs(drop_maybe) do
 | 
				
			||||||
		craftguide.register_craft{
 | 
							craftguide.register_craft({
 | 
				
			||||||
			type = "digging_chance",
 | 
								type = "digging_chance",
 | 
				
			||||||
			items = {name},
 | 
								items = {name},
 | 
				
			||||||
			output = fmt("%s %u", item, data.output),
 | 
								output = fmt("%s %u", item, data.output),
 | 
				
			||||||
			rarity = data.rarity,
 | 
								rarity = data.rarity,
 | 
				
			||||||
		}
 | 
							})
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1399,11 +1342,11 @@ local function register_drops(name, def)
 | 
				
			|||||||
	local dstack = ItemStack(drop)
 | 
						local dstack = ItemStack(drop)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if not dstack:is_empty() and dstack:get_name() ~= name then
 | 
						if not dstack:is_empty() and dstack:get_name() ~= name then
 | 
				
			||||||
		craftguide.register_craft{
 | 
							craftguide.register_craft({
 | 
				
			||||||
			type = "digging",
 | 
								type = "digging",
 | 
				
			||||||
			items = {name},
 | 
								items = {name},
 | 
				
			||||||
			output = drop,
 | 
								output = drop,
 | 
				
			||||||
		}
 | 
							})
 | 
				
			||||||
	elseif is_table(drop) then
 | 
						elseif is_table(drop) then
 | 
				
			||||||
		handle_drops_table(name, drop)
 | 
							handle_drops_table(name, drop)
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
@@ -1473,7 +1416,7 @@ local function get_init_items()
 | 
				
			|||||||
		last_str = str
 | 
							last_str = str
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local full_char, empty_char = "▰", "▱"
 | 
						local full_char, empty_char = "o", "."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for name, def in pairs(reg_items) do
 | 
						for name, def in pairs(reg_items) do
 | 
				
			||||||
		ic = ic + 1
 | 
							ic = ic + 1
 | 
				
			||||||
@@ -1483,7 +1426,7 @@ local function get_init_items()
 | 
				
			|||||||
			bar = bar .. (i <= percent / (100 / len) and full_char or empty_char)
 | 
								bar = bar .. (i <= percent / (100 / len) and full_char or empty_char)
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		iop(fmt("[craftguide] Caching data  %s  %u%%\r", bar, percent))
 | 
							iop(fmt("[craftguide] Caching data  %s  %u%%\n", bar, percent))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if show_item(def) then
 | 
							if show_item(def) then
 | 
				
			||||||
			if not fuel_cache[name] then
 | 
								if not fuel_cache[name] then
 | 
				
			||||||
@@ -1514,23 +1457,24 @@ local function get_init_items()
 | 
				
			|||||||
			fuel    = fuel_cache,
 | 
								fuel    = fuel_cache,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		http.fetch_async{
 | 
							http.fetch_async({
 | 
				
			||||||
			url = craftguide.export_url,
 | 
								url = craftguide.export_url,
 | 
				
			||||||
			post_data = write_json(post_data),
 | 
								post_data = write_json(post_data),
 | 
				
			||||||
		}
 | 
							})
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	print()
 | 
						print()
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function init_data(name)
 | 
					local function init_data(name)
 | 
				
			||||||
 | 
						local items = CORE_VERSION >= 500 and init_items or
 | 
				
			||||||
 | 
							(#init_items == 0 and get_init_items() or init_items)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pdata[name] = {
 | 
						pdata[name] = {
 | 
				
			||||||
		filter    = "",
 | 
							filter    = "",
 | 
				
			||||||
		pagenum   = 1,
 | 
							pagenum   = 1,
 | 
				
			||||||
		items      = init_items,
 | 
							items     = items,
 | 
				
			||||||
		items_raw  = init_items,
 | 
							items_raw = items,
 | 
				
			||||||
		favs       = {},
 | 
					 | 
				
			||||||
		fs_version = get_player_info(name).formspec_version,
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1546,7 +1490,9 @@ local function reset_data(data)
 | 
				
			|||||||
	data.items       = data.items_raw
 | 
						data.items       = data.items_raw
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if CORE_VERSION >= 500 then
 | 
				
			||||||
	on_mods_loaded(get_init_items)
 | 
						on_mods_loaded(get_init_items)
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
on_joinplayer(function(player)
 | 
					on_joinplayer(function(player)
 | 
				
			||||||
	local name = player:get_player_name()
 | 
						local name = player:get_player_name()
 | 
				
			||||||
@@ -1556,25 +1502,22 @@ end)
 | 
				
			|||||||
local function fields(player, _f)
 | 
					local function fields(player, _f)
 | 
				
			||||||
	local name = player:get_player_name()
 | 
						local name = player:get_player_name()
 | 
				
			||||||
	local data = pdata[name]
 | 
						local data = pdata[name]
 | 
				
			||||||
	--print(dump(_f))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if _f.clear then
 | 
						if _f.clear then
 | 
				
			||||||
		reset_data(data)
 | 
							reset_data(data)
 | 
				
			||||||
 | 
							return true, show_fs(player, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	elseif _f.prev_recipe or _f.next_recipe then
 | 
						elseif _f.prev_recipe or _f.next_recipe then
 | 
				
			||||||
		local num = data.rnum + (_f.prev_recipe and -1 or 1)
 | 
							local num = data.rnum + (_f.prev_recipe and -1 or 1)
 | 
				
			||||||
		data.rnum = data.recipes[num] and num or (_f.prev_recipe and #data.recipes or 1)
 | 
							data.rnum = data.recipes[num] and num or (_f.prev_recipe and #data.recipes or 1)
 | 
				
			||||||
 | 
							return true, show_fs(player, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	elseif _f.prev_usage or _f.next_usage then
 | 
						elseif _f.prev_usage or _f.next_usage then
 | 
				
			||||||
		local num = data.unum + (_f.prev_usage and -1 or 1)
 | 
							local num = data.unum + (_f.prev_usage and -1 or 1)
 | 
				
			||||||
		data.unum = data.usages[num] and num or (_f.prev_usage and #data.usages or 1)
 | 
							data.unum = data.usages[num] and num or (_f.prev_usage and #data.usages or 1)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	elseif _f.key_enter_field == "filter" or _f.search then
 | 
					 | 
				
			||||||
		if _f.filter == "" then
 | 
					 | 
				
			||||||
			reset_data(data)
 | 
					 | 
				
			||||||
		return true, show_fs(player, name)
 | 
							return true, show_fs(player, name)
 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						elseif (_f.key_enter_field == "filter" or _f.search) and _f.filter ~= "" then
 | 
				
			||||||
		local str = lower(_f.filter)
 | 
							local str = lower(_f.filter)
 | 
				
			||||||
		if data.filter == str then return end
 | 
							if data.filter == str then return end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1582,6 +1525,8 @@ local function fields(player, _f)
 | 
				
			|||||||
		data.pagenum = 1
 | 
							data.pagenum = 1
 | 
				
			||||||
		search(data)
 | 
							search(data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return true, show_fs(player, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	elseif _f.prev_page or _f.next_page then
 | 
						elseif _f.prev_page or _f.next_page then
 | 
				
			||||||
		if data.pagemax == 1 then return end
 | 
							if data.pagemax == 1 then return end
 | 
				
			||||||
		data.pagenum = data.pagenum - (_f.prev_page and 1 or -1)
 | 
							data.pagenum = data.pagenum - (_f.prev_page and 1 or -1)
 | 
				
			||||||
@@ -1592,15 +1537,7 @@ local function fields(player, _f)
 | 
				
			|||||||
			data.pagenum = data.pagemax
 | 
								data.pagenum = data.pagemax
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	elseif _f.fav then
 | 
							return true, show_fs(player, name)
 | 
				
			||||||
		local fav, i = is_fav(data)
 | 
					 | 
				
			||||||
		local total = #data.favs
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if total < 6 and not fav then
 | 
					 | 
				
			||||||
			data.favs[total + 1] = data.query_item
 | 
					 | 
				
			||||||
		elseif fav then
 | 
					 | 
				
			||||||
			remove(data.favs, i)
 | 
					 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		local item
 | 
							local item
 | 
				
			||||||
		for field in pairs(_f) do
 | 
							for field in pairs(_f) do
 | 
				
			||||||
@@ -1614,8 +1551,6 @@ local function fields(player, _f)
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		elseif sub(item, -4) == "_inv" then
 | 
							elseif sub(item, -4) == "_inv" then
 | 
				
			||||||
			item = sub(item, 1, -5)
 | 
								item = sub(item, 1, -5)
 | 
				
			||||||
		elseif sub(item, 1, 1) == "_" then
 | 
					 | 
				
			||||||
			item = sub(item, 2)
 | 
					 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		item = reg_aliases[item] or item
 | 
							item = reg_aliases[item] or item
 | 
				
			||||||
@@ -1626,37 +1561,28 @@ local function fields(player, _f)
 | 
				
			|||||||
			else
 | 
								else
 | 
				
			||||||
				data.show_usages = not data.show_usages
 | 
									data.show_usages = not data.show_usages
 | 
				
			||||||
			end
 | 
								end
 | 
				
			||||||
		elseif item == data.query_item then
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local recipes, usages = get_recipes(item, data, player)
 | 
							local recipes, usages = get_recipes(item, data, player)
 | 
				
			||||||
		if not recipes and not usages then return end
 | 
							if not recipes and not usages then return end
 | 
				
			||||||
		if data.show_usages and not usages then return end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		data.query_item = item
 | 
							data.query_item = item
 | 
				
			||||||
		data.recipes    = recipes
 | 
							data.recipes    = recipes
 | 
				
			||||||
		data.usages     = usages
 | 
							data.usages     = usages
 | 
				
			||||||
		data.rnum       = 1
 | 
							data.rnum       = 1
 | 
				
			||||||
		data.unum       = 1
 | 
							data.unum       = 1
 | 
				
			||||||
	end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return true, show_fs(player, name)
 | 
							return true, show_fs(player, name)
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if sfinv_only then
 | 
					if sfinv_only then
 | 
				
			||||||
	sfinv.register_page("craftguide:craftguide", {
 | 
						sfinv.register_page("craftguide:craftguide", {
 | 
				
			||||||
		title = S"Craft Guide",
 | 
							title = S"Craft Guide",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		is_in_nav = function(self, player, context)
 | 
					 | 
				
			||||||
			local name = player:get_player_name()
 | 
					 | 
				
			||||||
			return get_player_info(name).formspec_version >= 2
 | 
					 | 
				
			||||||
		end,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		get = function(self, player, context)
 | 
							get = function(self, player, context)
 | 
				
			||||||
			local name = player:get_player_name()
 | 
								local name = player:get_player_name()
 | 
				
			||||||
			local data = pdata[name]
 | 
								local formspec = make_formspec(name)
 | 
				
			||||||
			local formspec = make_fs(data)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return sfinv.make_formspec(player, context, formspec)
 | 
								return sfinv.make_formspec(player, context, formspec)
 | 
				
			||||||
		end,
 | 
							end,
 | 
				
			||||||
@@ -1684,19 +1610,14 @@ else
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	local function on_use(user)
 | 
						local function on_use(user)
 | 
				
			||||||
		local name = user:get_player_name()
 | 
							local name = user:get_player_name()
 | 
				
			||||||
		local data = pdata[name]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if data.fs_version == 1 then
 | 
					 | 
				
			||||||
			return msg(name, "Your Minetest client is outdated. " ..
 | 
					 | 
				
			||||||
				"Get the latest version on minetest.net to use the Crafting Guide.")
 | 
					 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if next(recipe_filters) then
 | 
							if next(recipe_filters) then
 | 
				
			||||||
 | 
								local data = pdata[name]
 | 
				
			||||||
			data.items_raw = get_filtered_items(user)
 | 
								data.items_raw = get_filtered_items(user)
 | 
				
			||||||
			search(data)
 | 
								search(data)
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		show_formspec(name, "craftguide", make_fs(data))
 | 
							show_formspec(name, "craftguide", make_formspec(name))
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	core.register_craftitem("craftguide:book", {
 | 
						core.register_craftitem("craftguide:book", {
 | 
				
			||||||
@@ -1737,29 +1658,29 @@ else
 | 
				
			|||||||
		end
 | 
							end
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	core.register_craft{
 | 
						core.register_craft({
 | 
				
			||||||
		output = "craftguide:book",
 | 
							output = "craftguide:book",
 | 
				
			||||||
		type   = "shapeless",
 | 
							type   = "shapeless",
 | 
				
			||||||
		recipe = {"default:book"}
 | 
							recipe = {"default:book"}
 | 
				
			||||||
	}
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	core.register_craft{
 | 
						core.register_craft({
 | 
				
			||||||
		type = "fuel",
 | 
							type = "fuel",
 | 
				
			||||||
		recipe = "craftguide:book",
 | 
							recipe = "craftguide:book",
 | 
				
			||||||
		burntime = 3
 | 
							burntime = 3
 | 
				
			||||||
	}
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	core.register_craft{
 | 
						core.register_craft({
 | 
				
			||||||
		output = "craftguide:sign",
 | 
							output = "craftguide:sign",
 | 
				
			||||||
		type   = "shapeless",
 | 
							type   = "shapeless",
 | 
				
			||||||
		recipe = {"default:sign_wall_wood"}
 | 
							recipe = {"default:sign_wall_wood"}
 | 
				
			||||||
	}
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	core.register_craft{
 | 
						core.register_craft({
 | 
				
			||||||
		type = "fuel",
 | 
							type = "fuel",
 | 
				
			||||||
		recipe = "craftguide:sign",
 | 
							recipe = "craftguide:sign",
 | 
				
			||||||
		burntime = 10
 | 
							burntime = 10
 | 
				
			||||||
	}
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if rawget(_G, "sfinv_buttons") then
 | 
						if rawget(_G, "sfinv_buttons") then
 | 
				
			||||||
		sfinv_buttons.register_button("craftguide", {
 | 
							sfinv_buttons.register_button("craftguide", {
 | 
				
			||||||
@@ -1965,34 +1886,39 @@ if progressive_mode then
 | 
				
			|||||||
		local name = player:get_player_name()
 | 
							local name = player:get_player_name()
 | 
				
			||||||
		local data = pdata[name]
 | 
							local data = pdata[name]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if CORE_VERSION >= 500 then
 | 
				
			||||||
			local meta = player:get_meta()
 | 
								local meta = player:get_meta()
 | 
				
			||||||
			data.inv_items = dslz(meta:get_string("inv_items")) or {}
 | 
								data.inv_items = dslz(meta:get_string("inv_items")) or {}
 | 
				
			||||||
			data.known_recipes = dslz(meta:get_string("known_recipes")) or 0
 | 
								data.known_recipes = dslz(meta:get_string("known_recipes")) or 0
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								data.inv_items = dslz(player:get_attribute("inv_items")) or {}
 | 
				
			||||||
 | 
								data.known_recipes = dslz(player:get_attribute("known_recipes")) or 0
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		data.hud = {
 | 
							data.hud = {
 | 
				
			||||||
			bg = player:hud_add{
 | 
								bg = player:hud_add({
 | 
				
			||||||
				hud_elem_type = "image",
 | 
									hud_elem_type = "image",
 | 
				
			||||||
				position      = {x = 0.78, y = 1},
 | 
									position      = {x = 0.78, y = 1},
 | 
				
			||||||
				alignment     = {x = 1,    y = 1},
 | 
									alignment     = {x = 1,    y = 1},
 | 
				
			||||||
				scale         = {x = 370,  y = 112},
 | 
									scale         = {x = 370,  y = 112},
 | 
				
			||||||
				text          = PNG.bg,
 | 
									text          = PNG.bg,
 | 
				
			||||||
			},
 | 
								}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			book = player:hud_add{
 | 
								book = player:hud_add({
 | 
				
			||||||
				hud_elem_type = "image",
 | 
									hud_elem_type = "image",
 | 
				
			||||||
				position      = {x = 0.79, y = 1.02},
 | 
									position      = {x = 0.79, y = 1.02},
 | 
				
			||||||
				alignment     = {x = 1,    y = 1},
 | 
									alignment     = {x = 1,    y = 1},
 | 
				
			||||||
				scale         = {x = 4,    y = 4},
 | 
									scale         = {x = 4,    y = 4},
 | 
				
			||||||
				text          = PNG.book,
 | 
									text          = PNG.book,
 | 
				
			||||||
			},
 | 
								}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			text = player:hud_add{
 | 
								text = player:hud_add({
 | 
				
			||||||
				hud_elem_type = "text",
 | 
									hud_elem_type = "text",
 | 
				
			||||||
				position      = {x = 0.84, y = 1.04},
 | 
									position      = {x = 0.84, y = 1.04},
 | 
				
			||||||
				alignment     = {x = 1,    y = 1},
 | 
									alignment     = {x = 1,    y = 1},
 | 
				
			||||||
				number        = 0xffffff,
 | 
									number        = 0xfff,
 | 
				
			||||||
				text          = "",
 | 
									text          = "",
 | 
				
			||||||
			},
 | 
								}),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	end)
 | 
						end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2002,13 +1928,22 @@ if progressive_mode then
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local function save_meta(player)
 | 
						local function save_meta(player)
 | 
				
			||||||
		local meta = player:get_meta()
 | 
							local meta
 | 
				
			||||||
		local name = player:get_player_name()
 | 
							local name = player:get_player_name()
 | 
				
			||||||
		local data = pdata[name]
 | 
							local data = pdata[name]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if CORE_VERSION >= 500 then
 | 
				
			||||||
 | 
								meta = player:get_meta()
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for i = 1, #to_save do
 | 
							for i = 1, #to_save do
 | 
				
			||||||
			local meta_name = to_save[i]
 | 
								local meta_name = to_save[i]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if CORE_VERSION >= 500 then
 | 
				
			||||||
				meta:set_string(meta_name, slz(data[meta_name]))
 | 
									meta:set_string(meta_name, slz(data[meta_name]))
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									player:set_attribute(meta_name, slz(data[meta_name]))
 | 
				
			||||||
 | 
								end
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2094,3 +2029,5 @@ register_command("craft", {
 | 
				
			|||||||
		return true, craftguide.show(name, node_name)
 | 
							return true, craftguide.show(name, node_name)
 | 
				
			||||||
	end,
 | 
						end,
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					minetest.log("action", "[craftguide] loaded.")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ License of source code
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
The MIT License (MIT)
 | 
					The MIT License (MIT)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Copyright (c) 2015-2020 Jean-Patrick Guerrero and contributors.
 | 
					Copyright (c) 2015-2019 Jean-Patrick Guerrero and contributors.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
				
			||||||
of this software and associated documentation files (the "Software"), to deal
 | 
					of this software and associated documentation files (the "Software"), to deal
 | 
				
			||||||
 
 | 
				
			|||||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 1.6 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 3.4 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 5.5 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 4.5 KiB  | 
		Reference in New Issue
	
	Block a user