From e64758aa0ad5ea6839f6d66d6922687f81c89bda Mon Sep 17 00:00:00 2001 From: Sokomine Date: Thu, 2 Oct 2014 03:20:00 +0200 Subject: [PATCH] improved crafting guide; added groups --- inspect.lua | 102 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/inspect.lua b/inspect.lua index 2e9139e..bddfc7b 100644 --- a/inspect.lua +++ b/inspect.lua @@ -99,16 +99,71 @@ replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe return nil; -- no item shall be removed from inventory end +-- some common groups +replacer.group_placeholder = {}; +replacer.group_placeholder[ 'group:wood' ] = 'default:wood'; +replacer.group_placeholder[ 'group:tree' ] = 'default:tree'; +replacer.group_placeholder[ 'group:stick' ] = 'default:stick'; +replacer.group_placeholder[ 'group:stone' ] = 'default:stone'; +replacer.group_placeholder[ 'group:sand' ] = 'default:sand'; +replacer.group_placeholder[ 'group:leaves'] = 'default:leaves'; +replacer.group_placeholder[ 'group:wood_slab'] = 'stairs:slab_wood'; +replacer.group_placeholder[ 'group:wool' ] = 'wool:white'; replacer.image_button_link = function( stack_string ) + local group = ''; + if( replacer.group_placeholder[ stack_string ] ) then + stack_string = replacer.group_placeholder[ stack_string ]; + group = 'G'; + end +-- TODO: show information about other groups not handled above local stack = ItemStack( stack_string ); local new_node_name = stack_string; if( stack and stack:get_name()) then new_node_name = stack:get_name(); end - return tostring( stack_string )..';'..tostring( new_node_name ); + return tostring( stack_string )..';'..tostring( new_node_name )..';'..group; end +replacer.add_circular_saw_receipe = function( node_name, receipes ) + if( not( node_name ) or not( circular_saw ) or not( circular_saw.names) or (node_name=='moreblocks:circular_saw')) then + return; + end + local help = node_name:split( ':' ); + if( not( help ) or #help ~= 2 or help[1]=='stairs') then + return; + end + help2 = help[2]:split('_'); + if( not( help2 ) or #help2 < 2 or (help2[1]~='micro' and help2[1]~='panel' and help2[1]~='stair' and help2[1]~='slab')) then + return; + end +-- for i,v in ipairs( circular_saw.names ) do +-- modname..":"..v[1].."_"..material..v[2] + +-- TODO: write better and more correct method of getting the names of the materials +-- TODO: make sure only nodes produced by the saw are listed here +help[1]='default'; + local basic_node_name = help[1]..':'..help2[2]; + -- node found that fits into the saw + receipes[ #receipes+1 ] = { method = 'saw', type = 'saw', items = { basic_node_name }, output = node_name}; + return receipes; +end + +replacer.add_colormachine_receipe = function( node_name, receipes ) + if( not( colormachine )) then + return; + end + local res = colormachine.get_node_name_painted( node_name, "" ); + + if( not( res) or not( res.possible ) or #res.possible < 1 ) then + return; + end + -- paintable node found + receipes[ #receipes+1 ] = { method = 'colormachine', type = 'colormachine', items = { res.possible[1] }, output = node_name}; + return receipes; +end + + replacer.inspect_show_crafting = function( name, node_name, fields ) if( not( name )) then return; @@ -119,16 +174,6 @@ replacer.inspect_show_crafting = function( name, node_name, fields ) receipe_nr = tonumber(fields.receipe_nr); end - - local res = minetest.get_all_craft_recipes( node_name ); - - -- offer all alternate creafting receipes thrugh prev/next buttons - if( fields and fields.prev_receipe and res and receipe_nr > 1 ) then - receipe_nr = receipe_nr - 1; - elseif( fields and fields.next_receipe and res and receipe_nr < #res ) then - receipe_nr = receipe_nr + 1; - end - -- the player may ask for receipes of indigrents to the current receipe if( fields ) then for k,v in pairs( fields ) do @@ -142,6 +187,21 @@ replacer.inspect_show_crafting = function( name, node_name, fields ) end end + local res = minetest.get_all_craft_recipes( node_name ); + if( not( res )) then + res = {}; + end + -- add special receipes for nodes created by machines + replacer.add_circular_saw_receipe( node_name, res ); + replacer.add_colormachine_receipe( node_name, res ); + + -- offer all alternate creafting receipes thrugh prev/next buttons + if( fields and fields.prev_receipe and receipe_nr > 1 ) then + receipe_nr = receipe_nr - 1; + elseif( fields and fields.next_receipe and receipe_nr < #res ) then + receipe_nr = receipe_nr + 1; + end + local formspec = "size[6,6]".. "field[20,20;0.1,0.1;node_name;node_name;"..node_name.."]".. -- invisible field for passing on information "field[21,21;0.1,0.1;receipe_nr;receipe_nr;"..tostring( receipe_nr ).."]".. -- another invisible field @@ -163,26 +223,30 @@ replacer.inspect_show_crafting = function( name, node_name, fields ) local drop = minetest.registered_nodes[ node_name ].drop; if( drop and type( drop )=='string' and drop ~= node_name ) then formspec = formspec.."label[2,1.6;Drops on dig:]".. - "item_image_button[2,2;1.0,1.0;"..replacer.image_button_link( drop )..";]"; + "item_image_button[2,2;1.0,1.0;"..replacer.image_button_link( drop ).."]"; end end else formspec = formspec.."label[1,5;Alternate "..tostring( receipe_nr ).."/"..tostring( #res ).."]"; --- TODO: handle groups --- TODO: add support for saw --- TODO: add support for colormachine -- reverse order; default receipes (and thus the most intresting ones) are usually the oldest local receipe = res[ #res+1-receipe_nr ]; - if( receipe.type=='normal' and receipe.items and #receipe.items>0) then + if( receipe.type=='normal' and receipe.items) then for i=1,9 do if( receipe.items[i] ) then formspec = formspec.."item_image_button["..(((i-1)%3)+1)..','..(math.floor((i-1)/3)+1)..";1.0,1.0;".. - replacer.image_button_link( receipe.items[i] )..";]"; + replacer.image_button_link( receipe.items[i] ).."]"; end end elseif( receipe.type=='cooking' and receipe.items and #receipe.items==1 ) then - formspec = formspec.."image[1,1;3.4,3.4;default_furnace_front.png]".. - "item_image_button[2,2;1.0,1.0;"..replacer.image_button_link( receipe.items[1] )..";]"; + formspec = formspec.."item_image_button[1,1;3.4,3.4;"..replacer.image_button_link( 'default:furnace' ).."]".. --default_furnace_front.png]".. + "item_image_button[2.9,2.7;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]"; + elseif( receipe.type=='colormachine' and receipe.items and #receipe.items==1 ) then + formspec = formspec.."item_image_button[1,1;3.4,3.4;"..replacer.image_button_link( 'colormachine:colormachine' ).."]".. --colormachine_front.png]".. + "item_image_button[2,2;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]"; + elseif( receipe.type=='saw' and receipe.items and #receipe.items==1 ) then + --formspec = formspec.."item_image[1,1;3.4,3.4;moreblocks:circular_saw]".. + formspec = formspec.."item_image_button[1,1;3.4,3.4;"..replacer.image_button_link( 'moreblocks:circular_saw' ).."]".. + "item_image_button[2,0.6;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]"; else formspec = formspec..'label[3,1;Error: Unkown receipe.]'; end