let railcorridors be placed by new api

this makes it a lot faster
This commit is contained in:
cora 2022-07-02 03:44:13 +02:00
parent a92b405efd
commit 9f66c9f673
5 changed files with 43 additions and 15 deletions

@ -2168,18 +2168,18 @@ mcl_mapgen_core.register_generator("main", basic, basic_node, 1, true)
mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blockseed)
local gennotify = minetest.get_mapgen_object("gennotify")
local pr = PseudoRandom(blockseed + 42)
local has_struct = {}
local poshash = minetest.hash_node_position(minp)
for _,struct in pairs(mcl_structures.registered_structures) do
if struct.deco_id then
local pr = PseudoRandom(blockseed + 42)
local has = false
if has_struct[struct.name] == nil then has_struct[struct.name] = {} end
for _, pos in pairs(gennotify["decoration#"..struct.deco_id] or {}) do
local realpos = vector.offset(pos,0,1,0)
minetest.remove_node(realpos)
if struct.chunk_probability == nil or (not has and pr:next(1,struct.chunk_probability) == 1 ) then
mcl_structures.place_structure(realpos,struct,pr)
mcl_structures.place_structure(realpos,struct,pr,blockseed)
has=true
end
end

@ -38,7 +38,7 @@ function mcl_structures.find_highest_y(pp)
return y
end
function mcl_structures.place_structure(pos, def, pr)
function mcl_structures.place_structure(pos, def, pr, blockseed)
if not def then return end
local logging = not def.terrain_feature
local y_offset = 0
@ -83,7 +83,7 @@ function mcl_structures.place_structure(pos, def, pr)
end
end
end
if def.on_place and not def.on_place(pos,def,pr) then
if def.on_place and not def.on_place(pos,def,pr,blockseed) then
if logging then
minetest.log("warning","[mcl_structures] "..def.name.." at "..minetest.pos_to_string(pp).." not placed. Conditions not satisfied.")
end
@ -94,20 +94,20 @@ function mcl_structures.place_structure(pos, def, pr)
local r = pr:next(1,#def.filenames)
local file = def.filenames[r]
if file then
local ap = function(pos,def,pr) end
local ap = function(pos,def,pr,blockseed) end
if def.after_place then ap = def.after_place end
mcl_structures.place_schematic(pp, file, "random", nil, true, "place_center_x,place_center_z",function(p)
if def.loot then generate_loot(pos,def,pr) end
return ap(pos,def,pr)
if def.loot then generate_loot(pos,def,pr,blockseed) end
return ap(pos,def,pr,blockseed)
end,pr)
if logging then
minetest.log("action","[mcl_structures] "..def.name.." placed at "..minetest.pos_to_string(pp))
end
return true
end
elseif def.place_func and def.place_func(pos,def,pr) then
if not def.after_place or ( def.after_place and def.after_place(pos,def,pr) ) then
elseif def.place_func and def.place_func(pos,def,pr,blockseed) then
if not def.after_place or ( def.after_place and def.after_place(pos,def,pr,blockseed) ) then
if logging then
minetest.log("action","[mcl_structures] "..def.name.." placed at "..minetest.pos_to_string(pp))
end

@ -336,7 +336,7 @@ minetest.register_chatcommand("spawnstruct", {
else
for n,d in pairs(mcl_structures.registered_structures) do
if n == param then
mcl_structures.place_structure(pos,d,pr)
mcl_structures.place_structure(pos,d,pr,math.random())
return true,message
end
end

@ -1097,11 +1097,40 @@ local function create_corridor_system(main_cave_coords)
-- At this point, all corridors were generated and all nodes were set.
-- We spawn the carts now
spawn_carts()
--spawn_carts()
return true
end
mcl_structures.register_structure("mineshaft",{
place_on = {"group:sand","group:grass_block","mcl_core:water_source","group:dirt","mcl_core:dirt_with_grass","mcl_core:gravel","group:material_stone"},
fill_ratio = 0.0001,
flags = "place_center_x, place_center_z, liquid_surface, force_placement, all_floors",
sidelen = 32,
--chunk_probability = 300,
y_max = 40,
y_min = mcl_vars.mg_overworld_min,
place_func = function(pos,def,pr,blockseed)
local r = pr:next(-50,-10)
local p = vector.offset(pos,0,r,0)
if p.y < mcl_vars.mg_overworld_min + 5 then
p.y = mcl_vars.mg_overworld_min + 5
end
if p.y > -10 then return end
local p1 = vector.offset(p,-def.sidelen,-def.sidelen,-def.sidelen)
local p2 = vector.offset(p,def.sidelen,def.sidelen,def.sidelen)
minetest.emerge_area(p1, p2, function(blockpos, action, calls_remaining, param)
if calls_remaining ~= 0 then return end
--minetest.log("lol")
InitRandomizer(blockseed)
create_corridor_system(p, pr)
end)
return true
end,
})
--[[ Old Generation code this is VERY slow
-- The rail corridor algorithm starts here
mcl_mapgen_core.register_generator("railcorridors", nil, function(minp, maxp, blockseed, _pr)
-- We re-init the randomizer for every mapchunk as we start generating in the middle of each mapchunk.
@ -1112,9 +1141,7 @@ mcl_mapgen_core.register_generator("railcorridors", nil, function(minp, maxp, bl
local buffer = 5
-- Do up to 10 tries to start a corridor system
-- 5 Still seems to generate a lot of them and
-- makes this noticeably faster.
for t=1,5 do
for t=1,10 do
-- Get semi-random height in mapchunk
local y = pr:next(minp.y + buffer, maxp.y - buffer)
y = math.floor(math.max(height_min + buffer, math.min(height_max - buffer, y)))
@ -1132,3 +1159,4 @@ mcl_mapgen_core.register_generator("railcorridors", nil, function(minp, maxp, bl
end
end
end, 10)
--]]

@ -1,4 +1,4 @@
name = tsm_railcorridors
author = UgnilJoZ
description = Adds simple underground mines with railways and occasional treasure chests.
depends = mcl_init, mcl_worlds, mcl_core, mcl_mapgen_core, mcl_loot, mcl_tnt, mcl_farming, mcl_mobspawners, mcl_minecarts
depends = mcl_init, mcl_worlds, mcl_core, mcl_mapgen_core, mcl_loot, mcl_tnt, mcl_farming, mcl_mobspawners, mcl_minecarts, mcl_structures