[Mod] Craft Guide [craft_guide] - Shows crafts for all loade

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Linuxdirk » Post

Napiophelios wrote:there is room if you ditch to chitchat about "Learn to craft..."
Yes, that could be removed completely and without any replacement :) And then there would be enough space to display even a 5×5 grid.

I don’t know if it’s possible, but the 3×3 grid could be displayed centered in the space the large grid would take. It wouldn’t look that bad.

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by cornernote » Post

Thats probably the best idea. The workbench is 5x5 (i dont think there are any 6x6 ones), so it would fit.

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Linuxdirk » Post

Is it possible to scale the slots? They’re usually displayed large enough to be visible even when scaled down by 50 percent. with this you could even add a 10×10 grid in the space of a 5×5 grid.

User avatar
Napiophelios
Member
Posts: 1035
Joined: Mon Jul 07, 2014 01:14
GitHub: Napiophelios
IRC: Nappi
In-game: Nappi

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Napiophelios » Post

The note has value and shouldnt be gotten rid of entirely;
First time users may not know how to get things started.

In BookMarks GUI the usage note dissappears when the first bookmark is created,
Can something like that be done here? Like a temporary instuctions?

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Linuxdirk » Post

Napiophelios wrote:First time users may not know how to get things started.
Well, first-time users could/should/did read this. The text could be extended and usage instructions could be given there for people that are too lazy to click the link leading to the instructions.

User avatar
Napiophelios
Member
Posts: 1035
Joined: Mon Jul 07, 2014 01:14
GitHub: Napiophelios
IRC: Nappi
In-game: Nappi

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Napiophelios » Post

Linuxdirk wrote:
Napiophelios wrote:First time users may not know how to get things started.
Well, first-time users could/should/did read this. The text could be extended and usage instructions could be given there for people that are too lazy to click the link leading to the instructions.
Thats funny and true...but just in case..
lets assume they are just too excited to get started to read the instructions
and help them out a little. :)

Miner59
Member
Posts: 46
Joined: Mon Sep 22, 2014 19:14

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Miner59 » Post

Hi cornernote,
I made a diff file with a formatted version of my code. It adds a button instead of a unknown item, when a crafting recipe contains a item called "group:xy". Also changes search function a bit and adds switching from first to last page and reverse.
Please copy from below.

Code: Select all

--- newest_git.lua	2014-12-14 16:33:08.000000000 +0100
+++ api_craft_guide.lua	2014-12-14 17:00:44.000000000 +0100
@@ -18,8 +18,6 @@
 
 -- define api variables
 craft_guide.crafts = {}
-craft_guide.groups = {}
-craft_guide.group_messages = {}
 
 
 -- log
@@ -51,6 +49,11 @@
 	if search == nil then 
 		search = meta:get_string("search")
 	end
+	if meta:get_string("formspec")=="" then
+		meta:set_string("saved_search","|")
+		meta:set_string("saved_page","1")
+		meta:set_string("saved_pages","1")
+	end
 	if page == nil then 
 		page = craft_guide.get_current_page(meta) 
 	end
@@ -59,7 +62,7 @@
 	end
 	local inv = meta:get_inventory()
 	local size = inv:get_size("main")
-	local start = (page-1) * (5*14) + 1
+	local start = (page-1) * (5*14) --was one too much before
 	local pages = math.floor((size-1) / (5*14) + 1)
 	local alternates = 0
 	local stack = inv:get_stack("output",1)
@@ -67,6 +70,126 @@
 	if crafts ~= nil then
 		alternates = #crafts
 	end
+	local build=""
+	for ii=1,9,1 do
+		local build_old=build
+		local build_stack = inv:get_stack("build",ii)
+		if build_stack~=nil then
+			local build_name=build_stack:get_name()
+			if string.sub(build_name,1,6)=="group:" then
+				local groups=string.sub(build_name,7)
+				local saved=""
+				for name,def in pairs(minetest.registered_items) do
+					local hasgroup=1
+					for group in string.gmatch(groups,"([^,]+)") do
+						if minetest.get_item_group(name, group)==0 then
+							hasgroup=0
+						end
+					end
+					if hasgroup==1 then
+                                                --prefer items from default mod
+						if string.sub(name,1,8)=="default:" then
+							build=build.."item_image_button["..tostring(2+((ii-1)%3))..","
+							..tostring(7+math.floor((ii-1)/3))..";1,1;"
+							..name..";t_758s"..tostring(ii)..";group]"
+							.."tooltip[t_758s"..tostring(ii)..";"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
+
+							saved=""
+							break
+						else
+							saved=name
+						end
+					end
+				end
+				if saved~="" then
+					build=build.."item_image_button["..tostring(2+((ii-1)%3))..","
+					..tostring(7+math.floor((ii-1)/3))..";1,1;"..saved..";t_758s"..tostring(ii)..";group]"
+					.."tooltip[t_758s"..tostring(ii)..";"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
+				end
+			end
+		end
+		if build_old==build then
+			build=build.."list[current_name;build;"..tostring(2+((ii-1)%3))..","..tostring(7+math.floor((ii-1)/3))..";1,1;"..tostring(ii-1).."]"
+		end
+	end
+	local cook=""
+	local cook_stack = inv:get_stack("cook",1)
+	if cook_stack~=nil then
+		local cook_name=cook_stack:get_name()
+		if string.sub(cook_name,1,6)=="group:" then
+			local groups=string.sub(cook_name,7)
+			local saved=""
+			for name,def in pairs(minetest.registered_items) do
+				local hasgroup=1
+				for group in string.gmatch(groups,"([^,]+)") do
+					if minetest.get_item_group(name, group)==0 then
+						hasgroup=0
+					end
+				end
+				if hasgroup==1 then
+					if string.sub(name,1,8)=="default:" then
+						cook="item_image_button[6,7;1,1;"..name..";c_758s1;group]"
+						.."tooltip[c_758s1;"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
+	
+						saved=""
+						break
+					else
+						saved=name
+					end
+				end
+			end
+			if saved~="" then
+				cook="item_image_button[6,7;1,1;"..saved..";c_758s1;group]"
+				.."tooltip[c_758s1;"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
+			end
+		end
+		if cook=="" then
+			cook="list[current_name;cook;6,7;1,1;]"
+		end
+	end
+
+	local fuel=""
+	local fuel_stack = inv:get_stack("fuel",1)
+	if fuel_stack~=nil then
+		local fuel_name=fuel_stack:get_name()
+		if string.sub(fuel_name,1,6)=="group:" then
+			local groups=string.sub(fuel_name,7)
+			local saved=""
+			for name,def in pairs(minetest.registered_items) do
+				local hasgroup=1
+				for group in string.gmatch(groups,"([^,]+)") do
+					if minetest.get_item_group(name, group)==0 then
+						hasgroup=0
+					end
+				end
+				if hasgroup==1 then
+					if string.sub(name,1,8)=="default:" then
+						fuel="item_image_button[6,7;1,1;"..name..";f_758s1;group]"
+						.."tooltip[f_758s1;"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
+	
+						saved=""
+						break
+					else
+						saved=name
+					end
+				end
+			end
+			if saved~="" then
+				fuel="item_image_button[6,7;1,1;"..saved..";f_758s1;group]"
+				.."tooltip[f_758s1;"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
+			end
+		end
+		if fuel=="" then
+			fuel="list[current_name;fuel;6,9;1,1;]"
+		end
+	end
+
+	back=""
+	if meta:get_string("saved_search")~="|" then
+		back="button[6,5.8;2.7,1;back_button;<--- Back]"
+	end
+
+
 	local formspec = "size[14,10;]"
 		.."list[current_name;main;0,0;14,5;"..tostring(start).."]"
 
@@ -76,7 +199,7 @@
 
 		.."field[6,5.4;2,1;craft_guide_search_box;;"..tostring(search).."]"
 		.."button[7.5,5.1;1.2,1;craft_guide_search_button;Search]"
-
+		..back
 		.."label[9,5.2;page "..tostring(page).." of "..tostring(pages).."]"
 		.."button[11,5;1.5,1;craft_guide_prev;<<]"
 		.."button[12.5,5;1.5,1;craft_guide_next;>>]"
@@ -85,13 +208,11 @@
 		.."list[current_name;output;0,7;1,1;]"
 
 		.."label[2,6.5;Inventory Craft]"
-		.."list[current_name;build;2,7;3,3;]"
-
+		..build
 		.."label[6,6.5;Cook]"
-		.."list[current_name;cook;6,7;1,1;]"
+		..cook
 		.."label[6,8.5;Fuel]"
-		.."list[current_name;fuel;6,9;1,1;]"
-
+		..fuel
 		.."label[8,6.5;Bookmarks]"
 		.."list[current_name;bookmark;8,7;6,3;]"
 
@@ -142,23 +263,43 @@
 	
 	-- search
 	search = fields.craft_guide_search_box
