Merge pull request 'Fix railcorridors aka make mapgen fast again' (#2384) from railcorridors into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/2384 Reviewed-by: MysticTempest <mystictempest@noreply.git.minetest.land>wood_api
commit
86233c774d
|
@ -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)
|
mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blockseed)
|
||||||
local gennotify = minetest.get_mapgen_object("gennotify")
|
local gennotify = minetest.get_mapgen_object("gennotify")
|
||||||
local pr = PseudoRandom(blockseed + 42)
|
|
||||||
local has_struct = {}
|
local has_struct = {}
|
||||||
local poshash = minetest.hash_node_position(minp)
|
local poshash = minetest.hash_node_position(minp)
|
||||||
for _,struct in pairs(mcl_structures.registered_structures) do
|
for _,struct in pairs(mcl_structures.registered_structures) do
|
||||||
if struct.deco_id then
|
if struct.deco_id then
|
||||||
|
local pr = PseudoRandom(blockseed + 42)
|
||||||
local has = false
|
local has = false
|
||||||
if has_struct[struct.name] == nil then has_struct[struct.name] = {} end
|
if has_struct[struct.name] == nil then has_struct[struct.name] = {} end
|
||||||
for _, pos in pairs(gennotify["decoration#"..struct.deco_id] or {}) do
|
for _, pos in pairs(gennotify["decoration#"..struct.deco_id] or {}) do
|
||||||
local realpos = vector.offset(pos,0,1,0)
|
local realpos = vector.offset(pos,0,1,0)
|
||||||
minetest.remove_node(realpos)
|
minetest.remove_node(realpos)
|
||||||
if struct.chunk_probability == nil or (not has and pr:next(1,struct.chunk_probability) == 1 ) then
|
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
|
has=true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ function mcl_structures.find_highest_y(pp)
|
||||||
return y
|
return y
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_structures.place_structure(pos, def, pr)
|
function mcl_structures.place_structure(pos, def, pr, blockseed)
|
||||||
if not def then return end
|
if not def then return end
|
||||||
local logging = not def.terrain_feature
|
local logging = not def.terrain_feature
|
||||||
local y_offset = 0
|
local y_offset = 0
|
||||||
|
@ -83,7 +83,7 @@ function mcl_structures.place_structure(pos, def, pr)
|
||||||
end
|
end
|
||||||
end
|
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
|
if logging then
|
||||||
minetest.log("warning","[mcl_structures] "..def.name.." at "..minetest.pos_to_string(pp).." not placed. Conditions not satisfied.")
|
minetest.log("warning","[mcl_structures] "..def.name.." at "..minetest.pos_to_string(pp).." not placed. Conditions not satisfied.")
|
||||||
end
|
end
|
||||||
|
@ -94,20 +94,20 @@ function mcl_structures.place_structure(pos, def, pr)
|
||||||
local r = pr:next(1,#def.filenames)
|
local r = pr:next(1,#def.filenames)
|
||||||
local file = def.filenames[r]
|
local file = def.filenames[r]
|
||||||
if file then
|
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
|
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)
|
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
|
if def.loot then generate_loot(pos,def,pr,blockseed) end
|
||||||
return ap(pos,def,pr)
|
return ap(pos,def,pr,blockseed)
|
||||||
end,pr)
|
end,pr)
|
||||||
if logging then
|
if logging then
|
||||||
minetest.log("action","[mcl_structures] "..def.name.." placed at "..minetest.pos_to_string(pp))
|
minetest.log("action","[mcl_structures] "..def.name.." placed at "..minetest.pos_to_string(pp))
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif def.place_func and def.place_func(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) ) then
|
if not def.after_place or ( def.after_place and def.after_place(pos,def,pr,blockseed) ) then
|
||||||
if logging then
|
if logging then
|
||||||
minetest.log("action","[mcl_structures] "..def.name.." placed at "..minetest.pos_to_string(pp))
|
minetest.log("action","[mcl_structures] "..def.name.." placed at "..minetest.pos_to_string(pp))
|
||||||
end
|
end
|
||||||
|
|
|
@ -336,7 +336,7 @@ minetest.register_chatcommand("spawnstruct", {
|
||||||
else
|
else
|
||||||
for n,d in pairs(mcl_structures.registered_structures) do
|
for n,d in pairs(mcl_structures.registered_structures) do
|
||||||
if n == param then
|
if n == param then
|
||||||
mcl_structures.place_structure(pos,d,pr)
|
mcl_structures.place_structure(pos,d,pr,math.random())
|
||||||
return true,message
|
return true,message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,6 +42,14 @@ tsm_railcorridors.carts = { "mcl_minecarts:minecart" }
|
||||||
|
|
||||||
function tsm_railcorridors.on_construct_cart(pos, cart)
|
function tsm_railcorridors.on_construct_cart(pos, cart)
|
||||||
-- TODO: Fill cart with treasures
|
-- 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
|
end
|
||||||
|
|
||||||
-- Fallback function. Returns a random treasure. This function is called for chests
|
-- Fallback function. Returns a random treasure. This function is called for chests
|
||||||
|
|
|
@ -364,18 +364,24 @@ local function Platform(p, radius, node, node2)
|
||||||
if not node2 then
|
if not node2 then
|
||||||
node2 = { name = tsm_railcorridors.nodes.dirt }
|
node2 = { name = tsm_railcorridors.nodes.dirt }
|
||||||
end
|
end
|
||||||
|
local n1 = {}
|
||||||
|
local n2 = {}
|
||||||
for zi = p.z-radius, p.z+radius do
|
for zi = p.z-radius, p.z+radius do
|
||||||
for xi = p.x-radius, p.x+radius do
|
for xi = p.x-radius, p.x+radius do
|
||||||
local np, np2 = NeedsPlatform({x=xi,y=p.y,z=zi})
|
local np, np2 = NeedsPlatform({x=xi,y=p.y,z=zi})
|
||||||
if np then
|
if np then
|
||||||
if np2 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
|
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
minetest.bulk_set_node(n1,node)
|
||||||
|
minetest.bulk_set_node(n2,node2)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Chests
|
-- Chests
|
||||||
|
@ -388,11 +394,16 @@ local function PlaceChest(pos, param2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- This function checks if a cart has ACTUALLY been spawned.
|
-- This function checks if a cart has ACTUALLY been spawned.
|
||||||
-- To be calld by minetest.after.
|
-- To be calld by minetest.after.
|
||||||
-- This is a workaround thanks to the fact that minetest.add_entity is unreliable as fuck
|
-- This is a workaround thanks to the fact that minetest.add_entity is unreliable as fuck
|
||||||
-- See: https://github.com/minetest/minetest/issues/4759
|
-- See: https://github.com/minetest/minetest/issues/4759
|
||||||
-- FIXME: Kill this horrible hack with fire as soon you can.
|
-- 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 function RecheckCartHack(params)
|
||||||
local pos = params[1]
|
local pos = params[1]
|
||||||
local cart_id = params[2]
|
local cart_id = params[2]
|
||||||
|
@ -408,6 +419,8 @@ local function RecheckCartHack(params)
|
||||||
end
|
end
|
||||||
minetest.log("info", "[tsm_railcorridors] Cart spawn FAILED: "..minetest.pos_to_string(pos))
|
minetest.log("info", "[tsm_railcorridors] Cart spawn FAILED: "..minetest.pos_to_string(pos))
|
||||||
end
|
end
|
||||||
|
--]]
|
||||||
|
|
||||||
|
|
||||||
-- Try to place a cobweb.
|
-- Try to place a cobweb.
|
||||||
-- pos: Position of cobweb
|
-- pos: Position of cobweb
|
||||||
|
@ -937,7 +950,10 @@ local function spawn_carts()
|
||||||
-- Note that the callback function is also called there.
|
-- Note that the callback function is also called there.
|
||||||
-- TODO: Move callback function to this position when the
|
-- TODO: Move callback function to this position when the
|
||||||
-- minetest.add_entity bug has been fixed.
|
-- 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
|
||||||
end
|
end
|
||||||
carts_table = {}
|
carts_table = {}
|
||||||
|
@ -1092,6 +1108,34 @@ local function create_corridor_system(main_cave_coords)
|
||||||
return true
|
return true
|
||||||
end
|
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","mcl_core:snow"},
|
||||||
|
fill_ratio = 0.0001,
|
||||||
|
flags = "place_center_x, place_center_z, force_placement, all_floors",
|
||||||
|
sidelen = 32,
|
||||||
|
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 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)
|
||||||
|
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
|
-- The rail corridor algorithm starts here
|
||||||
mcl_mapgen_core.register_generator("railcorridors", nil, function(minp, maxp, blockseed, _pr)
|
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.
|
-- We re-init the randomizer for every mapchunk as we start generating in the middle of each mapchunk.
|
||||||
|
@ -1120,3 +1164,4 @@ mcl_mapgen_core.register_generator("railcorridors", nil, function(minp, maxp, bl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end, 10)
|
end, 10)
|
||||||
|
--]]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name = tsm_railcorridors
|
name = tsm_railcorridors
|
||||||
author = UgnilJoZ
|
author = UgnilJoZ
|
||||||
description = Adds simple underground mines with railways and occasional treasure chests.
|
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
|
||||||
|
|
Loading…
Reference in New Issue