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

User avatar
Linuxdirk
Member
 
Posts: 497
Joined: Wed Sep 17, 2014 11:21
GitHub: dsohler
In-game: Linuxdirk

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

by Linuxdirk » Sat Dec 13, 2014 16:02

deivan wrote:Don't be a cry baby.... Is a function, you give the group and the function return a item from the group... Easy and clear...

Yeah, fuck it, why be polite?
 

deivan
Member
 
Posts: 452
Joined: Fri Feb 15, 2013 10:16

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

by deivan » Sat Dec 13, 2014 16:09

Well, I am focused in the question. But sorry.
 

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

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

by cornernote » Sun Dec 14, 2014 00:54

deivan wrote:Don't be a cry baby.... Is a function, you give the group and the function return a item from the group... Easy and clear...


Instead of telling us all how easy it is, you could just do the pull request. Unless it actually isn't that easy.
 

deivan
Member
 
Posts: 452
Joined: Fri Feb 15, 2013 10:16

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

by deivan » Sun Dec 14, 2014 01:41

I don't working with LUA a some months... Seeking in my code the core portion of the routine is some like:

1) When loading the module you need add a list into a matrix to use it for the recipient. Well, if a item exist then
have a group, I catch every group and created this variable, "groups"... The item who make the group, the first one, become the example.

2) When you found a group in the recipient then you use this variable, and the example, the first item found with the group and added for example inside the list.

In my code this implementation have many comments and don't have more than 30 lines.
 

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

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

by cornernote » Sun Dec 14, 2014 01:44

Yes, the code looks clean and commented, but unfortunately I only speak english so I cannot read it. I did find the part that converts a group into an item, however I havent coded minetest or lua in almost a year, and I dont have time to test the change.

I guess you aren't going to do a pull request, but if anyone else would like to then I'd be happy to pull it.
 

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

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

by cornernote » Sun Dec 14, 2014 05:20

I pushed a fix for this, based on the same way deivan handled it in his code.

Ideally you could click "Alternate" and it will show the other items in the group, but its a bit of extra work to do it that way. At least now you get a recipe.
 

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

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

by cornernote » Sun Dec 14, 2014 06:07

Did an improvement where it sends the player a message explaining the item was used instead of the group, and lists all the items in the group they can use.
 

User avatar
Linuxdirk
Member
 
Posts: 497
Joined: Wed Sep 17, 2014 11:21
GitHub: dsohler
In-game: Linuxdirk

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

by Linuxdirk » Sun Dec 14, 2014 06:26

I can confirm this. Works as expected! No more “unknown item” for item groups! Thanks!
 

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

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

by arcturian_vagabond » Sun Dec 14, 2014 08:54

Don wrote:This is the bug that is discussed above. Glass is made by cooking group:sand. Hopefully someone will fix this soon.


I'll wait for a fix then. Thanks for the confirmation.
 

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

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

by cornernote » Sun Dec 14, 2014 09:46

arcturian_vagabond wrote:I'll wait for a fix then. Thanks for the confirmation.


It was fixed today.
 

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

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

by Miner59 » Sun Dec 14, 2014 10:40

Hi,
I reworked your mod and added some nice features.

I hope this is ok and license allows this.
If you don't like to post this in your thread maybe I can make a own thread.

What I changed:

-no unknown items shown when recipes have "group:..." inside, there is then instead a button displayed which shows all items in this group when you press it.

-added a new feature to show the complete list of items you need for a item. For example: output: default:bookshelf,
then it shows: 6 "group:wood", 27 "papyrus". This feature was the most work. I hope it works, but no guarantee.(It could lead to huge for loops which it doesn't exit when recipes are very compex. Also needs to be tested which more mods.)

-you can direct change from last page to first page and from first page to last page now

-added a button to exit the formspec

-crafting recipe for craft guide changed to use group:stick

-crafting recipe for craft guide pc changed to use just the recipe with stone slabs

Maybe more which I forgot.

Screenshot:
Image

Download: see attachment
Attachments
guide.zip
Craft guide - modified by Miner59
(15.39 KiB) Downloaded 664 times
 

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

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

by cornernote » Sun Dec 14, 2014 10:58

That is very cool. It's a much nicer way of showing the group than what I did today.

Wish you had have posted a few hours ago, would have saved me some effort! =)

The terms of the license allow you to use the code for anything you like, so long as the same license applies and my copyright is left. You can add yourself to the copyright line. As for posting in this thread, any improvement or suggestion is very welcome. I think there are too many copies of some mods, and if everyone worked together we would have one superior mod instead of 20 independent ones.

Do you want to do a pull request with your changes? I'd be happy to accept it. If you do that you will appear in the contributors on the documentation page (http://cornernote.github.io/minetest-craft_guide/). I'll also add you to the credits section.

