mirror of
https://github.com/Sokomine/replacer.git
synced 2024-11-15 06:10:21 +01:00
always show craft guide; show lightlevel; show additional information if a particular node is selected; show if there are alternate drops
This commit is contained in:
parent
2aff5cd370
commit
24962d4f77
103
inspect.lua
103
inspect.lua
|
@ -21,7 +21,7 @@ minetest.register_tool( "replacer:inspect",
|
|||
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
|
||||
return replacer.inspect( itemstack, user, pointed_thing, above, false );
|
||||
return replacer.inspect( itemstack, user, pointed_thing, above, true ); --false );
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
|
@ -59,7 +59,8 @@ replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe
|
|||
if( sdata.itemstring ) then
|
||||
text = text..' ['..tostring( sdata.itemstring )..']';
|
||||
if( show_receipe ) then
|
||||
replacer.inspect_show_crafting( name, sdata.itemstring, nil );
|
||||
-- the fields part is used here to provide additional information about the entity
|
||||
replacer.inspect_show_crafting( name, sdata.itemstring, { pos=pos, luaob=luaob} );
|
||||
end
|
||||
end
|
||||
if( sdata.age ) then
|
||||
|
@ -93,15 +94,24 @@ replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe
|
|||
else
|
||||
text = 'This is a \"'..tostring( minetest.registered_nodes[ node.name ].description or ' - no description provided -')..'\" block'..text;
|
||||
end
|
||||
local protected_info = "";
|
||||
if( minetest.is_protected( pos, name )) then
|
||||
text = text..' You can\'t dig this node. It is protected.';
|
||||
protected_info = 'WARNING: You can\'t dig this node. It is protected.';
|
||||
elseif( minetest.is_protected( pos, '_THIS_NAME_DOES_NOT_EXIST_' )) then
|
||||
text = text..' You can dig this node, but others can\'t.';
|
||||
protected_info = 'INFO: You can dig this node, but others can\'t.';
|
||||
end
|
||||
minetest.chat_send_player( name, text );
|
||||
text = text..' '..protected_info;
|
||||
-- no longer spam the chat; the craft guide is more informative
|
||||
-- minetest.chat_send_player( name, text );
|
||||
|
||||
if( show_receipe ) then
|
||||
replacer.inspect_show_crafting( name, node.name, nil );
|
||||
-- get light of the node at the current time
|
||||
local light = minetest.get_node_light(pos, nil);
|
||||
if( light==0 ) then
|
||||
light = minetest.get_node_light( {x=pos.x,y=pos.y+1,z=pos.z});
|
||||
end
|
||||
-- the fields part is used here to provide additional information about the node
|
||||
replacer.inspect_show_crafting( name, node.name, {pos=pos, param2=node.param2, light=light, protected_info=protected_info} );
|
||||
end
|
||||
return nil; -- no item shall be removed from inventory
|
||||
end
|
||||
|
@ -110,6 +120,7 @@ end
|
|||
replacer.group_placeholder = {};
|
||||
replacer.group_placeholder[ 'group:wood' ] = 'default:wood';
|
||||
replacer.group_placeholder[ 'group:tree' ] = 'default:tree';
|
||||
replacer.group_placeholder[ 'group:sapling']= 'default:sapling';
|
||||
replacer.group_placeholder[ 'group:stick' ] = 'default:stick';
|
||||
replacer.group_placeholder[ 'group:stone' ] = 'default:cobble'; -- 'default:stone'; point people to the cheaper cobble
|
||||
replacer.group_placeholder[ 'group:sand' ] = 'default:sand';
|
||||
|
@ -190,11 +201,15 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
|
|||
if( not( name )) then
|
||||
return;
|
||||
end
|
||||
|
||||
local receipe_nr = 1;
|
||||
if( not( node_name )) then
|
||||
node_name = fields.node_name;
|
||||
receipe_nr = tonumber(fields.receipe_nr);
|
||||
end
|
||||
-- turn it into an item stack so that we can handle dropped stacks etc
|
||||
local stack = ItemStack( node_name );
|
||||
node_name = stack:get_name();
|
||||
|
||||
-- the player may ask for receipes of indigrents to the current receipe
|
||||
if( fields ) then
|
||||
|
@ -224,12 +239,57 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
|
|||
receipe_nr = receipe_nr + 1;
|
||||
end
|
||||
|
||||
local desc = nil;
|
||||
if( minetest.registered_nodes[ node_name ] ) then
|
||||
if( minetest.registered_nodes[ node_name ].description
|
||||
and minetest.registered_nodes[ node_name ].description~= "") then
|
||||
desc = "\""..minetest.registered_nodes[ node_name ].description.."\" block";
|
||||
elseif( minetest.registered_nodes[ node_name ].name ) then
|
||||
desc = "\""..minetest.registered_nodes[ node_name ].name.."\" block";
|
||||
else
|
||||
desc = " - no description provided - block";
|
||||
end
|
||||
elseif( minetest.registered_items[ node_name ] ) then
|
||||
if( minetest.registered_items[ node_name ].description
|
||||
and minetest.registered_items[ node_name ].description~= "") then
|
||||
desc = "\""..minetest.registered_items[ node_name ].description.."\" item";
|
||||
elseif( minetest.registered_items[ node_name ].name ) then
|
||||
desc = "\""..minetest.registered_items[ node_name ].name.."\" item";
|
||||
else
|
||||
desc = " - no description provided - item";
|
||||
end
|
||||
end
|
||||
if( not( desc ) or desc=="") then
|
||||
desc = ' - no description provided - ';
|
||||
end
|
||||
|
||||
local formspec = "size[6,6]"..
|
||||
"label[0,5.5;This is a "..minetest.formspec_escape( desc )..".]"..
|
||||
"button_exit[5.0,4.3;1,0.5;quit;Exit]"..
|
||||
"label[0,0;Name:]"..
|
||||
"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
|
||||
"label[1,0;"..tostring( node_name ).."]"..
|
||||
"item_image_button[5,2;1.0,1.0;"..tostring( node_name )..";normal;]";
|
||||
|
||||
-- provide additional information regarding the node in particular that has been inspected
|
||||
if( fields.pos ) then
|
||||
formspec = formspec.."label[0.0,0.3;Located at "..
|
||||
minetest.formspec_escape( minetest.pos_to_string( fields.pos ));
|
||||
if( fields.param2 ) then
|
||||
formspec = formspec.." with param2="..tostring( fields.param2 );
|
||||
end
|
||||
if( fields.light ) then
|
||||
formspec = formspec.." and receiving "..tostring( fields.light ).." light";
|
||||
end
|
||||
formspec = formspec..".]";
|
||||
end
|
||||
|
||||
-- show information about protection
|
||||
if( fields.protected_info and fields.protected_info ~= "" ) then
|
||||
formspec = formspec.."label[0.0,4.5;"..minetest.formspec_escape( fields.protected_info ).."]";
|
||||
end
|
||||
|
||||
if( not( res ) or receipe_nr > #res or receipe_nr < 1 ) then
|
||||
receipe_nr = 1;
|
||||
end
|
||||
|
@ -237,16 +297,33 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
|
|||
formspec = formspec.."button[3.8,5;1,0.5;prev_receipe;prev]";
|
||||
end
|
||||
if( res and receipe_nr < #res ) then
|
||||
formspec = formspec.."button[5.0,5;1,0.5;next_receipe;next]";
|
||||
formspec = formspec.."button[5.0,5.0;1,0.5;next_receipe;next]";
|
||||
end
|
||||
if( not( res ) or #res<1) then
|
||||
formspec = formspec..'label[3,1;No receipes.]';
|
||||
if( minetest.registered_nodes[ node_name ]
|
||||
and minetest.registered_nodes[ node_name ].drop ) then
|
||||
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 ).."]";
|
||||
if( drop ) then
|
||||
if( 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 ).."]";
|
||||
elseif( type( drop )=='table' and drop.items ) then
|
||||
local droplist = {};
|
||||
for _,drops in ipairs( drop.items ) do
|
||||
for _,item in ipairs( drops.items ) do
|
||||
-- avoid duplicates; but include the item itshelf
|
||||
droplist[ item ] = 1;
|
||||
end
|
||||
end
|
||||
local i = 1;
|
||||
formspec = formspec.."label[2,1.6;May drop on dig:]";
|
||||
for k,v in pairs( droplist ) do
|
||||
formspec = formspec..
|
||||
"item_image_button["..(((i-1)%3)+1)..","..math.floor(((i-1)/3)+2)..";1.0,1.0;"..replacer.image_button_link( k ).."]";
|
||||
i = i+1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
|
@ -264,6 +341,12 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
|
|||
replacer.image_button_link( receipe.items[i] ).."]";
|
||||
end
|
||||
end
|
||||
elseif( receipe.type=='cooking' and receipe.items and #receipe.items==1
|
||||
and receipe.output=="" ) then
|
||||
formspec = formspec.."item_image_button[1,1;3.4,3.4;"..replacer.image_button_link( 'default:furnace_active' ).."]".. --default_furnace_front.png]"..
|
||||
"item_image_button[2.9,2.7;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]"..
|
||||
"label[1.0,0;"..tostring(receipe.items[1]).."]"..
|
||||
"label[0,0.5;This can be used as a fuel.]";
|
||||
elseif( receipe.type=='cooking' and receipe.items and #receipe.items==1 ) then
|
||||
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] ).."]";
|
||||
|
|
Loading…
Reference in New Issue
Block a user