handle_schematics/player_can_provide.lua

56 lines
2.4 KiB
Lua

-- if the player builds a house manually, there are some nodes the players cannot
-- supply as the nodes are not obtainable (only their drop) - thus, in most cases,
-- the drop is what we ask for; except for these nodes where the origianl node
-- can be obtained through smelting/crafting:
handle_schematics.direct_instead_of_drop = {};
handle_schematics.direct_instead_of_drop[ "default:stone" ] = true;
handle_schematics.direct_instead_of_drop[ "default:desert_stone" ] = true;
handle_schematics.direct_instead_of_drop[ "default:clay" ] = true;
-- stores a table of node names and what the player can provide instead
-- of the very node; this is necessary as i.e. default:grass_5 cannot
-- be obtained without creative (it drops default:grass_1 or sometimes
-- wheat seeds); same applies for farming plants
handle_schematics.player_can_provide = {};
for i=1,5 do
handle_schematics.player_can_provide[ "default:grass_"..i ] = "default:grass_1";
end
-- neither can partly grown wheat or cotton plants be obtained
for i=1,8 do
handle_schematics.player_can_provide[ "farming:wheat_"..i ] = "farming:seed_wheat";
end
for i=1,8 do
handle_schematics.player_can_provide[ "farming:cotton_"..i ] = "farming:seed_cotton";
end
-- makes use of handle_schematics.player_can_provide; but also takes
-- the drop into account (for i.e. doors or other open/closed nodes)
handle_schematics.get_what_player_can_provide = function( node_wanted )
-- stone, desert_stone, clay and perhaps some other nodes can be obtained even
-- though they drop something diffrent
if( handle_schematics.direct_instead_of_drop[ node_wanted ] ) then
return node_wanted;
end
-- the player can i.e. provide seeds for a plant or the harvested grass_1
if( handle_schematics.player_can_provide[ node_wanted ]) then
return handle_schematics.player_can_provide[ node_wanted ];
end
-- some nodes like i.e. dirt with grass or stone with coal cannot be obtained;
-- in such a case we ask for the drop; this is also useful for doors etc.
if( minetest.registered_nodes[ node_wanted ]
-- provided the drop actually exists
and minetest.registered_nodes[ node_wanted ].drop
and minetest.registered_items[ minetest.registered_nodes[ node_wanted ].drop ]) then
return minetest.registered_nodes[ node_wanted ].drop;
end
-- the player ought to be able to come up with this node (or we need to define more exceptions)
return node_wanted;
end