My only concern is your code standards. You need to at least tab your indents so the code is readable. Your variable names are also very short making them hard to understand without reading a lot of code, but that is secondary to the tab indents.

I did a diff on the code, and it seems you have added a lot of lines of code, as well as modified a lot. I would be happy to lose the changes I made today and merge with your code as your solution is far superior to mine, and you also have a lot of other nice features.
 

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

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

by cornernote » Sun Dec 14, 2014 11:14

I like the "You Need" thing...

When I do "Bookshelf", it tells me I need wood and papyrus. It gets the papyrus by looping the ingredients of the book (then the paper)

When I do "Wooden Pickaxe", it tells me I need wood and sticks. I get that it cant go deeper than this because they are group items (and there are multiple ways to build them, so impossible to show the source).

But then this raises the question... Why loop back to the ingredients of the book/paper? The user can find out how to make the book by dragging it into the output.

Anyway, I guess the lookback loop works (as far as can be expected considering groups are an issue), so it would be best left in there as it saves some clicks.
 

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

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

by Miner59 » Sun Dec 14, 2014 12:15

Hi cornernote,
nice that you like my modifications.
I will try to make the code with the buttons for groups nicer. Sorry for that mess I dared to post here... XD

The code for the "You need" feature is very hacky :-( , I will try to improve this later.
I think the example with the bookshelf is too simple, but it's more informative maybe for machines from technic mod.
Do you think I can name this feature "Purchase list"? Is this a good English term for this?
 

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

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

by cornernote » Sun Dec 14, 2014 12:19

Awesome! Looking forward to seeing the pull request with your mods.

"Items Required" would be a better term. But "You Need" and "Purchase List" are both fine too.

How on earth did you code it with no tab indentation!? My brain can't even think about the code unless I indent it.
 

User avatar
Linuxdirk
Member
 
Posts: 497
Joined: Wed Sep 17, 2014 11:21
GitHub: dsohler
In-game: Linuxdirk

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

by Linuxdirk » Sun Dec 14, 2014 12:32

Miner59 wrote:The code for the "You need" feature is very hacky :-(

And it replaces the bookmarks :(

Miner59 wrote:but it's more informative maybe for machines from technic mod.

Or some of the extremely complicated Home Decor ones :)

Miner59 wrote:Do you think I can name this feature "Purchase list"?

What’s wrong with “You need …”? It’s very descriptive.

cornernote wrote:How on earth did you code it with no tab indentation!? My brain can't even think about the code unless I indent it.

Hooray for using Vim. g, g, =, G … And BAM, everything is indented properly :)
 

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

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

by cornernote » Sun Dec 14, 2014 12:38

Linuxdirk wrote:
Miner59 wrote:The code for the "You need" feature is very hacky :-(

And it replaces the bookmarks :(


No, you click the ">>" button and it toggles between bookmarks and you need.
 

User avatar
Napiophelios
Member
 
Posts: 752
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 » Sun Dec 14, 2014 12:46

This is nice for standard recipes;

Workbench mod recipes that use a larger craft grid
only shows part of recipe.
 

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

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

by cornernote » Sun Dec 14, 2014 12:47

I thought about that a lot. I think if it gets a bigger recipe it needs to have a different formspec, because there is no room left on the current one.
 

User avatar
Napiophelios
Member
 
Posts: 752
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 » Sun Dec 14, 2014 13:21

there is room if you ditch to chitchat about "Learn to craft...",
it would probably look very cramped and ugly though

would it be possible to maybe disable the usage note when an advanced recipe is given
and use the space temporarily?
 

User avatar
Linuxdirk
Member
 
Posts: 497
Joined: Wed Sep 17, 2014 11:21
GitHub: dsohler
In-game: Linuxdirk

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

by Linuxdirk » Sun Dec 14, 2014 13:42

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 » Sun Dec 14, 2014 13:46

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: 497
Joined: Wed Sep 17, 2014 11:21
GitHub: dsohler
In-game: Linuxdirk

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

by Linuxdirk » Sun Dec 14, 2014 13:53

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: 752
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 » Sun Dec 14, 2014 14:15

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: 497
Joined: Wed Sep 17, 2014 11:21
GitHub: dsohler
In-game: Linuxdirk

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

by Linuxdirk » Sun Dec 14, 2014 14:19

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: 752
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 » Sun Dec 14, 2014 14:24

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 » Sun Dec 14, 2014 16:15

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.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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

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

by arcturian_vagabond » Sun Dec 14, 2014 16:30

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 » Mon Dec 15, 2014 00:00

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 » Mon Dec 15, 2014 08:01

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...
 

PreviousNext

Return to Mod Releases

Who is online

Users browsing this forum: No registered users and 43 guests

cron