0
0
Fork 0

Remove get_structure_data_construct

the positions are available from the registered structure
This commit is contained in:
cora 2022-10-24 05:12:01 +02:00
parent c30e2c33b9
commit 9aaa13408a
3 changed files with 9 additions and 41 deletions

View File

@ -87,7 +87,7 @@ minetest.register_craftitem("mcl_end:ender_eye", {
end end
local origin = user:get_pos() local origin = user:get_pos()
origin.y = origin.y + 1.5 origin.y = origin.y + 1.5
local strongholds = mcl_structures.get_structure_data("stronghold") local strongholds = mcl_structures.registered_structures["end_shrine"].static_pos
local dim = mcl_worlds.pos_to_dimension(origin) local dim = mcl_worlds.pos_to_dimension(origin)
local is_creative = minetest.is_creative_enabled(user:get_player_name()) local is_creative = minetest.is_creative_enabled(user:get_player_name())
@ -105,7 +105,7 @@ minetest.register_craftitem("mcl_end:ender_eye", {
local closest_stronghold local closest_stronghold
local lowest_dist local lowest_dist
for s=1, #strongholds do for s=1, #strongholds do
local h_pos = table.copy(strongholds[s].pos) local h_pos = table.copy(strongholds[s])
local h_origin = table.copy(origin) local h_origin = table.copy(origin)
h_pos.y = 0 h_pos.y = 0
h_origin.y = 0 h_origin.y = 0
@ -128,14 +128,14 @@ minetest.register_craftitem("mcl_end:ender_eye", {
if lowest_dist <= 25 then if lowest_dist <= 25 then
local velocity = 4 local velocity = 4
-- Stronghold is close: Fly directly to stronghold and take Y into account. -- Stronghold is close: Fly directly to stronghold and take Y into account.
dir = vector.normalize(vector.direction(origin, closest_stronghold.pos)) dir = vector.normalize(vector.direction(origin, closest_stronghold))
obj:set_velocity({x=dir.x*velocity, y=dir.y*velocity, z=dir.z*velocity}) obj:set_velocity({x=dir.x*velocity, y=dir.y*velocity, z=dir.z*velocity})
else else
local velocity = 12 local velocity = 12
-- Don't care about Y if stronghold is still far away. -- Don't care about Y if stronghold is still far away.
-- Fly to direction of X/Z, and always upwards so it can be seen easily. -- Fly to direction of X/Z, and always upwards so it can be seen easily.
local o = {x=origin.x, y=0, z=origin.z} local o = {x=origin.x, y=0, z=origin.z}
local s = {x=closest_stronghold.pos.x, y=0, z=closest_stronghold.pos.z} local s = {x=closest_stronghold.x, y=0, z=closest_stronghold.z}
dir = vector.normalize(vector.direction(o, s)) dir = vector.normalize(vector.direction(o, s))
obj:set_acceleration({x=dir.x*-3, y=4, z=dir.z*-3}) obj:set_acceleration({x=dir.x*-3, y=4, z=dir.z*-3})
obj:set_velocity({x=dir.x*velocity, y=3, z=dir.z*velocity}) obj:set_velocity({x=dir.x*velocity, y=3, z=dir.z*velocity})

View File

@ -16,26 +16,17 @@ local stronghold_rings = {
} }
local strongholds = {} local strongholds = {}
local stronghold_positions = {}
local strongholds_inited = false
local mg_name = minetest.get_mapgen_setting("mg_name") local mg_name = minetest.get_mapgen_setting("mg_name")
local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true"
local seed = tonumber(minetest.get_mapgen_setting("seed"))
-- Determine the stronghold positions and store them into the strongholds table.
-- The stronghold positions are based on the world seed.
-- The actual position might be offset by a few blocks because it might be shifted
-- to make sure the end portal room is completely within the boundaries of a mapchunk.
local function init_strongholds() local function init_strongholds()
if strongholds_inited then local stronghold_positions = {}
return
end
-- Don't generate strongholds in singlenode -- Don't generate strongholds in singlenode
if mg_name == "singlenode" then if mg_name == "singlenode" then
strongholds_inited = true return {}
return
end end
local seed = tonumber(minetest.get_mapgen_setting("seed"))
local pr = PseudoRandom(seed) local pr = PseudoRandom(seed)
for s=1, #stronghold_rings do for s=1, #stronghold_rings do
local ring = stronghold_rings[s] local ring = stronghold_rings[s]
@ -54,7 +45,6 @@ local function init_strongholds()
end end
local pos = { x = math.cos(angle) * dist, y = y, z = math.sin(angle) * dist } local pos = { x = math.cos(angle) * dist, y = y, z = math.sin(angle) * dist }
pos = vector.round(pos) pos = vector.round(pos)
table.insert(strongholds, { pos = pos, generated = false })
table.insert(stronghold_positions, pos) table.insert(stronghold_positions, pos)
-- Rotate angle by (360 / amount) degrees. -- Rotate angle by (360 / amount) degrees.
@ -62,10 +52,7 @@ local function init_strongholds()
angle = math.fmod(angle + ((math.pi*2) / ring.amount), math.pi*2) angle = math.fmod(angle + ((math.pi*2) / ring.amount), math.pi*2)
end end
end end
return stronghold_positions
mcl_structures.register_structure_data("stronghold", table.copy(strongholds))
strongholds_inited = true
end end
-- Stronghold generation for register_on_generated. -- Stronghold generation for register_on_generated.
@ -103,10 +90,8 @@ local function generate_strongholds(minp, maxp, blockseed)
end end
end end
init_strongholds()
mcl_structures.register_structure("end_shrine",{ mcl_structures.register_structure("end_shrine",{
static_pos = stronghold_positions, static_pos = init_strongholds(),
filenames = { filenames = {
minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_portal_room_simple.mts" minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_portal_room_simple.mts"
}, },

View File

@ -3,7 +3,6 @@ local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
mcl_structures = {} mcl_structures = {}
local structure_data = {}
local rotations = { local rotations = {
"0", "0",
@ -85,22 +84,6 @@ local function dir_to_rotation(dir)
return "0" return "0"
end end
--this is only used by end shrines - find a better way eventually ...
function mcl_structures.get_structure_data(structure_type)
if structure_data[structure_type] then
return table.copy(structure_data[structure_type])
else
return {}
end
end
-- Register a structures table for the given type. The table format is the same as for
-- mcl_structures.get_structure_data.
function mcl_structures.register_structure_data(structure_type, structures)
structure_data[structure_type] = structures
end
dofile(modpath.."/api.lua") dofile(modpath.."/api.lua")
dofile(modpath.."/shipwrecks.lua") dofile(modpath.."/shipwrecks.lua")
dofile(modpath.."/desert_temple.lua") dofile(modpath.."/desert_temple.lua")