From db4f2baafc2f814d1a1931dc987f8f66973773b7 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 2 Jul 2022 00:21:47 +0200 Subject: [PATCH 1/6] Tweak tsm_railcorridors for faster mapgen This just does 5 instead of 10 attempts to spawn a corridor in a chunk. There still appear to be plenty corridors and it makes mapgen noticeably faster. --- mods/MAPGEN/tsm_railcorridors/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 4514061679..75abe5c286 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -1102,7 +1102,9 @@ mcl_mapgen_core.register_generator("railcorridors", nil, function(minp, maxp, bl local buffer = 5 -- Do up to 10 tries to start a corridor system - for t=1,10 do + -- 5 Still seems to generate a lot of them and + -- makes this noticeably faster. + for t=1,5 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))) From a92b405efd5cadb9e2b0e9a9a15a4540c4bef042 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 2 Jul 2022 00:27:09 +0200 Subject: [PATCH 2/6] Comment out unused cart-checking hackery --- mods/MAPGEN/tsm_railcorridors/gameconfig.lua | 8 ++++++++ mods/MAPGEN/tsm_railcorridors/init.lua | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mods/MAPGEN/tsm_railcorridors/gameconfig.lua b/mods/MAPGEN/tsm_railcorridors/gameconfig.lua index de4b181199..3ada3052ff 100644 --- a/mods/MAPGEN/tsm_railcorridors/gameconfig.lua +++ b/mods/MAPGEN/tsm_railcorridors/gameconfig.lua @@ -42,6 +42,14 @@ tsm_railcorridors.carts = { "mcl_minecarts:minecart" } function tsm_railcorridors.on_construct_cart(pos, cart) -- TODO: Fill cart with treasures + + -- This is it? There's this giant hack announced in + -- the other file and I grep for the function and it's + -- a stub? :) + + -- The path here using some minetest.after hackery was + -- deactivated in init.lua - reactivate when this does + -- something the function is called RecheckCartHack. end -- Fallback function. Returns a random treasure. This function is called for chests diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 75abe5c286..8bb0d7253f 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -388,11 +388,16 @@ local function PlaceChest(pos, param2) end end + -- This function checks if a cart has ACTUALLY been spawned. -- To be calld by minetest.after. -- This is a workaround thanks to the fact that minetest.add_entity is unreliable as fuck -- See: https://github.com/minetest/minetest/issues/4759 -- FIXME: Kill this horrible hack with fire as soon you can. + +-- Why did anyone activate it in the first place? It doesn't +-- have a function seeing as there are no chest minecarts yet. +--[[ local function RecheckCartHack(params) local pos = params[1] local cart_id = params[2] @@ -408,6 +413,8 @@ local function RecheckCartHack(params) end minetest.log("info", "[tsm_railcorridors] Cart spawn FAILED: "..minetest.pos_to_string(pos)) end +--]] + -- Try to place a cobweb. -- pos: Position of cobweb @@ -937,7 +944,10 @@ local function spawn_carts() -- Note that the callback function is also called there. -- TODO: Move callback function to this position when the -- minetest.add_entity bug has been fixed. - minetest.after(3, RecheckCartHack, {cpos, cart_id}) + + -- minetest.after(3, RecheckCartHack, {cpos, cart_id}) + -- This whole recheck logic leads to a stub right now + -- it can be reenabled when chest carts are a thing. end end carts_table = {} From 9f66c9f6731cf668baeb3f238aa48b23db1283dc Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 2 Jul 2022 03:44:13 +0200 Subject: [PATCH 3/6] let railcorridors be placed by new api this makes it a lot faster --- mods/MAPGEN/mcl_mapgen_core/init.lua | 4 +-- mods/MAPGEN/mcl_structures/api.lua | 14 +++++----- mods/MAPGEN/mcl_structures/init.lua | 2 +- mods/MAPGEN/tsm_railcorridors/init.lua | 36 +++++++++++++++++++++++--- mods/MAPGEN/tsm_railcorridors/mod.conf | 2 +- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index f9745b4719..5a6082533a 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -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 diff --git a/mods/MAPGEN/mcl_structures/api.lua b/mods/MAPGEN/mcl_structures/api.lua index 4e017b502b..a4a3e59cfb 100644 --- a/mods/MAPGEN/mcl_structures/api.lua +++ b/mods/MAPGEN/mcl_structures/api.lua @@ -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 diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index a77b3dbe4b..0eafab584a 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -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 diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 8bb0d7253f..3f1e5b5a68 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -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) +--]] diff --git a/mods/MAPGEN/tsm_railcorridors/mod.conf b/mods/MAPGEN/tsm_railcorridors/mod.conf index c846cff19e..d1a9ada4a1 100644 --- a/mods/MAPGEN/tsm_railcorridors/mod.conf +++ b/mods/MAPGEN/tsm_railcorridors/mod.conf @@ -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 From 0a2e68d136b21a56e4bf4ecc0dced9decf458600 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 2 Jul 2022 04:07:38 +0200 Subject: [PATCH 4/6] spawn carts, make mineshafts a bit less frequent --- mods/MAPGEN/tsm_railcorridors/init.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 3f1e5b5a68..7095aa0b42 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -1104,8 +1104,8 @@ 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", + fill_ratio = 0.00005, + flags = "place_center_x, place_center_z, force_placement, all_floors", sidelen = 32, --chunk_probability = 300, y_max = 40, @@ -1116,7 +1116,7 @@ mcl_structures.register_structure("mineshaft",{ 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 + if p.y > -10 then return true 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) @@ -1124,6 +1124,7 @@ mcl_structures.register_structure("mineshaft",{ --minetest.log("lol") InitRandomizer(blockseed) create_corridor_system(p, pr) + spawn_carts() end) return true end, From 40d0c1affb247a67fad157303f850c6e7d96c46f Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 3 Jul 2022 02:28:30 +0200 Subject: [PATCH 5/6] slightly optimize placement --- mods/MAPGEN/tsm_railcorridors/init.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 7095aa0b42..1a786f643c 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -364,18 +364,24 @@ local function Platform(p, radius, node, node2) if not node2 then node2 = { name = tsm_railcorridors.nodes.dirt } end + local n1 = {} + local n2 = {} for zi = p.z-radius, p.z+radius do for xi = p.x-radius, p.x+radius do local np, np2 = NeedsPlatform({x=xi,y=p.y,z=zi}) if np then if np2 then - minetest.set_node({x=xi,y=p.y-1,z=zi}, node2) + --minetest.set_node({x=xi,y=p.y-1,z=zi}, node2) + table.insert(n1,{x=xi,y=p.y-1,z=zi}) else - minetest.set_node({x=xi,y=p.y-1,z=zi}, node) + --minetest.set_node({x=xi,y=p.y-1,z=zi}, node) + table.insert(n2,{x=xi,y=p.y-1,z=zi}) end end end end + minetest.bulk_set_node(n1,node) + minetest.bulk_set_node(n2,node2) end -- Chests @@ -1097,7 +1103,7 @@ 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 From 3584d89028166385b57111c6123328f4637767ad Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 3 Jul 2022 22:23:25 +0200 Subject: [PATCH 6/6] better distribution --- mods/MAPGEN/tsm_railcorridors/init.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 1a786f643c..07716dcba0 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -1109,11 +1109,10 @@ local function create_corridor_system(main_cave_coords) 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.00005, + place_on = {"group:sand","group:grass_block","mcl_core:water_source","group:dirt","mcl_core:dirt_with_grass","mcl_core:gravel","group:material_stone","mcl_core:snow"}, + fill_ratio = 0.0001, flags = "place_center_x, place_center_z, 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) @@ -1130,7 +1129,6 @@ mcl_structures.register_structure("mineshaft",{ --minetest.log("lol") InitRandomizer(blockseed) create_corridor_system(p, pr) - spawn_carts() end) return true end,