calling on_construct, growing saplings, replacing cottages-chests
parent
fa65ee89bb
commit
8321943358
|
@ -127,7 +127,6 @@ handle_schematics.analyze_mts_file = function( path )
|
|||
|
||||
-- unkown node
|
||||
local regnode = minetest.registered_nodes[ nodenames[ id ]];
|
||||
local paramtype2 = minetest.registered_nodes[ nodenames[ id ]] and minetest.registered_nodes[ nodenames[ id ]].paramtype2
|
||||
if( not( regnode ) and not( nodenames[ id ] )) then
|
||||
scm[y][x][z] = c_ignore;
|
||||
elseif( not( regnode )) then
|
||||
|
@ -135,15 +134,29 @@ handle_schematics.analyze_mts_file = function( path )
|
|||
content = c_ignore,
|
||||
name = nodenames[ id ],
|
||||
param2 = p2} };
|
||||
elseif( paramtype2 ~= 'facedir' and paramtype2 ~= 'wallmounted' ) then
|
||||
scm[y][x][z] = ids[ id ];
|
||||
else
|
||||
scm[y][x][z] = { node = {
|
||||
local paramtype2 = regnode.paramtype2;
|
||||
local needs_on_constr = regnode.on_construct;
|
||||
|
||||
if( paramtype2 ~= 'facedir' and paramtype2 ~= 'wallmounted' and not( regnode.on_construct)) then
|
||||
scm[y][x][z] = ids[ id ];
|
||||
elseif( not( regnode.on_construct )) then
|
||||
scm[y][x][z] = { node = {
|
||||
content = ids[ id ],
|
||||
--name = nodenames[ id ],
|
||||
--param2 = p2,
|
||||
--rotation = paramtype2}
|
||||
param2list = mg_villages.get_param2_rotated( paramtype2, p2 )} };
|
||||
elseif( paramtype2 ~= 'facedir' and paramtype2 ~= 'wallmounted' ) then
|
||||
scm[y][x][z] = { node = {
|
||||
content = ids[ id ],
|
||||
on_constr = true }};
|
||||
else
|
||||
scm[y][x][z] = { node = {
|
||||
content = ids[ id ],
|
||||
param2list = mg_villages.get_param2_rotated( paramtype2, p2 ),
|
||||
on_constr = true }};
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
10
mapgen.lua
10
mapgen.lua
|
@ -679,6 +679,14 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
|
|||
cid.c_ethereal_clay_orange = minetest.get_content_id( 'bakedclay:orange' );
|
||||
end
|
||||
|
||||
cid.c_chest = minetest.get_content_id( 'default:chest' );
|
||||
cid.c_chest_locked = minetest.get_content_id( 'default:chest_locked' );
|
||||
cid.c_chest_private = minetest.get_content_id( 'cottages:chest_private' );
|
||||
cid.c_chest_work = minetest.get_content_id( 'cottages:chest_work' );
|
||||
cid.c_chest_storage = minetest.get_content_id( 'cottages:chest_storage' );
|
||||
cid.c_chest_shelf = minetest.get_content_id( 'cottages:shelf' );
|
||||
cid.c_sign = minetest.get_content_id( 'default:sign_wall' );
|
||||
|
||||
t1 = time_elapsed( t1, 'defines' );
|
||||
--[[
|
||||
local centered_here = 0;
|
||||
|
@ -768,7 +776,7 @@ t1 = time_elapsed( t1, 'repair_outer_shell' );
|
|||
|
||||
for _, village in ipairs(villages) do
|
||||
|
||||
village.to_add_data = mg_villages.place_buildings( village, tmin, tmax, data, param2_data, a, village_noise);
|
||||
village.to_add_data = mg_villages.place_buildings( village, tmin, tmax, data, param2_data, a, village_noise, cid);
|
||||
t1 = time_elapsed( t1, 'place_buildings' );
|
||||
|
||||
mg_villages.place_dirt_roads( village, tmin, tmax, data, param2_data, a, village_noise, c_feldweg);
|
||||
|
|
62
villages.lua
62
villages.lua
|
@ -698,7 +698,7 @@ end
|
|||
|
||||
|
||||
|
||||
local function generate_building(pos, minp, maxp, data, param2_data, a, pr, extranodes, replacements)
|
||||
local function generate_building(pos, minp, maxp, data, param2_data, a, pr, extranodes, replacements, cid, extra_calls)
|
||||
local binfo = mg_villages.BUILDINGS[pos.btype]
|
||||
local scm
|
||||
|
||||
|
@ -759,7 +759,7 @@ local function generate_building(pos, minp, maxp, data, param2_data, a, pr, extr
|
|||
zoff = pos.bsizex - scm_x + 1;
|
||||
end
|
||||
|
||||
local has_snow = false;
|
||||
local has_snow = false; -- TODO: make some villages snow covered if moresnow is installed
|
||||
local ground_type = c_dirt_with_grass;
|
||||
for y = 0, binfo.ysize-1 do
|
||||
ax, ay, az = pos.x+x, pos.y+y+binfo.yoff, pos.z+z
|
||||
|
@ -807,6 +807,15 @@ local function generate_building(pos, minp, maxp, data, param2_data, a, pr, extr
|
|||
elseif( t.node.param2 ) then
|
||||
param2_data[a:index(ax, ay, az)] = t.node.param2;
|
||||
end
|
||||
|
||||
-- for this node, we need to call on_construct
|
||||
if( t.node.on_constr and t.node.on_constr==true ) then
|
||||
if( not( extra_calls.on_constr[ new_content ] )) then
|
||||
extra_calls.on_constr[ new_content ] = { {x=ax, y=ay, z=az}};
|
||||
else
|
||||
table.insert( extra_calls.on_constr[ new_content ], {x=ax, y=ay, z=az});
|
||||
end
|
||||
end
|
||||
-- air and gravel
|
||||
elseif t ~= c_ignore then
|
||||
|
||||
|
@ -820,6 +829,36 @@ local function generate_building(pos, minp, maxp, data, param2_data, a, pr, extr
|
|||
data[a:index(ax, ay, az)] = new_content;
|
||||
-- param2 is not set here
|
||||
end
|
||||
|
||||
-- some nodes may require additional actions after placing them
|
||||
if( not( new_content ) or new_content == cid.c_air or new_content == cid.c_ignore ) then
|
||||
-- do nothing
|
||||
|
||||
elseif( new_content == cid.c_sapling
|
||||
or new_content == cid.c_jsapling
|
||||
or new_content == cid.c_savannasapling
|
||||
or new_content == cid.c_pinesapling ) then
|
||||
-- store that a tree is to be grown there
|
||||
table.insert( extra_calls.trees, {x=ax, y=ay, z=az, typ=new_content});
|
||||
|
||||
elseif( new_content == cid.c_chest
|
||||
or new_content == cid.c_chest_locked
|
||||
or new_content == cid.c_chest_shelf ) then
|
||||
-- we're dealing with a chest that might need filling
|
||||
table.insert( extra_calls.chests, {x=ax, y=ay, z=az, typ=new_content});
|
||||
|
||||
elseif( new_content == cid.c_chest_private
|
||||
or new_content == cid.c_chest_work
|
||||
or new_content == cid.c_chest_storage ) then
|
||||
-- we're dealing with a chest that might need filling
|
||||
table.insert( extra_calls.chests, {x=ax, y=ay, z=az, typ=new_content});
|
||||
-- place a normal chest here
|
||||
data[a:index(ax, ay, az)] = cid.c_chest;
|
||||
|
||||
elseif( new_content == cid.c_sign ) then
|
||||
-- the sign may require some text to be written on it
|
||||
table.insert( extra_calls.signs, {x=ax, y=ay, z=az, typ=new_content});
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1117,7 +1156,7 @@ end
|
|||
|
||||
-- actually place the buildings (at least those which came as .we files; .mts files are handled later on)
|
||||
-- this code is also responsible for tree placement
|
||||
mg_villages.place_buildings = function(village, minp, maxp, data, param2_data, a, vnoise)
|
||||
mg_villages.place_buildings = function(village, minp, maxp, data, param2_data, a, vnoise, cid)
|
||||
local vx, vz, vs, vh = village.vx, village.vz, village.vs, village.vh
|
||||
local village_type = village.village_type;
|
||||
local seed = mg_villages.get_bseed({x=vx, z=vz})
|
||||
|
@ -1136,11 +1175,26 @@ mg_villages.place_buildings = function(village, minp, maxp, data, param2_data, a
|
|||
local replacements = mg_villages.get_replacement_table( village.village_type, p, village.to_add_data.replacements );
|
||||
|
||||
local extranodes = {}
|
||||
local extra_calls = { on_constr = {}, trees = {}, chests = {}, signs = {} };
|
||||
for _, pos in ipairs(bpos) do
|
||||
-- replacements are in table format for mapgen-based building spawning
|
||||
generate_building(pos, minp, maxp, data, param2_data, a, pr_village, extranodes, replacements )
|
||||
generate_building(pos, minp, maxp, data, param2_data, a, pr_village, extranodes, replacements, cid, extra_calls )
|
||||
end
|
||||
|
||||
-- call on_oncstruct for all nodes that need it
|
||||
for k, v in pairs( extra_calls.on_constr ) do
|
||||
local node_name = minetest.get_name_from_content_id( k );
|
||||
for _, pos in ipairs(v) do
|
||||
minetest.registered_nodes[ node_name ].on_construct( pos );
|
||||
end
|
||||
end
|
||||
|
||||
-- grow trees into saplings
|
||||
for _,v in ipairs( extra_calls.trees ) do
|
||||
mg_villages.grow_a_tree( v, v.typ, minp, maxp, data, a, cid, pr );
|
||||
end
|
||||
|
||||
|
||||
-- replacements are in list format for minetest.place_schematic(..) type spawning
|
||||
return { extranodes = extranodes, bpos = bpos, replacements = replacements.list, dirt_roads = village.to_add_data.dirt_roads,
|
||||
plantlist = village.to_add_data.plantlist };
|
||||
|
|
28
we.lua
28
we.lua
|
@ -88,16 +88,38 @@ mg_villages.import_scm = function(scm)
|
|||
ent.meta = {fields={}, inventory={}}
|
||||
end
|
||||
local paramtype2 = minetest.registered_nodes[ent.name] and minetest.registered_nodes[ent.name].paramtype2
|
||||
local on_constr = minetest.registered_nodes[ent.name] and minetest.registered_nodes[ent.name].on_construct
|
||||
if( on_constr ) then
|
||||
on_constr = true;
|
||||
end
|
||||
-- unkown nodes are discarded here!
|
||||
if ent.name == "mg:ignore" or not paramtype2 then
|
||||
scm[ent.y][ent.x][ent.z] = c_ignore
|
||||
if( on_constr ) then
|
||||
scm[ent.y][ent.x][ent.z] = {
|
||||
node = {
|
||||
content = minetest.get_content_id(ent.name),
|
||||
name = ent.name,
|
||||
on_constr = true
|
||||
}}
|
||||
else
|
||||
scm[ent.y][ent.x][ent.z] = c_ignore
|
||||
end
|
||||
elseif numk(ent.meta.fields) == 0 and numk(ent.meta.inventory) == 0 then
|
||||
if paramtype2 ~= "facedir" and paramtype2 ~= "wallmounted" then
|
||||
scm[ent.y][ent.x][ent.z] = minetest.get_content_id(ent.name)
|
||||
if( not( on_constr )) then
|
||||
scm[ent.y][ent.x][ent.z] = minetest.get_content_id(ent.name)
|
||||
else
|
||||
scm[ent.y][ent.x][ent.z] = {
|
||||
node = {
|
||||
content = minetest.get_content_id(ent.name),
|
||||
on_constr = true
|
||||
}}
|
||||
end
|
||||
else
|
||||
scm[ent.y][ent.x][ent.z] = {
|
||||
node = {
|
||||
content = minetest.get_content_id(ent.name),
|
||||
on_constr = on_constr,
|
||||
name = ent.name,param2 = ent.param2, param2list = mg_villages.get_param2_rotated( paramtype2, ent.param2 )},
|
||||
rotation = paramtype2}
|
||||
end
|
||||
|
@ -106,12 +128,14 @@ mg_villages.import_scm = function(scm)
|
|||
scm[ent.y][ent.x][ent.z] = {extranode = true,
|
||||
node = {
|
||||
content = minetest.get_content_id(ent.name),
|
||||
on_constr = on_constr,
|
||||
name = ent.name, param2 = ent.param2},
|
||||
meta = ent.meta}
|
||||
else
|
||||
scm[ent.y][ent.x][ent.z] = {extranode = true,
|
||||
node = {
|
||||
content = minetest.get_content_id(ent.name),
|
||||
on_constr = on_constr,
|
||||
name = ent.name, param2 = ent.param2, param2list = mg_villages.get_param2_rotated( paramtype2, ent.param2 )},
|
||||
meta = ent.meta,
|
||||
rotation = paramtype2}
|
||||
|
|
Loading…
Reference in New Issue