+	if search~=nil then
+		--empty search input when there is no caracter or digit, "*" displays all items registered
+		if string.lower(search)==string.upper(search) and tonumber(search)==nil and search~="*" then
+			search=""
+		end
+	end
+
 	meta:set_string("search", search)
 	if fields.craft_guide_search_button then
+	meta:set_string("saved_search", "|")
 		page = 1
 	end
 
 	-- change page
 	if fields.craft_guide_prev then
 		page = page - 1
+	if page < 1 then
+		page = pages
+	end
+
 	end
 	if fields.craft_guide_next then
 		page = page + 1
-	end
-	if page < 1 then
+	if page > pages then
 		page = 1
 	end
-	if page > pages then
-		page = pages
+	end
+
+	if fields.back_button then
+		local saved = meta:get_string("saved_search")
+		if saved~="|" then
+			search=saved
+			meta:set_string("search", saved)
+			page=tonumber(meta:get_string("saved_page"))
+			pages=tonumber(meta:get_string("saved_pages"))
+			meta:set_string("saved_search", "|")
+		end
 	end
 
 	-- get an alternate recipe
@@ -170,6 +311,177 @@
 		alternate = 1
 	end
 
+	--group buttons
+	local starts=""
+	local ends=""
+	local xx=""
+	local formspec = meta:get_string("formspec")
+	if fields.c_758s1 then --cook
+		xx,starts=string.find(formspec,"tooltip%[c_758s1;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.f_758s1 then --fuel
+		xx,starts=string.find(formspec,"tooltip%[f_758s1;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.t_758s1 then 
+		xx,starts=string.find(formspec,"tooltip%[t_758s1;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.t_758s2 then 
+		xx,starts=string.find(formspec,"tooltip%[t_758s2;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.t_758s3 then 
+		xx,starts=string.find(formspec,"tooltip%[t_758s3;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.t_758s4 then 
+		xx,starts=string.find(formspec,"tooltip%[t_758s4;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.t_758s5 then 
+		xx,starts=string.find(formspec,"tooltip%[t_758s5;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.t_758s6 then 
+		xx,starts=string.find(formspec,"tooltip%[t_758s6;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.t_758s7 then 
+		xx,starts=string.find(formspec,"tooltip%[t_758s7;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.t_758s8 then 
+		xx,starts=string.find(formspec,"tooltip%[t_758s8;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+	if fields.t_758s9 then 
+		xx,starts=string.find(formspec,"tooltip%[t_758s9;")
+		if starts~=nil then
+			ends,xx=string.find(formspec,"%]",starts+1)
+			local group=string.lower(string.sub(formspec,starts+1,ends-2))
+			meta:set_string("search", "group:"..group)
+			if meta:get_string("saved_search")=="|" then
+				meta:set_string("saved_search", search)
+				meta:set_string("saved_page", tostring(page))
+				meta:set_string("saved_pages", tostring(pages))
+			end
+			page = 1
+			search="group:"..group
+		end
+	end
+
 	-- update the formspec
 	craft_guide.create_inventory(inv, search)
 	meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta, search, page, alternate))
@@ -196,8 +508,6 @@
 
 -- update_recipe
 craft_guide.update_recipe = function(meta, player, stack, alternate)
-    craft_guide.group_messages[player:get_player_name()] = {}
-
 	local inv = meta:get_inventory()
 	for i=0,inv:get_size("build"),1 do
 		inv:set_stack("build", i, nil)
@@ -208,6 +518,8 @@
 	if stack==nil then return end
 	inv:set_stack("output", 1, stack:get_name())
 
+	alternate = tonumber(alternate) or 1
+	craft_guide.log(player:get_player_name().." requests recipe "..alternate.." for "..stack:get_name())
 	local crafts = craft_guide.crafts[stack:get_name()]
 	
 	if crafts == nil then
@@ -217,101 +529,105 @@
 		meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
 		return
 	end
-	alternate = tonumber(alternate) or 1
 	if alternate < 1 or alternate > #crafts then
 		alternate = 1
 	end
 
 	local craft = crafts[alternate]
+	
+	-- show me the unknown items
+	craft_guide.log(dump(craft))
+	--minetest.chat_send_player(player:get_player_name(), "recipe for "..stack:get_name()..": "..dump(craft))
+	
 	local itemstack = ItemStack(craft.output)
 	inv:set_stack("output", 1, itemstack)
-    
+
 	-- cook
 	if craft.type == "cooking" then
-		inv:set_stack("cook", 1, craft_guide.get_item_name(craft.recipe, player))
+		inv:set_stack("cook", 1, craft.recipe)
 		meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
 		return
 	end
 	-- fuel
 	if craft.type == "fuel" then
-		inv:set_stack("fuel", 1, craft_guide.get_item_name(craft.recipe, player))
+		inv:set_stack("fuel", 1, craft.recipe)
 		meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
 		return
 	end
 	-- build (shaped or shapeless)
 	if craft.recipe[1] then
 		if (type(craft.recipe[1]) == "string") then
-			inv:set_stack("build", 1, craft_guide.get_item_name(craft.recipe[1], player))
+			inv:set_stack("build", 1, craft.recipe[1])
 		else
 			if craft.recipe[1][1] then
-				inv:set_stack("build", 1, craft_guide.get_item_name(craft.recipe[1][1], player))
+				inv:set_stack("build", 1, craft.recipe[1][1])
 			end
 			if craft.recipe[1][2] then
-				inv:set_stack("build", 2, craft_guide.get_item_name(craft.recipe[1][2], player))
+				inv:set_stack("build", 2, craft.recipe[1][2])
 			end
 			if craft.recipe[1][3] then
-				inv:set_stack("build", 3, craft_guide.get_item_name(craft.recipe[1][3], player))
+				inv:set_stack("build", 3, craft.recipe[1][3])
 			end
 		end
 	end
 	if craft.recipe[2] then
 		if (type(craft.recipe[2]) == "string") then
-			inv:set_stack("build", 2, craft_guide.get_item_name(craft.recipe[2], player))
+			inv:set_stack("build", 2, craft.recipe[2])
 		else
 			if craft.recipe[2][1] then
-				inv:set_stack("build", 4, craft_guide.get_item_name(craft.recipe[2][1], player))
+				inv:set_stack("build", 4, craft.recipe[2][1])
 			end
 			if craft.recipe[2][2] then
-				inv:set_stack("build", 5, craft_guide.get_item_name(craft.recipe[2][2], player))
+				inv:set_stack("build", 5, craft.recipe[2][2])
 			end
 			if craft.recipe[2][3] then
-				inv:set_stack("build", 6, craft_guide.get_item_name(craft.recipe[2][3], player))
+				inv:set_stack("build", 6, craft.recipe[2][3])
 			end
 		end
 	end
 	if craft.recipe[3] then
 		if (type(craft.recipe[3]) == "string") then
-			inv:set_stack("build", 3, craft_guide.get_item_name(craft.recipe[3], player))
+			inv:set_stack("build", 3, craft.recipe[3])
 		else
 			if craft.recipe[3][1] then
-				inv:set_stack("build", 7, craft_guide.get_item_name(craft.recipe[3][1], player))
+				inv:set_stack("build", 7, craft.recipe[3][1])
 			end
 			if craft.recipe[3][2] then
-				inv:set_stack("build", 8, craft_guide.get_item_name(craft.recipe[3][2], player))
+				inv:set_stack("build", 8, craft.recipe[3][2])
 			end
 			if craft.recipe[3][3] then
-				inv:set_stack("build", 9, craft_guide.get_item_name(craft.recipe[3][3], player))
+				inv:set_stack("build", 9, craft.recipe[3][3])
 			end
 		end
 	end
 	if craft.recipe[4] then
 		if (type(craft.recipe[4]) == "string") then
-			inv:set_stack("build", 4, craft_guide.get_item_name(craft.recipe[4], player))
+			inv:set_stack("build", 4, craft.recipe[4])
 		end
 	end
 	if craft.recipe[5] then
 		if (type(craft.recipe[5]) == "string") then
-			inv:set_stack("build", 5, craft_guide.get_item_name(craft.recipe[5], player))
+			inv:set_stack("build", 5, craft.recipe[5])
 		end
 	end
 	if craft.recipe[6] then
 		if (type(craft.recipe[6]) == "string") then
-			inv:set_stack("build", 6, craft_guide.get_item_name(craft.recipe[6], player))
+			inv:set_stack("build", 6, craft.recipe[6])
 		end
 	end
 	if craft.recipe[7] then
 		if (type(craft.recipe[7]) == "string") then
-			inv:set_stack("build", 7, craft_guide.get_item_name(craft.recipe[7], player))
+			inv:set_stack("build", 7, craft.recipe[7])
 		end
 	end
 	if craft.recipe[8] then
 		if (type(craft.recipe[8]) == "string") then
-			inv:set_stack("build", 8, craft_guide.get_item_name(craft.recipe[8], player))
+			inv:set_stack("build", 8, craft.recipe[8])
 		end
 	end
 	if craft.recipe[9] then
 		if (type(craft.recipe[9]) == "string") then
-			inv:set_stack("build", 9, craft_guide.get_item_name(craft.recipe[9], player))
+			inv:set_stack("build", 9, craft.recipe[9])
 		end
 	end
 	meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
@@ -324,22 +640,47 @@
 	for name,def in pairs(minetest.registered_items) do
 		-- local craft_recipe = minetest.get_craft_recipe(name);
 		-- if craft_recipe.items ~= nil then
-		local craft = craft_guide.crafts[name];
-		if craft ~= nil then
-			if (not def.groups.not_in_craft_guide or def.groups.not_in_craft_guide == 0)
-					--and (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
-					and def.description and def.description ~= "" then
-				if search then
-					if string.find(def.name, search) or string.find(def.description, search) then
+				local craft = craft_guide.crafts[name];
+		if (not def.groups.not_in_craft_guide or def.groups.not_in_craft_guide == 0)
+			and (craft ~= nil or (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0))
+			--and (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
+			and def.description and def.description ~= "" then
+			if search and search~="" then
+				--search used to display groups of items
+				--if you enter something in search field it displays items without crafting recipes too
+				search=string.lower(search)
+				if string.sub(search,1,6)=="group:" then
+					local groups=string.sub(search,7)
+					local hasgroup=0
+					for group in string.gmatch(groups,"([^,]+)") do
+						if minetest.get_item_group(name, group)>0 then
+							hasgroup=1
+						else
+							hasgroup=0
+							break
+						end
+					end
+					if hasgroup==1 then
 						table.insert(craft_guide_list, name)
 					end
 				else
+					search=string.lower(search)
+					local test1=0
+					local test2=0
+					local test3=0
+					test1,test2=string.find(string.lower(def.name.."           "), search)					
+					test2,test3=string.find(string.lower(def.description.."           "), search)					
+					if (test1~=nil and test1>0) or (test2~=nil and test2>0) or search=="*" then
+						table.insert(craft_guide_list, name)
+					end
+				end
+			else
+				if craft ~= nil then
 					table.insert(craft_guide_list, name)
 				end
 			end
 		end
 	end
-
 	table.sort(craft_guide_list)
 	for i=0,inv:get_size("main"),1 do
 		inv:set_stack("main", i, nil)
@@ -390,57 +731,3 @@
 end
 
 
--- get an item name, if it's a group then get an item in the group
-craft_guide.get_item_name = function(item_name, player)
-    if string.find(item_name, "group:") then
-        local group_name = item_name
-        if craft_guide.table_count(craft_guide.groups) == 0 then
-            craft_guide.load_item_groups()
-        end
-        if craft_guide.table_count(craft_guide.groups) > 0 then
-            local other_items = {}
-            if craft_guide.groups[string.sub(group_name, 7)] ~= nil then
-                item_name = craft_guide.groups[string.sub(group_name, 7)].item_name
-                other_items = craft_guide.groups[string.sub(group_name, 7)].other_items
-                if #other_items > 0 then
-                    if craft_guide.group_messages[player:get_player_name()][item_name] == nil then
-                        minetest.chat_send_player(player:get_player_name(), "Item "..item_name.." used for "..group_name..". You can also use "..table.concat(other_items, ", ")..".")
-                    end
-                    craft_guide.group_messages[player:get_player_name()][item_name] = true
-                end
-            end
-        end
-    end
-    return item_name
-end
-
-
--- load the item groups table
-craft_guide.load_item_groups = function()
-    for name,def in pairs(minetest.registered_items) do
-        if name ~= nil and def ~= nil and dump(name) ~= "\"\"" and dump(def) ~= "\"\"" then
-            local i = 1
-            for group,_ in pairs(def.groups) do
-                if craft_guide.groups[group] == nil then
-                    craft_guide.groups[group] = {}
-                    craft_guide.groups[group].other_items = {}
-                    craft_guide.groups[group].item_name = name
-                else
-                    craft_guide.groups[group].other_items[i] = name
-                    i = i+1
-                end
-            end
-        end
-    end
-end
-
-
--- count items in a table
-craft_guide.table_count = function(count_table)
-    local count = 0;
-    for k,v in pairs(count_table) do
-        count = count + 1
-    end
-    return count
-end
-

User avatar
arcturian_vagabond
Member
Posts: 15
Joined: Thu Dec 11, 2014 01:58
In-game: posipil
Location: United States
Contact:

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by arcturian_vagabond » Post

cornernote wrote:It was fixed today.
Thank you for responding. I am working with the Miner59 version for now. It seems to fully address the problem described in my post. I really like this mod. Thanks for your work.

:)

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by cornernote » Post

Miner59 wrote:Hi cornernote,
I made a diff file with a formatted version of my code. It adds a button instead of a unknown item, when a crafting recipe contains a item called "group:xy". Also changes search function a bit and adds switching from first to last page and reverse.
Please copy from below.
Hi Miner59,

That looks much cleaner. Can you do a pull request on guthub? This way you will be tracked as the contributor of this change.

I can do it for you, but it means github will not mark you as a contributor (although I will still add you to the credits section)

Let me know if you need any help with the pull request.

Miner59
Member
Posts: 46
Joined: Mon Sep 22, 2014 19:14

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Miner59 » Post

Hi,
I can do it for you, but it means github will not mark you as a contributor (although I will still add you to the credits section)
I prefer if you will add it on github yourself. It is ok for me if you are marked as contributur and I don't need to sign in on github.

The diff still has lots of copy & paste code in on_recieve_fields function, but I found no solution to make a for loop out of it.
The problem is that you need to check every button, so it goes: if fields.button1 then, if fields.button2 then, etc...
I tried to use fields.button[1], but this seems not to work. And I don't think you can turn a string in a field name.
So I think only solution is copy& paste how I did...

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by cornernote » Post

Can you post the whole file instead of the diff? That will be easier for me to apply.

Thanks.

User avatar
arcturian_vagabond
Member
Posts: 15
Joined: Thu Dec 11, 2014 01:58
In-game: posipil
Location: United States
Contact:

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by arcturian_vagabond » Post

If you find it useful then I ask not for your wealth, but simply to spare your time to consider the world we share by watching Earthlings, a multi-award winning film available to watch online for free.
I did and it will take some time for me to process. I asked by ingame partner to watch it, but she said it is too intense for her.

Miner59
Member
Posts: 46
Joined: Mon Sep 22, 2014 19:14

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Miner59 » Post

Hi,
good news, I'm finished with formatting my code and giving variables better names. xD
I tested my changes and finally don't find any problems with it.

I added a few new buttons and made changes, so you can add items to bookmarks now even if you are looking at the "you need:" list.
And it's possible to show a "you need" list for bookmarks now, because you can replace main inventory list with it if you use the small button pointing upwards.

So I'm quite happy with my modifications, maybe the only thing it would need to be a perfect guide would be if it knows recipes for machines from technic mod, like grinding for example.

Here's another screenshot:

Image

Notice that the numbers of items needed are a bit off when the recipes got to complex, like in the example of a HV Battery Box. This are rounding errors which sum up a bit.


Download: see attachment
Attachments
guide.zip
Craft guide - modified by Miner59, improved version
(17.66 KiB) Downloaded 101 times

User avatar
Don
Member
Posts: 1643
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Don » Post

Excellent work!
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!

A list of my mods can be found here

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by cornernote » Post

Miner59 wrote:Notice that the numbers of items needed are a bit off when the recipes got to complex, like in the example of a HV Battery Box. This are rounding errors which sum up a bit.
Can you give a brief explanation about how it calculated 15.11 of an item?

You should run math.ceil on the number, just so it doesn't have a decimal.

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by cornernote » Post

@Miner59

I pushed your changes:
https://github.com/cornernote/minetest- ... 0b2065bc3d

I also added you to the credits:
http://cornernote.github.io/minetest-craft_guide/

Thanks for your hard work and awesome code!

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by cornernote » Post

arcturian_vagabond wrote:
If you find it useful then I ask not for your wealth, but simply to spare your time to consider the world we share by watching Earthlings, a multi-award winning film available to watch online for free.
I did and it will take some time for me to process. I asked by ingame partner to watch it, but she said it is too intense for her.
Thanks for taking the time to watch it.

User avatar
arcturian_vagabond
Member
Posts: 15
Joined: Thu Dec 11, 2014 01:58
In-game: posipil
Location: United States
Contact:

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by arcturian_vagabond » Post

Thanks for taking the time to watch it.
I don't mind being challenged with difficult material, but I don't pretend to have all the answers.

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Linuxdirk » Post

Miner59 wrote:Notice that the numbers of items needed are a bit off when the recipes got to complex, […]. This are rounding errors which sum up a bit.
Then don’t round while calculating and only round as last step right before displaying? :)

Miner59
Member
Posts: 46
Joined: Mon Sep 22, 2014 19:14

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Miner59 » Post

Can you give a brief explanation about how it calculated 15.11 of an item?

You should run math.ceil on the number, just so it doesn't have a decimal.
You actually need 14 raw latex, so it's 1,11 off.
The explanation is, that all items of the recipe are added to inventory slots first, then they are counted.
If there are too many items they wouldn't fit inside the inventory.., so I divide them by 50 if numbers get to big.
So I get rounding errors when restoring them later. That's why I said this is a bit hacky...
And you can't just round everything to integers, because if you need a cable and you get 6 cables from 3 copper you only need 0,5 copper in the end.

But I wrote a new version which saves the items in a table, and now it should always calculate correct amount of items. Although I finally found a way to make a for loop which checks if any of the buttons is pressed and this makes huge amount of copy&paste code unnecessary.
I saw that I had added a small image in my texture folder, which isn't needed. I forgot it was there, so you can remove it again.

Here's a diff. I hope it is enough, otherwise i will post whole file again.

Code: Select all


@@ -21,6 +21,8 @@
 -- define api variables
 craft_guide.crafts = {}
 
+craft_guide.you_need_list = {}
+
 -- here you can disable "you need" feature if you don't want it
 craft_guide.you_need=true
 
@@ -126,7 +127,7 @@
 		meta:set_string("saved_pages","1")
 		meta:set_string("switch","bookmarks")
 		meta:set_string("poslist","down")
-		meta:set_string("amounts","")
+		meta:set_string("globalcount","1")
 	end	
 	if page == nil then 
 		page = craft_guide.get_current_page(meta) 
@@ -144,132 +145,14 @@
 	if crafts ~= nil then
 		alternates = #crafts
 	end
-	local build=""
-	for ii=1,9,1 do
-		local build_old=build
-		local build_stack = inv:get_stack("build",ii)
-		if build_stack~=nil then
-			local build_name=build_stack:get_name()
-			if string.sub(build_name,1,6)=="group:" then
-				local groups=string.sub(build_name,7)
-				local saved=""
-				for name,def in pairs(minetest.registered_items) do
-					local hasgroup=1
-					for group in string.gmatch(groups,"([^,]+)") do
-						if minetest.get_item_group(name, group)==0 then
-							hasgroup=0
-						end
-					end
-					if hasgroup==1 then
-                                                --prefer items from default mod
-						if string.sub(name,1,8)=="default:" then
-							build=build.."item_image_button["..tostring(2+((ii-1)%3))..","
-							..tostring(7+math.floor((ii-1)/3))..";1,1;"
-							..name..";t_758s"..tostring(ii)..";group]"
-							.."tooltip[t_758s"..tostring(ii)..";"
-							..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
-
-							saved=""
-							break
-						elseif saved=="" then
-							saved=name
-						end
-					end
-				end
-				if saved~="" then
-					build=build.."item_image_button["..tostring(2+((ii-1)%3))..","
-					..tostring(7+math.floor((ii-1)/3))..";1,1;"..saved..";t_758s"..tostring(ii)..";group]"
-					.."tooltip[t_758s"..tostring(ii)..";"
-					..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
-				end
-			end
-		end
-		if build_old==build then
-			build=build.."list[current_name;build;"..tostring(2+((ii-1)%3))..","..tostring(7+math.floor((ii-1)/3))
-				..";1,1;"..tostring(ii-1).."]"
-		end
-	end
-	local cook=""
-	local cook_stack = inv:get_stack("cook",1)
-	if cook_stack~=nil then
-		local cook_name=cook_stack:get_name()
-		if string.sub(cook_name,1,6)=="group:" then
-			local groups=string.sub(cook_name,7)
-			local saved=""
-			for name,def in pairs(minetest.registered_items) do
-				local hasgroup=1
-				for group in string.gmatch(groups,"([^,]+)") do
-					if minetest.get_item_group(name, group)==0 then
-						hasgroup=0
-					end
-				end
-				if hasgroup==1 then
-					if string.sub(name,1,8)=="default:" then
-						cook="item_image_button[6,7;1,1;"..name..";c_758s1;group]"
-						.."tooltip[c_758s1;"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
-	
-						saved=""
-						break
-					elseif saved=="" then
-						saved=name
-					end
-				end
-			end
-			if saved~="" then
-				cook="item_image_button[6,7;1,1;"..saved..";c_758s1;group]"
-				.."tooltip[c_758s1;"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
-			end
-		end
-		if cook=="" then
-			cook="list[current_name;cook;6,7;1,1;]"
-		end
-	end
-
-	local fuel=""
-	local fuel_stack = inv:get_stack("fuel",1)
-	if fuel_stack~=nil then
-		local fuel_name=fuel_stack:get_name()
-		if string.sub(fuel_name,1,6)=="group:" then
-			local groups=string.sub(fuel_name,7)
-			local saved=""
-			for name,def in pairs(minetest.registered_items) do
-				local hasgroup=1
-				for group in string.gmatch(groups,"([^,]+)") do
-					if minetest.get_item_group(name, group)==0 then
-						hasgroup=0
-					end
-				end
-				if hasgroup==1 then
-					if string.sub(name,1,8)=="default:" then
-						fuel="item_image_button[6,9;1,1;"..name..";f_758s1;group]"
-						.."tooltip[f_758s1;"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
-	
-						saved=""
-						break
-					elseif saved=="" then
-						saved=name
-					end
-				end
-			end
-			if saved~="" then
-				fuel="item_image_button[6,9;1,1;"..saved..";f_758s1;group]"
-				.."tooltip[f_758s1;"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
-			end
-		end
-		if fuel=="" then
-			fuel="list[current_name;fuel;6,9;1,1;]"
-		end
-	end
-	bk=""
+	backbutton=""
 	if meta:get_string("saved_search")~="|" then
-		bk="button[6,5.8;2.7,1;back_button;<--- Back]"
+		backbutton="button[6,5.8;2.7,1;back_button;<--- Back]"
 	end
-
 	local changeable_part=""
 	if meta:get_string("switch")=="youneed" and craft_guide.you_need then
 		changeable_part="button[9.7,6.35;0.8,0.7;switch_to_bookmarks;>>]"
 				.."tooltip[switch_to_bookmarks;Show your saved bookmarks]"
-
 		if meta:get_string("poslist")=="down" then
 			changeable_part= changeable_part.."label[8,6.5;You need:]"
 				.."button[10.42,6.35;0.5,0.7;move_up;^]"
@@ -278,67 +161,15 @@
 				.."label[11.2,6.35;bookmarks]"
 				.."label[12.6,6.05;->]"
 				.."list[current_name;add;13,6;1,1;]"
+				..craft_guide.build_button_list(meta,inv,"youneed",12,29,8,7,6)
+
 		else
 			changeable_part= changeable_part.."button[10.42,6.35;0.5,0.7;move_down;v]"
 				.."tooltip[move_down;Move the list of needed items downwards]"
+				..craft_guide.build_button_list(meta,inv,"youneed",12,29,0,1,14,0)
 		end
+		changeable_part= changeable_part..craft_guide.get_amounts(meta,inv,"youneed")
 
-		local itemlist=""
-		local x=8
-		local y=7
-		local widht=6
-		if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then
-			x=0
-			y=1
-			widht=14
-		end
-		for ii=1,18,1 do
-			local itemlist_old=itemlist
-			local itemlist_stack = inv:get_stack("youneed",ii)
-			if itemlist_stack~=nil then
-				local itemlist_name=itemlist_stack:get_name()
-				if string.sub(itemlist_name,1,6)=="group:" then
-					local groups=string.sub(itemlist_name,7)
-					local saved=""
-					for name,def in pairs(minetest.registered_items) do
-						local hasgroup=1
-						for group in string.gmatch(groups,"([^,]+)") do
-							if minetest.get_item_group(name, group)==0 then
-								hasgroup=0
-							end
-						end
-						if hasgroup==1 then
-        	                                        --prefer items from default mod
-							if string.sub(name,1,8)=="default:" then
-								itemlist=itemlist.."item_image_button["..tostring(x+((ii-1)%widht))..","
-								..tostring(y+math.floor((ii-1)/widht))..";1,1;"
-								..name..";u_758s"..tostring(ii)..";group]"
-								.."tooltip[u_758s"..tostring(ii)..";"
-								..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
-	
-								saved=""
-								break
-							elseif saved=="" then
-								saved=name
-							end
-						end
-					end
-					if saved~="" then
-						itemlist=itemlist.."item_image_button["..tostring(x+((ii-1)%widht))..","
-						..tostring(y+math.floor((ii-1)/widht))..";1,1;"..saved..";u_758s"..tostring(ii)..";group]"
-						.."tooltip[u_758s"..tostring(ii)..";"..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
-					end
-				end
-			end
-			if itemlist_old==itemlist
-				and (meta:get_string("poslist")=="down"
-				or (inv:get_stack("youneed",ii)~= nil and inv:get_stack("youneed",ii):get_name()~=""))
-				then
-				itemlist=itemlist.."list[current_name;youneed;"..tostring(x+((ii-1)%widht))..","
-					..tostring(y+math.floor((ii-1)/widht))..";1,1;"..tostring(ii-1).."]"
-			end
-		end
-		changeable_part= changeable_part..itemlist..meta:get_string("amounts")
 	end
  	if meta:get_string("switch")=="bookmarks" or (not craft_guide.you_need) or meta:get_string("poslist")=="up" then
 
@@ -365,8 +196,7 @@
 
 		.."field[6,5.4;2,1;craft_guide_search_box;;"..tostring(search).."]"
 		.."button[7.5,5.1;1.2,1;craft_guide_search_button;Search]"
-		..bk
-
+		..backbutton
 		.."label[9,5.2;page "..tostring(page).." of "..tostring(pages).."]"
 		.."button[11,5;1.5,1;craft_guide_prev;<<]"
 		.."button[12.5,5;1.5,1;craft_guide_next;>>]"
@@ -375,11 +205,11 @@
 		.."list[current_name;output;0,7;1,1;]"
 
 		.."label[2,6.5;Inventory Craft]"
-		..build
+		..craft_guide.build_button_list(meta,inv,"build",3,11,2,7,3)
 		.."label[6,6.5;Cook]"
-		..cook
+		..craft_guide.build_button_list(meta,inv,"cook",1,1,6,7,1)
 		.."label[6,8.5;Fuel]"
-		..fuel
+		..craft_guide.build_button_list(meta,inv,"fuel",2,2,6,9,1)
 		..changeable_part
 		.."button_exit[0,9.2;1,0.8;close_mm;ESC]"
 
@@ -406,8 +236,6 @@
 	inv:set_size("fuel", 1)
 	inv:set_size("bookmark", 6*3)
 	inv:set_size("youneed", 6*15)
-	inv:set_size("trylist", 6*10)
-	inv:set_size("overflow", 6*6)
 	inv:set_size("bin", 1)
 	inv:set_size("add", 1)
 	craft_guide.create_inventory(inv)
@@ -447,7 +275,6 @@
 	if fields.craft_guide_search_button then
 		if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then
 			meta:set_string("switch","bookmarks")
-			craft_guide.update_recipe(meta, player, stack, alternate)
 		end		
 		meta:set_string("saved_search", "|")
 		page = 1
@@ -461,7 +288,6 @@
 		end
 		if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then
 			meta:set_string("switch","bookmarks")
-			craft_guide.update_recipe(meta, player, stack, alternate)
 		end
 	end
 
@@ -472,7 +298,6 @@
 		end
 		if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then
 			meta:set_string("switch","bookmarks")
-			craft_guide.update_recipe(meta, player, stack, alternate)
 		end
 	end
 
@@ -487,7 +312,6 @@
 	if fields.back_button then
 		if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then
 			meta:set_string("switch","bookmarks")
-			craft_guide.update_recipe(meta, player, stack, alternate)
 		end		
 		local saved_search = meta:get_string("saved_search")
 		if saved_search~="|" then
@@ -514,14 +338,12 @@
 	if fields.move_up then	
 		if meta:get_string("switch")=="youneed" then
 			meta:set_string("poslist","up")
-			craft_guide.update_recipe(meta, player, stack, alternate)
 		end
 	end
 
 	if fields.move_down then	
 		if meta:get_string("switch")=="youneed" then
 			meta:set_string("poslist","down")
-			craft_guide.update_recipe(meta, player, stack, alternate)
 		end
 	end
 
@@ -535,458 +357,130 @@
 		alternate = 1
 	end
 
-	--group buttons
-
-	--button in cook list
+	--group buttons, finally a solution with a for loop
 	local starts=""
 	local ends=""
 	local xx=""
 	local formspec = meta:get_string("formspec")
-	if fields.c_758s1 then 
-		xx,starts=string.find(formspec,"tooltip%[c_758s1;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	--button in fuel list
-	if fields.f_758s1 then 
-		xx,starts=string.find(formspec,"tooltip%[f_758s1;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	--buttons in Inventory Craft
-	if fields.t_758s1 then 
-		xx,starts=string.find(formspec,"tooltip%[t_758s1;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.t_758s2 then 
-		xx,starts=string.find(formspec,"tooltip%[t_758s2;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.t_758s3 then 
-		xx,starts=string.find(formspec,"tooltip%[t_758s3;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.t_758s4 then 
-		xx,starts=string.find(formspec,"tooltip%[t_758s4;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.t_758s5 then 
-		xx,starts=string.find(formspec,"tooltip%[t_758s5;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.t_758s6 then 
-		xx,starts=string.find(formspec,"tooltip%[t_758s6;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.t_758s7 then 
-		xx,starts=string.find(formspec,"tooltip%[t_758s7;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.t_758s8 then 
-		xx,starts=string.find(formspec,"tooltip%[t_758s8;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
+	for button_number=1,29,1 do
+		if fields[("t_758s"..tostring(button_number))] then 
+			xx,starts=string.find(formspec,"tooltip%[t_758s"..tostring(button_number)..";")
+			if starts~=nil then
+				ends,xx=string.find(formspec,"%]",starts+1)
+				local group=string.lower(string.sub(formspec,starts+1,ends-2))
+				meta:set_string("search", "group:"..group)
+				if meta:get_string("saved_search")=="|" then
+					meta:set_string("saved_search", search)
+					meta:set_string("saved_page", tostring(page))
+					meta:set_string("saved_pages", tostring(pages))
+				end
+				page = 1
+				search="group:"..group
 			end
-			page = 1
-			search="group:"..group
+		break
 		end
 	end
-	if fields.t_758s9 then 
-		xx,starts=string.find(formspec,"tooltip%[t_758s9;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
+	if starts~="" and meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then --button pressed, need to move back to bookmarks
+		meta:set_string("switch","bookmarks")
 	end
+	-- update the formspec
+	craft_guide.create_inventory(inv, search)
+	meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta, search, page, alternate))
+end
 
-	--buttons in You Need
-	if fields.u_758s1 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s1;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s2 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s2;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s3 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s3;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s4 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s4;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s5 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s5;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s6 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s6;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s7 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s7;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s8 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s8;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s9 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s9;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s11 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s11;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s12 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s12;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s13 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s13;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
-	end
-	if fields.u_758s14 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s14;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
+
+-- returns formspec string of a inventory list with buttons for group items
+craft_guide.build_button_list = function(meta,inv,list,start_index,end_index,x,y,w,show_empty)
+	if show_empty~=0 then
+		show_empty=1
+	end
+	local string=""
+	for i=1,end_index-start_index+1,1 do
+		local string_old=string
+		local stack = inv:get_stack(list,i)
+		if stack~=nil then
+			local name=stack:get_name()
+			if string.sub(name,1,6)=="group:" then
+				local groups=string.sub(name,7)
+				local saved=""
+				for name,def in pairs(minetest.registered_items) do
+					local hasgroup=1
+					for group in string.gmatch(groups,"([^,]+)") do
+						if minetest.get_item_group(name, group)==0 then
+							hasgroup=0
+						end
+					end
+					if hasgroup==1 then
+                                                --prefer items from default mod
+						if string.sub(name,1,8)=="default:" then
+							string=string.."item_image_button["..tostring(x+((i-1)%w))..","
+							..tostring(y+math.floor((i-1)/w))..";1,1;"
+							..name..";t_758s"..tostring(i+start_index-1)..";group]"
+							.."tooltip[t_758s"..tostring(i+start_index-1)..";"
+							..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
+
+							saved=""
+							break
+						elseif saved=="" then
+							saved=name
+						end
+					end
+				end
+				if saved~="" then
+					string=string.."item_image_button["..tostring(x+((i-1)%w))..","
+					..tostring(y+math.floor((i-1)/w))..";1,1;"..saved..";t_758s"..tostring(i+start_index-1)..";group]"
+					.."tooltip[t_758s"..tostring(i+start_index-1)..";"
+					..string.upper(string.sub(groups,1,1))..string.sub(groups.." ",2).."]"
+				end
 			end
-			page = 1
-			search="group:"..group
 		end
-	end
-	if fields.u_758s15 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s15;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
+		if string_old==string and ((stack~=nil and stack:get_name()~="") or show_empty==1) then
+			string=string.."list[current_name;"..list..";"..tostring(x+((i-1)%w))..","..tostring(y+math.floor((i-1)/w))
+				..";1,1;"..tostring(i-1).."]"
 		end
 	end
-	if fields.u_758s16 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s16;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
-		end
+	return string
+end
+
+
+-- returns a formspec string with item amounts
+craft_guide.get_amounts = function(meta,inv,list)
+	local amounts=""
+	local xx=8.1
+	local yy=7.45
+	local w=6
+	local size=18
+	if meta:get_string("poslist")=="up" then
+		xx=0.1
+		yy=1.45
+		w=14
+		size=70
 	end
-	if fields.u_758s17 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s17;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
+	for jj=1,size,1 do
+		local item=string.lower(inv:get_stack(list,jj):get_name())
+		local cnt=1
+		if item==nil or item=="" then
+			break
 		end
-	end
-	if fields.u_758s18 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s18;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
+		local count=craft_guide.you_need_list[item]
+		if count~=nil then
+			cnt=math.floor(((count)/tonumber(meta:get_string("globalcount")))*1000+0.49)/1000
+			if cnt>1000 then
+				cnt=math.floor(cnt+0.49)
+			elseif cnt>100 then
+				cnt=math.floor(cnt*10+0.49)/10
+			elseif cnt>10 then
+				cnt=math.floor(cnt*100+0.49)/100
 			end
-			page = 1
-			search="group:"..group
+			amounts=amounts.."label["..tostring(xx+((jj-1)%w))..","..tostring(yy+math.floor((jj-1)/w))..";"..tostring(cnt).."]"
 		end
-	end
-	if fields.u_758s10 then 
-		xx,starts=string.find(formspec,"tooltip%[u_758s10;")
-		if starts~=nil then
-			ends,xx=string.find(formspec,"%]",starts+1)
-			local group=string.lower(string.sub(formspec,starts+1,ends-2))
-			meta:set_string("search", "group:"..group)
-			if meta:get_string("saved_search")=="|" then
-				meta:set_string("saved_search", search)
-				meta:set_string("saved_page", tostring(page))
-				meta:set_string("saved_pages", tostring(pages))
-			end
-			page = 1
-			search="group:"..group
+		jj=jj+1
+		if jj > size then
+			break
 		end
+
 	end
-	if starts~="" and meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then --button pressed, need to move back to bookmarks
-		meta:set_string("switch","bookmarks")
-	end
-	-- update the formspec
-	craft_guide.create_inventory(inv, search)
-	meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta, search, page, alternate))
+	return amounts
 end
 
 
@@ -1010,11 +504,11 @@
 
 -- update_recipe
 craft_guide.update_recipe = function(meta, player, stack, alternate)
-	meta:set_string("amounts","")
-	local count={}
 	local globalcount=1
-	local m="tq7k" --random modifier to turn unstackable items in stackable items
-
+	local list={}
+	local list2={}
+	local test={}
+	local forlist={}
 	local inv = meta:get_inventory()
 	if meta:get_string("out")~="" then
 		inv:set_stack("output", 1, ItemStack(meta:get_string("out")))
@@ -1026,12 +520,6 @@
 	for i=0,inv:get_size("youneed"),1 do
 		inv:set_stack("youneed", i, nil)
 	end
-	for i=0,inv:get_size("trylist"),1 do
-		inv:set_stack("trylist", i, nil)
-	end
-	for i=0,inv:get_size("overflow"),1 do
-		inv:set_stack("overflow", i, nil)
-	end
 
 	inv:set_stack("cook", 1, nil)
 	inv:set_stack("fuel", 1, nil)
@@ -1154,18 +642,21 @@
 		end
 	end
 	if meta:get_string("switch")=="youneed" and craft_guide.you_need then
-		count[1]=1
-		inv:set_stack("youneed", 1,ItemStack(stack:get_name()))
-		for j=1,5,1 do
+		craft_guide.you_need_list=nil
+		craft_guide.you_need_list={}
+		list[stack:get_name()] = {}
+		list[stack:get_name()] = 1
+		for j=1,10,1 do	--main iteration loop
 			local finished=1
 			local limit=inv:get_size("youneed")
-			for k=1,limit,1 do
-				local name=string.lower(inv:get_stack("youneed", k):get_name())
-				if string.len(name)>4 and string.sub(name,string.len(name)-3)==m then
-					name=string.sub(name,1,string.len(name)-4)
+			local k=0
+			for name,count in pairs(list) do
+				if k>limit then
+					break
 				end
+				k=k+1
 				local isbase=0
-				if name==nil or name=="" or string.sub(name,1,6)=="group:" then
+				if name==nil or name=="" or count==0 or string.sub(name,1,6)=="group:" then
 					isbase=1
 				elseif j>1 or k>1 then
 					for ii=1,999,1 do
@@ -1221,256 +712,257 @@
 								craftnumber=#crafts+1
 							end
 							local index=craftnumber
-							local list="trylist"
 							if j>1 then
 								if #crafts==1 and index<=#crafts then 
 									bestvalue=0
 									istest=0
-									list="youneed"
 								elseif index>#crafts or bestvalue==0 then
 									index=bestcraft
 									bestvalue=0
 									istest=0
-									list="youneed"
 								end
 							else
 								bestvalue=0
 								index=alternate
 								istest=0
-								list="youneed"
 							end
 							local craft = crafts[index]
 							if craft~=nil and craft.type~="fuel" then
-								local amount=count[k]
+								local amount=count
 								if istest==0 then
-									inv:set_stack("youneed", k,nil)
-									count[k]=0
+									list[name]=0
 									local output_count=ItemStack(craft.output):get_count()
 									if output_count~=1 and (j>1 or k>1) then
 										if amount/output_count==math.floor(amount/output_count) then
 											amount=amount/output_count
 										else
 											globalcount=globalcount*output_count
-											for ii=1,100,1 do
-												if count[ii]==nil then
-													ii=111
-												else
-													count[ii]=count[ii]*output_count
+											for _name,_amount in pairs(list) do
+												if tonumber(amount)>0 then
+													list[_name]=tonumber(_amount)*output_count
 												end
 											end
 										end
 									end
 								end
-								if(amount>50) then
-									amount=math.floor(amount/50+0.49)
-									if list=="youneed" then
-										list="overflow"
-									end
+								if istest==1 then
+									list2=list
+									list=nil
+									list={}
+									list=test
 								end
 								if craft.type == "cooking" then
-									for ci=1,amount,1 do
-										inv:add_item(list,ItemStack(craft.recipe))
+									if list[craft.recipe]==nil then
+										list[(craft.recipe)]={}
+										list[(craft.recipe)]=amount
+									else
+										local add=amount+tonumber(list[(craft.recipe)])
+										list[(craft.recipe)]=add
 									end
 								else
 									if craft.recipe[1] then
 										if (type(craft.recipe[1]) == "string") then
-											local item=ItemStack(craft.recipe[1])
-											if item:get_stack_max()<10 then
-												item=ItemStack(item:get_name()..m)
-											end
-											for ci=1,amount,1 do
-												inv:add_item(list,item)
+											if list[craft.recipe[1]]==nil then
+												list[(craft.recipe[1])]={}
+												list[(craft.recipe[1])]=amount
+											else
+												local add =amount+tonumber(list[(craft.recipe[1])])
+												list[(craft.recipe[1])]=add
 											end
 										else
 											if craft.recipe[1][1] then
-												local item=ItemStack(craft.recipe[1][1])
-												if item:get_stack_max()<10 then
-													item=ItemStack(item:get_name()..m)
-												end
-												for ci=1,amount,1 do
-													inv:add_item(list,item)
+												if list[(craft.recipe[1][1])]==nil then
+													list[(craft.recipe[1][1])]={}
+													list[(craft.recipe[1][1])]=amount
+												else
+													local add =amount+tonumber(list[(craft.recipe[1][1])])
+													list[(craft.recipe[1][1])]=add
 												end
 											end
 											if craft.recipe[1][2] then
-												local item=ItemStack(craft.recipe[1][2])
-												if item:get_stack_max()<10 then
-													item=ItemStack(item:get_name()..m)
-												end
-												for ci=1,amount,1 do
-													inv:add_item(list,item)
+												if list[(craft.recipe[1][2])]==nil then
+													list[(craft.recipe[1][2])]={}
+													list[(craft.recipe[1][2])]=amount
+												else
+													local add =amount+tonumber(list[(craft.recipe[1][2])])
+													list[(craft.recipe[1][2])]=add
 												end
 											end
 											if craft.recipe[1][3] then
-												local item=ItemStack(craft.recipe[1][3])
-												if item:get_stack_max()<10 then
-													item=ItemStack(item:get_name()..m)
-												end
-												for ci=1,amount,1 do
-													inv:add_item(list,item)
+												if list[(craft.recipe[1][3])]==nil then
+													list[(craft.recipe[1][3])]={}
+													list[(craft.recipe[1][3])]=amount
+												else
+													local add =amount+tonumber(list[(craft.recipe[1][3])])
+													list[(craft.recipe[1][3])]=add
 												end
 											end
 										end
 									end
 									if craft.recipe[2] then
 										if (type(craft.recipe[2]) == "string") then
-											local item=ItemStack(craft.recipe[2])
-											if item:get_stack_max()<10 then
-												item=ItemStack(item:get_name()..m)
-											end
-											for ci=1,amount,1 do
-												inv:add_item(list,item)
+											if list[(craft.recipe[2])]==nil then
+												list[(craft.recipe[2])]={}
+												list[(craft.recipe[2])]=amount
+											else
+												local add =amount+tonumber(list[(craft.recipe[2])])
+												list[(craft.recipe[2])]=add
 											end
 										else
 											if craft.recipe[2][1] then
-												local item=ItemStack(craft.recipe[2][1])
-												if item:get_stack_max()<10 then
-													item=ItemStack(item:get_name()..m)
-												end
-												for ci=1,amount,1 do
-													inv:add_item(list,item)
+												if list[(craft.recipe[2][1])]==nil then
+													list[(craft.recipe[2][1])]={}
+													list[(craft.recipe[2][1])]=amount
+												else
+													local add =amount+tonumber(list[(craft.recipe[2][1])])
+													list[(craft.recipe[2][1])]=add
 												end
 											end
 											if craft.recipe[2][2] then
-												local item=ItemStack(craft.recipe[2][2])
-												if item:get_stack_max()<10 then
-													item=ItemStack(item:get_name()..m)
-												end
-												for ci=1,amount,1 do
-													inv:add_item(list,item)
+												if list[(craft.recipe[2][2])]==nil then
+													list[(craft.recipe[2][2])]={}
+													list[(craft.recipe[2][2])]=amount
+												else
+													local add =amount+tonumber(list[(craft.recipe[2][2])])
+													list[(craft.recipe[2][2])]=add
 												end
 											end
 											if craft.recipe[2][3] then
-												local item=ItemStack(craft.recipe[2][3])
-												if item:get_stack_max()<10 then
-													item=ItemStack(item:get_name()..m)
-												end
-												for ci=1,amount,1 do
-													inv:add_item(list,item)
+												if list[(craft.recipe[2][3])]==nil then
+													list[(craft.recipe[2][3])]={}
+													list[(craft.recipe[2][3])]=amount
+												else
+													local add =amount+tonumber(list[(craft.recipe[2][3])])
+													list[(craft.recipe[2][3])]=add
 												end
 											end
 										end
 									end
 									if craft.recipe[3] then
 										if (type(craft.recipe[3]) == "string") then
-											local item=ItemStack(craft.recipe[3])
-											if item:get_stack_max()<10 then
-												item=ItemStack(item:get_name()..m)
-											end
-											for ci=1,amount,1 do
-												inv:add_item(list,item)
+											if list[(craft.recipe[3])]==nil then
+												list[(craft.recipe[3])]={}
+												list[(craft.recipe[3])]=amount
+											else
+												local add =amount+tonumber(list[(craft.recipe[3])])
+												list[(craft.recipe[3])]=add
 											end
 										else
 											if craft.recipe[3][1] then
-												local item=ItemStack(craft.recipe[3][1])
-												if item:get_stack_max()<10 then
-													item=ItemStack(item:get_name()..m)
-												end
-												for ci=1,amount,1 do
-													inv:add_item(list,item)
+												if list[(craft.recipe[3][1])]==nil then
+													list[(craft.recipe[3][1])]={}
+													list[(craft.recipe[3][1])]=amount
+												else
+													local add =amount+tonumber(list[(craft.recipe[3][1])])
+													list[(craft.recipe[3][1])]=add
 												end
 											end
 											if craft.recipe[3][2] then
-												local item=ItemStack(craft.recipe[3][2])
-												if item:get_stack_max()<10 then
-													item=ItemStack(item:get_name()..m)
-												end
-												for ci=1,amount,1 do
-													inv:add_item(list,item)
+												if list[(craft.recipe[3][2])]==nil then
+													list[(craft.recipe[3][2])]={}
+													list[(craft.recipe[3][2])]=amount
+												else
+													local add =amount+tonumber(list[(craft.recipe[3][2])])
+													list[(craft.recipe[3][2])]=add
 												end
 											end
 											if craft.recipe[3][3] then
-												local item=ItemStack(craft.recipe[3][3])
-												if item:get_stack_max()<10 then
-													item=ItemStack(item:get_name()..m)
-												end
-												for ci=1,amount,1 do
-													inv:add_item(list,item)
+												if list[(craft.recipe[3][3])]==nil then
+													list[(craft.recipe[3][3])]={}
+													list[(craft.recipe[3][3])]=amount
+												else
+													local add =amount+tonumber(list[(craft.recipe[3][3])])
+													list[(craft.recipe[3][3])]=add
 												end
 											end
 										end
 									end
 									if craft.recipe[4] then
 										if (type(craft.recipe[4]) == "string") then
-											local item=ItemStack(craft.recipe[4])
-											if item:get_stack_max()<10 then
-												item=ItemStack(item:get_name()..m)
-											end
-											for ci=1,amount,1 do
-												inv:add_item(list,item)
+											if list[(craft.recipe[4])]==nil then
+												list[(craft.recipe[4])]={}
+												list[(craft.recipe[4])]=amount
+											else
+												local add =amount+tonumber(list[(craft.recipe[4])])
+												list[(craft.recipe[4])]=add
 											end
 										end
 									end
 									if craft.recipe[5] then
 										if (type(craft.recipe[5]) == "string") then
-											local item=ItemStack(craft.recipe[5])
-											if item:get_stack_max()<10 then
-												item=ItemStack(item:get_name()..m)
-											end
-											for ci=1,amount,1 do
-												inv:add_item(list,item)
+											if list[(craft.recipe[5])]==nil then
+												list[(craft.recipe[5])]={}
+												list[(craft.recipe[5])]=amount
+											else
+												local add =amount+tonumber(list[(craft.recipe[5])])
+												list[(craft.recipe[5])]=add
 											end
 										end
 									end
 									if craft.recipe[6] then
 										if (type(craft.recipe[6]) == "string") then
-											local item=ItemStack(craft.recipe[6])
-											if item:get_stack_max()<10 then
-												item=ItemStack(item:get_name()..m)
-											end
-											for ci=1,amount,1 do
-												inv:add_item(list,item)
+											if list[(craft.recipe[6])]==nil then
+												list[(craft.recipe[6])]={}
+												list[(craft.recipe[6])]=amount
+											else
+												local add =amount+tonumber(list[(craft.recipe[6])])
+												list[(craft.recipe[6])]=add
 											end
 										end
 									end
 									if craft.recipe[7] then
 										if (type(craft.recipe[7]) == "string") then
-											local item=ItemStack(craft.recipe[7])
-											if item:get_stack_max()<10 then
-												item=ItemStack(item:get_name()..m)
-											end
-											for ci=1,amount,1 do
-												inv:add_item(list,item)
+											if list[(craft.recipe[7])]==nil then
+												list[(craft.recipe[7])]={}
+												list[(craft.recipe[7])]=amount
+											else
+												local add =amount+tonumber(list[(craft.recipe[7])])
+												list[(craft.recipe[7])]=add
 											end
 										end
 									end
 									if craft.recipe[8] then
 										if (type(craft.recipe[8]) == "string") then
-											local item=ItemStack(craft.recipe[8])
-											if item:get_stack_max()<10 then
-												item=ItemStack(item:get_name()..m)
-											end
-											for ci=1,amount,1 do
-												inv:add_item(list,item)
+											if list[(craft.recipe[8])]==nil then
+												list[(craft.recipe[8])]={}
+												list[(craft.recipe[8])]=amount
+											else
+												local add =amount+tonumber(list[(craft.recipe[8])])
+												list[(craft.recipe[8])]=add
 											end
 										end
 									end
 									if craft.recipe[9] then
 										if (type(craft.recipe[9]) == "string") then
-											local item=ItemStack(craft.recipe[9])
-											if item:get_stack_max()<10 then
-												item=ItemStack(item:get_name()..m)
-											end
-											for ci=1,amount,1 do
-												inv:add_item(list,item)
+											if list[(craft.recipe[9])]==nil then
+												list[(craft.recipe[9])]={}
+												list[(craft.recipe[9])]=amount
+											else
+												local add =amount+tonumber(list[(craft.recipe[9])])
+												list[(craft.recipe[9])]=add
 											end
 										end
 									end
 								end
+								if istest==1 then
+									test=list
+									list=nil
+									list={}
+									list=list2
+								end
+
 							end
 	
+
 							if istest==1 then
-								for jj=1,inv:get_size("trylist"),1 do
-									local item=inv:get_stack("trylist", jj):get_name()
-									inv:set_stack("trylist", jj, ItemStack(nil))
-									if string.len(item)>4 and string.sub(item,string.len(item)-3)==m then
-										item=string.sub(item,1,string.len(item)-4)
-									end
-									inv:set_stack("trylist", jj, ItemStack(item))
-								end
 								local value=0
-								for h=1,inv:get_size("trylist"),1 do
-									if inv:get_stack("trylist", h)~=nil then
-										local name=string.lower(inv:get_stack("trylist", h):get_name())
+								local h=0
+								for name,testcount in pairs(test) do
+									h=h+1
+									if h>888 then
+									break
+									end
+									if testcount>0 then
 										if name.def==nil or (craft_guide.crafts[name]==nil 
 											and string.sub(name,1,8)=="technic:")
 											then
@@ -1549,52 +1041,12 @@
 											end
 										end
 									end
-									inv:set_stack("trylist", h,ItemStack(nil))
 								end
 								if value<bestvalue then
 									bestcraft=index
 									bestvalue=value
 								end
 							else
-								local overflow_index=1
-								for h=1,inv:get_size("youneed"),1 do
-									if inv:get_stack("youneed", h)~=nil and inv:get_stack("youneed", h):get_name()~=nil 
-										and inv:get_stack("youneed", h):get_name()~="" then
-										if count[h]==nil or count[h]==0 then 
-											count[h]=inv:get_stack("youneed", h):get_count()
-										else
-											count[h]=count[h]+(inv:get_stack("youneed", h):get_count()-1)
-										end
-										inv:set_stack("youneed", h,ItemStack(inv:get_stack("youneed", h):get_name()))
-									else
-										if overflow_index==0 or inv:get_stack("overflow", overflow_index)==nil 
-											or inv:get_stack("overflow", overflow_index):get_name()==nil
-											or inv:get_stack("overflow", overflow_index):get_name()==""
-											then
-												overflow_index=0
-										else
-											local additem=inv:get_stack("overflow",overflow_index):get_name()
-											count[h]=inv:get_stack("overflow", overflow_index):get_count()*50
-											inv:set_stack("youneed", h, ItemStack(additem))
-											inv:set_stack("overflow", overflow_index,ItemStack(nil))
-											overflow_index=overflow_index+1
-										end
-									end
-								end
-								local size=inv:get_size("youneed")
-								for jjj=1,size,1 do
-									local item1=inv:get_stack("youneed", jjj):get_name()
-									if item1~=nil then
-										for jj=jjj+1,size,1 do
-											local item2=inv:get_stack("youneed", jj):get_name()
-											if item1==item2 and count[jjj]~=nil and count[jj]~=nil then
-												count[jjj]=count[jjj]+count[jj]
-												count[jj]=0
-												inv:set_stack("youneed", jj,ItemStack(nil))
-											end
-										end
-									end
-								end
 								craftnumber=999
 								break
 							end
@@ -1607,69 +1059,54 @@
 			end
 		end
 	end
-	local itemlist=""
-	local size=inv:get_size("youneed")
-	for jjj=1,size,1 do
-		local item1=inv:get_stack("youneed", jjj):get_name()
-		if item1~=nil then
-			for jj=jjj+1,size,1 do
-				local item2=inv:get_stack("youneed", jj):get_name()
-				if item1==item2 and count[jjj]~=nil and count[jj]~=nil then
-					count[jjj]=count[jjj]+count[jj]
-					count[jj]=0
-					inv:set_stack("youneed", jj,ItemStack(nil))
-				end
-			end
-		end
-	end
-	for jj=1,inv:get_size("youneed"),1 do
-		local item=inv:get_stack("youneed", jj):get_name()
-		inv:set_stack("youneed", jj, ItemStack(nil))
-		if string.len(item)>4 and string.sub(item,string.len(item)-3)==m then
-			item=string.sub(item,1,string.len(item)-4)
-		end
-		inv:add_item("youneed", ItemStack(item))
-	end
-	for jjj=1,55,1 do
-		if count[jjj]~=nil then 
-			if count[jjj]==0 then
-				for jj=jjj+1,55,1 do
-					if count[jj]~=nil and count[jj]~=0 then
-						count[jjj]=count[jj]
-						count[jj]=0
-						break
+	local jj=1
+	local duplicate=0
+	for name,amount in pairs(list) do
+		local count=tonumber(amount)
+		if name~=nil and count>0 and string.lower(name)~=string.upper(name) then
+			local lower=string.lower(name)
+			if craft_guide.you_need_list[lower]~=nil and craft_guide.you_need_list[lower]>0 then
+				craft_guide.you_need_list[lower]=count+craft_guide.you_need_list[lower]
+			else
+				inv:add_item("youneed", lower)
+				if inv:get_stack("youneed",jj)==nil or inv:get_stack("youneed",jj):get_name()=="" then
+					for jjj=1,jj,1 do
+						if inv:get_stack("youneed",jjj):get_count()>1 then
+							local alias=string.lower(inv:get_stack("youneed",jjj):get_name())
+							craft_guide.you_need_list[alias]=craft_guide.you_need_list[alias]+count
+							inv:set_stack("youneed",jjj,alias)
+
+						end
+					end
+							inv:set_stack("youneed",jj,ItemStack(nil))
+							duplicate=1
+							list[lower]=0
+
+				elseif string.lower(inv:get_stack("youneed",jj):get_name())~=lower then
+					local alias=string.lower(inv:get_stack("youneed",jj):get_name())
+					if list[alias]==nil then
+						craft_guide.you_need_list[alias]={}
+						craft_guide.you_need_list[alias]=count
+					else
+						list[alias]=list[alias]+count
 					end
+					list[lower]=0
+				else
+					craft_guide.you_need_list[lower]={}
+					craft_guide.you_need_list[lower]=count
 				end
-			end
-		end
-	end
-	local xx=8.1
-	local yy=7.45
-	local widht=6
-	if meta:get_string("switch")=="youneed" and meta:get_string("poslist")=="up" then
-		xx=0.1
-		yy=1.45
-		widht=14
-	end
-	for jj=1,inv:get_size("youneed"),1 do
-		if count[jj]==nil then
-			jj=111
-			break
-		else
-			if count[jj]>0 then
-				local cnt=math.floor(((count[jj])/globalcount)*1000+0.49)/1000
-				if cnt>1000 then
-					cnt=math.floor(cnt+0.49)
-				elseif cnt>100 then
-					cnt=math.floor(cnt*10+0.49)/10
-				elseif cnt>10 then
-					cnt=math.floor(cnt*100+0.49)/100
+				if duplicate==0 then
+					jj=jj+1
+				else
+					duplicate=0
+				end
+				if jj>inv:get_size("youneed") then
+					break
 				end
-				itemlist=itemlist.."label["..tostring(xx+((jj-1)%widht))..","..tostring(yy+math.floor((jj-1)/widht))..";"..tostring(cnt).."]"
 			end
 		end
 	end
-	meta:set_string("amounts",itemlist)
+	meta:set_string("globalcount",tostring(globalcount))
 	meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
 end
 
Thanks for your hard work and awesome code!
Thanks, it was really nice to hear that you like my modifications.

cornernote
Member
Posts: 844
Joined: Wed Jul 11, 2012 15:02

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by cornernote » Post

Hi Miner59,

It would be a lot easier if you sign up to github. It's really easy to create pull requests. Much easier than making zipballs and much easier than me applying diffs then committing.

Miner59
Member
Posts: 46
Joined: Mon Sep 22, 2014 19:14

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Miner59 » Post

Hi cornernote,
finally I made my pull request.
I added support for recipes for the machines from technic mod now.

Is it ok that I made one pull request with all my changes?
I can split if you want but I think this only make problems and much work.
Maybe I will test myself a bit more over christmas, and then you can make a new version of craft guide with my changes. Would be my suggestion...

Ok, I don't want to waste more time with minetest today, Happy Christmas and bye.
Attachments
guide.zip
my newest version
(18.9 KiB) Downloaded 60 times

Miner59
Member
Posts: 46
Joined: Mon Sep 22, 2014 19:14

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Miner59 » Post

Ok, cornernote merged my changes in craft guide now.

I think I write a summary what is new:

- imagebuttons for items which represent a group of items in craft recipes instead of "unknown item"

- "you need" list, shows a summary of all items needed to craft an item. Should always return exact numbers now.
You can switch between "you need" and bookmarks" with " >> " button. "^"-button moves "you need" list up, and it
replaces the main list where you can select the item from. Please test yourself ingame.

- now you can switch directly from last page to first page and reverse

- it shows now when you can use an item as fuel and shows the burntime. Items with no other craft recipe other then
the one of type "fuel" aren't shown. (because this would include things like tree trunks or saplings)

- it shows the registered craft recipes for Grinder, Compressor, Extractor, Alloy Furnace and Centrifuge from technic mod


And a tip for searching a special item:
The items in the main list are sorted alphabetically, including the prefix. So items of one mod are usually together because they have the same prefix. So you should better be able to find a special item
Also there is a search function, you can use this if you know how the item is called which you search.
If you know that the item is in a group, you can search for "group:wood", or other groups like "group:soil" or "group:cracky".
Additionally if you enter "*" in search field it shows items without craft recipe, too.

Download: on github, see first post


Edit: here are some screenshots:


Image


Image

User avatar
Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Topywo » Post

Thanks for all the work!

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Craft Guide [craft_guide] - Shows crafts for all l

by Linuxdirk » Post

This mod gets more and more awesome!

A big “thumbs up” to all contributors!

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests