1
0
Fork 0

Fix mcl_worlds to work with mapgen api

new_mapgen_api
kay27 2022-01-20 05:11:21 +04:00
parent f592437e8a
commit 682d2b3229
4 changed files with 39 additions and 103 deletions

View File

@ -5,25 +5,25 @@ local get_connected_players = minetest.get_connected_players
-- For a given position, returns a 2-tuple: -- For a given position, returns a 2-tuple:
-- 1st return value: true if pos is in void -- 1st return value: true if pos is in void
-- 2nd return value: true if it is in the deadly part of the void -- 2nd return value: true if it is in the deadly part of the void
local min1, min2, min3 = mcl_mapgen.overworld.min, mcl_mapgen.end_.min, mcl_mapgen.nether.min
local max1, max2, max3 = mcl_mapgen.overworld.max, mcl_mapgen.end_.max, mcl_mapgen.nether.max+128
function mcl_worlds.is_in_void(pos) function mcl_worlds.is_in_void(pos)
local void = local y = pos.y
not ((pos.y < mcl_vars.mg_overworld_max and pos.y > mcl_vars.mg_overworld_min) or local void = not ((y < max1 and y > min1) or (y < max2 and y > min2) or (y < max3 and y > min3))
(pos.y < mcl_vars.mg_nether_max+128 and pos.y > mcl_vars.mg_nether_min) or
(pos.y < mcl_vars.mg_end_max and pos.y > mcl_vars.mg_end_min))
local void_deadly = false local void_deadly = false
local deadly_tolerance = 64 -- the player must be this many nodes “deep” into the void to be damaged local deadly_tolerance = 64 -- the player must be this many nodes “deep” into the void to be damaged
if void then if void then
-- Overworld → Void → End → Void → Nether → Void -- Overworld → Void → End → Void → Nether → Void
if pos.y < mcl_vars.mg_overworld_min and pos.y > mcl_vars.mg_end_max then if y < min1 and y > max2 then
void_deadly = pos.y < mcl_vars.mg_overworld_min - deadly_tolerance void_deadly = y < min1 - deadly_tolerance
elseif pos.y < mcl_vars.mg_end_min and pos.y > mcl_vars.mg_nether_max+128 then elseif y < min2 and y > max3 then
-- The void between End and Nether. Like usual, but here, the void -- The void between End and Nether. Like usual, but here, the void
-- *above* the Nether also has a small tolerance area, so player -- *above* the Nether also has a small tolerance area, so player
-- can fly above the Nether without getting hurt instantly. -- can fly above the Nether without getting hurt instantly.
void_deadly = (pos.y < mcl_vars.mg_end_min - deadly_tolerance) and (pos.y > mcl_vars.mg_nether_max+128 + deadly_tolerance) void_deadly = (y < min2 - deadly_tolerance) and (y > max3 + deadly_tolerance)
elseif pos.y < mcl_vars.mg_nether_min then elseif y < min3 then
void_deadly = pos.y < mcl_vars.mg_nether_min - deadly_tolerance void_deadly = y < min3 - deadly_tolerance
end end
end end
return void, void_deadly return void, void_deadly
@ -35,12 +35,12 @@ end
-- If the Y coordinate is not located in any dimension, it will return: -- If the Y coordinate is not located in any dimension, it will return:
-- nil, "void" -- nil, "void"
function mcl_worlds.y_to_layer(y) function mcl_worlds.y_to_layer(y)
if y >= mcl_vars.mg_overworld_min then if y >= min1 then
return y - mcl_vars.mg_overworld_min, "overworld" return y - min1, "overworld"
elseif y >= mcl_vars.mg_nether_min and y <= mcl_vars.mg_nether_max+128 then elseif y >= min3 and y <= max3 then
return y - mcl_vars.mg_nether_min, "nether" return y - min3, "nether"
elseif y >= mcl_vars.mg_end_min and y <= mcl_vars.mg_end_max then elseif y >= min2 and y <= max2 then
return y - mcl_vars.mg_end_min, "end" return y - min2, "end"
else else
return nil, "void" return nil, "void"
end end
@ -61,25 +61,25 @@ local pos_to_dimension = mcl_worlds.pos_to_dimension
-- MineClone 2. -- MineClone 2.
-- mc_dimension is one of "overworld", "nether", "end" (default: "overworld"). -- mc_dimension is one of "overworld", "nether", "end" (default: "overworld").
function mcl_worlds.layer_to_y(layer, mc_dimension) function mcl_worlds.layer_to_y(layer, mc_dimension)
if mc_dimension == "overworld" or mc_dimension == nil then if not mc_dimension or mc_dimension == "overworld" then
return layer + mcl_vars.mg_overworld_min return layer + min1
elseif mc_dimension == "nether" then elseif mc_dimension == "nether" then
return layer + mcl_vars.mg_nether_min return layer + min3
elseif mc_dimension == "end" then elseif mc_dimension == "end" then
return layer + mcl_vars.mg_end_min return layer + min2
end end
end end
-- Takes a position and returns true if this position can have weather -- Takes a position and returns true if this position can have weather
function mcl_worlds.has_weather(pos) function mcl_worlds.has_weather(pos)
-- Weather in the Overworld and the high part of the void below -- Weather in the Overworld and the high part of the void below
return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64 return pos.y <= max1 and pos.y >= min1 - 64
end end
-- Takes a position and returns true if this position can have Nether dust -- Takes a position and returns true if this position can have Nether dust
function mcl_worlds.has_dust(pos) function mcl_worlds.has_dust(pos)
-- Weather in the Overworld and the high part of the void below -- Weather in the Overworld and the high part of the void below
return pos.y <= mcl_vars.mg_nether_max + 138 and pos.y >= mcl_vars.mg_nether_min - 10 return pos.y <= max3 + 138 and pos.y >= min3 - 10
end end
-- Takes a position (pos) and returns true if compasses are working here -- Takes a position (pos) and returns true if compasses are working here
@ -89,7 +89,7 @@ function mcl_worlds.compass_works(pos)
if dim == "nether" or dim == "end" then if dim == "nether" or dim == "end" then
return false return false
elseif dim == "void" then elseif dim == "void" then
return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64 return pos.y <= max1 and pos.y >= min1 - 64
else else
return true return true
end end
@ -152,4 +152,3 @@ minetest.register_globalstep(function(dtime)
dimtimer = 0 dimtimer = 0
end end
end) end)

View File

@ -29,7 +29,6 @@ local math_min = math.min
local math_max = math.max local math_max = math.max
local math_ceil = math.ceil local math_ceil = math.ceil
--custom mcl_vars
local get_node = mcl_mapgen.get_far_node local get_node = mcl_mapgen.get_far_node

View File

@ -1,59 +1,3 @@
--[[
-------------------------------------------------------------------------------
-- build schematic, replace material, rotation
-------------------------------------------------------------------------------
function settlements.build_schematic(vm, data, va, pos, building, replace_wall, name)
-- get building node material for better integration to surrounding
local platform_material = mcl_vars.get_node(pos)
if not platform_material or (platform_material.name == "air" or platform_material.name == "ignore") then
return
end
platform_material = platform_material.name
-- pick random material
local material = wallmaterial[math.random(1,#wallmaterial)]
-- schematic conversion to lua
local schem_lua = minetest.serialize_schematic(building,
"lua",
{lua_use_comments = false, lua_num_indent_spaces = 0}).." return schematic"
-- replace material
if replace_wall == "y" then
schem_lua = schem_lua:gsub("mcl_core:cobble", material)
end
schem_lua = schem_lua:gsub("mcl_core:dirt_with_grass",
platform_material)
-- Disable special junglewood for now.
-- special material for spawning npcs
-- schem_lua = schem_lua:gsub("mcl_core:junglewood",
-- "settlements:junglewood")
--
-- format schematic string
local schematic = loadstring(schem_lua)()
-- build foundation for the building an make room above
local width = schematic["size"]["x"]
local depth = schematic["size"]["z"]
local height = schematic["size"]["y"]
local possible_rotations = {"0", "90", "180", "270"}
local rotation = possible_rotations[ math.random( #possible_rotations ) ]
settlements.foundation(
pos,
width,
depth,
height,
rotation)
vm:set_data(data)
-- place schematic
minetest.place_schematic_on_vmanip(
vm,
pos,
schematic,
rotation,
nil,
true)
vm:write_to_map(true)
end]]
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- initialize settlement_info -- initialize settlement_info
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View File

@ -50,12 +50,6 @@ function settlements.terraform(settlement_info, pr)
local p = {x=pos.x+xi, y=pos.y, z=pos.z+zi} local p = {x=pos.x+xi, y=pos.y, z=pos.z+zi}
settlements.ground(p, pr) settlements.ground(p, pr)
else else
-- write ground
-- local p = {x=pos.x+xi, y=pos.y+yi, z=pos.z+zi}
-- local node = mcl_vars.get_node(p)
-- if node and node.name ~= "air" then
-- minetest.swap_node(p,{name="air"})
-- end
minetest.swap_node({x=pos.x+xi, y=pos.y+yi, z=pos.z+zi},{name="air"}) minetest.swap_node({x=pos.x+xi, y=pos.y+yi, z=pos.z+zi},{name="air"})
end end
end end