better handling of opened and closed objects and some dirt types

This commit is contained in:
Sokomine 2017-04-27 20:14:17 +02:00
parent 489cd14b95
commit d4ff899103
2 changed files with 63 additions and 13 deletions

View File

@ -2,6 +2,31 @@
-- "dirt" stands as a placeholder for "some ground node; can be stone or dirt or something similar";
handle_schematics.also_acceptable = {};
handle_schematics.add_also_acceptable = function( name1, name2 )
-- only add entry if both nodes exist
if( not( name1 ) or not( name2 ) or name1==name2
or not( minetest.registered_nodes[ name1 ] )
or not( minetest.registered_nodes[ name2 ] )
or handle_schematics.direct_instead_of_drop[ name1 ]
or handle_schematics.direct_instead_of_drop[ name2 ]) then
return;
end
-- the table works by content_id for faster lookup at the time of placement
local id1 = minetest.get_content_id( name1 );
local id2 = minetest.get_content_id( name2 );
if( not( id1 ) or not( id2 ) or ( id1==id2 )) then
return;
end
-- make sure the entry exists so that we can add to the table
if( not( handle_schematics.also_acceptable[ id1 ])) then
handle_schematics.also_acceptable[ id1 ] = { is_ok = {}};
end
handle_schematics.also_acceptable[ id1 ].is_ok[ id2 ] = 1;
--print ("[handle_schematics] Accepting "..tostring( name2 ).." instead of "..tostring( name1 ));
end
-- This function fills the table handle_schematics.also_acceptable with data.
-- The general assumption is that dirt nodes in schematics are most of the time just placeholders
-- and could as well be other nodes - like i.e. stone, stone with ore, other variants of dirt
@ -10,8 +35,6 @@ handle_schematics.also_acceptable = {};
-- have to be dirt_with_grass. Most of the time it will look much better if what was placed
-- there by mapgen is taken instead (i.e. the local dirt type, sand, gravel, ...)
handle_schematics.enable_use_dirt_as_placeholder = function()
local dirt_id = minetest.get_content_id("default:dirt");
handle_schematics.also_acceptable[ dirt_id ] = { is_ok = {}};
local fill_nodes = {"default:stone","default:stone_with_coal","default:stone_with_iron",
"default:stone_with_copper","default:stone_with_mese","default:stone_with_diamond",
"default:stone_with_gold","default:stone_with_tin",
@ -22,13 +45,10 @@ handle_schematics.enable_use_dirt_as_placeholder = function()
"default:dirt_with_dry_grass","default:dirt_with_grass","default:dirt_with_rainforest_litter",
"default:dirt_with_snow", "default:snowblock","default:ice"};
for i,v in ipairs( fill_nodes ) do
local id = minetest.get_content_id( v );
handle_schematics.also_acceptable[ dirt_id ].is_ok[ id ] = 1;
handle_schematics.add_also_acceptable( "default:dirt", v )
end
-- it does not always have to be dirt_with_grass
dirt_id = minetest.get_content_id( "default:dirt_with_grass" );
handle_schematics.also_acceptable[ dirt_id ] = { is_ok = {}};
fill_nodes = {
-- falling nodes...but may still be ok in this context
"default:gravel","default:sand","default:desert_sand","default:silver_sand",
@ -36,8 +56,35 @@ handle_schematics.enable_use_dirt_as_placeholder = function()
"default:dirt_with_dry_grass","default:dirt_with_grass","default:dirt_with_rainforest_litter",
"default:dirt_with_snow","default:dirt","default:snowblock","default:ice"};
for i,v in ipairs( fill_nodes ) do
local id = minetest.get_content_id( v );
handle_schematics.also_acceptable[ dirt_id ].is_ok[ id ] = 1;
handle_schematics.add_also_acceptable( "default:dirt_with_grass", v )
end
end
-- doors and gates tend to be diffrent nodes in their open state
-- TODO: this also covers soil
handle_schematics.enable_doors_open_closed = function()
for k,v in pairs(minetest.registered_nodes) do
if( v.drop
and v.drop
and type( v.drop )=='string'
and v.drop ~= k ) then
if( minetest.registered_nodes[ v.drop ]
-- stone and desert_stone need to be handled diffrently;
-- some dirt and grass types etc. are also handled
and not(handle_schematics.direct_instead_of_drop[ k ])) then
handle_schematics.add_also_acceptable( k, v.drop );
handle_schematics.add_also_acceptable( v.drop, k );
elseif( minetest.registered_items[ v.drop ]
and ( k==v.drop.."_a" or k==v.drop.."_b" or k==v.drop.."_open" or k==v.drop.."_closed")) then
local namen = { v.drop.."_a", v.drop.."_b", v.drop.."_open", v.drop.."_closed"};
for i,name1 in ipairs( namen ) do
for j,name2 in ipairs( namen ) do
handle_schematics.add_also_acceptable( name1, name2 );
end
end
end
end
end
end

View File

@ -41,6 +41,11 @@ dofile(handle_schematics.modpath.."/replacements_roof.lua")
dofile(handle_schematics.modpath.."/replacements_get_table.lua")
-- apart from dirt_with_grass, some other nodes may not be obtainable without
-- creative because their drop is diffrent from their node name (i.e grass,
-- farming, doors, ..)
dofile(handle_schematics.modpath.."/player_can_provide.lua")
-- assume dirt to be a general placeholder for "something you can
-- walk on"; might be stone, other dirt types etc.; this also
-- accepts other dirt and sand types for dirt_with_grass
@ -48,11 +53,9 @@ dofile(handle_schematics.modpath.."/dirt_is_not_always_dirt.lua")
-- actually enable it (if you do not want this function just set
-- handle_schematics.also_acceptable = {} somewhere in your code
handle_schematics.enable_use_dirt_as_placeholder();
-- apart from dirt_with_grass, some other nodes may not be obtainable without
-- creative because their drop is diffrent from their node name (i.e grass,
-- farming, doors, ..)
dofile(handle_schematics.modpath.."/player_can_provide.lua")
-- doors have the tendency to come in either "open" or "closed" state - neither
-- of which ought to make a difference
handle_schematics.enable_doors_open_closed();
-- uses build_chest.* namespace
-- a chest for spawning buildings manually