Rename random_struct to mcl_structures
This commit is contained in:
parent
7c85b380b9
commit
ba2d83eff9
15 changed files with 24 additions and 23 deletions
1
mods/MAPGEN/mcl_structures/build/desert_temple.we
Normal file
1
mods/MAPGEN/mcl_structures/build/desert_temple.we
Normal file
File diff suppressed because one or more lines are too long
1
mods/MAPGEN/mcl_structures/build/pnj_field_1.we
Normal file
1
mods/MAPGEN/mcl_structures/build/pnj_field_1.we
Normal file
File diff suppressed because one or more lines are too long
1
mods/MAPGEN/mcl_structures/build/pnj_house_1.we
Normal file
1
mods/MAPGEN/mcl_structures/build/pnj_house_1.we
Normal file
File diff suppressed because one or more lines are too long
1
mods/MAPGEN/mcl_structures/build/pnj_house_2.we
Normal file
1
mods/MAPGEN/mcl_structures/build/pnj_house_2.we
Normal file
File diff suppressed because one or more lines are too long
1
mods/MAPGEN/mcl_structures/build/pnj_house_3.we
Normal file
1
mods/MAPGEN/mcl_structures/build/pnj_house_3.we
Normal file
File diff suppressed because one or more lines are too long
1
mods/MAPGEN/mcl_structures/build/pnj_light.we
Normal file
1
mods/MAPGEN/mcl_structures/build/pnj_light.we
Normal file
|
@ -0,0 +1 @@
|
|||
return {{["y"] = 3, ["x"] = 0, ["name"] = "mcl_torches:torch_wall", ["z"] = 1, ["meta"] = {["inventory"] = {}, ["fields"] = {}}, ["param2"] = 1, ["param1"] = 15}, {["y"] = 0, ["x"] = 1, ["name"] = "mcl_fences:fence", ["z"] = 1, ["meta"] = {["inventory"] = {}, ["fields"] = {}}, ["param2"] = 0, ["param1"] = 157}, {["y"] = 1, ["x"] = 1, ["name"] = "mcl_fences:fence", ["z"] = 1, ["meta"] = {["inventory"] = {}, ["fields"] = {}}, ["param2"] = 0, ["param1"] = 173}, {["y"] = 2, ["x"] = 1, ["name"] = "mcl_fences:fence", ["z"] = 1, ["meta"] = {["inventory"] = {}, ["fields"] = {}}, ["param2"] = 0, ["param1"] = 189}, {["y"] = 3, ["x"] = 1, ["name"] = "mcl_torches:torch_wall", ["z"] = 0, ["meta"] = {["inventory"] = {}, ["fields"] = {}}, ["param2"] = 0, ["param1"] = 15}, {["y"] = 3, ["x"] = 1, ["name"] = "mcl_wool:black", ["z"] = 1, ["meta"] = {["inventory"] = {}, ["fields"] = {}}, ["param2"] = 0, ["param1"] = 0}, {["y"] = 3, ["x"] = 1, ["name"] = "mcl_torches:torch_wall", ["z"] = 2, ["meta"] = {["inventory"] = {}, ["fields"] = {}}, ["param2"] = 2, ["param1"] = 15}, {["y"] = 3, ["x"] = 2, ["name"] = "mcl_torches:torch_wall", ["z"] = 1, ["meta"] = {["inventory"] = {}, ["fields"] = {}}, ["param2"] = 3, ["param1"] = 15}}
|
1
mods/MAPGEN/mcl_structures/build/pnj_town_1.we
Normal file
1
mods/MAPGEN/mcl_structures/build/pnj_town_1.we
Normal file
File diff suppressed because one or more lines are too long
1
mods/MAPGEN/mcl_structures/build/pnj_town_withway_1.we
Normal file
1
mods/MAPGEN/mcl_structures/build/pnj_town_withway_1.we
Normal file
File diff suppressed because one or more lines are too long
1
mods/MAPGEN/mcl_structures/build/pnj_watersource.we
Normal file
1
mods/MAPGEN/mcl_structures/build/pnj_watersource.we
Normal file
File diff suppressed because one or more lines are too long
1
mods/MAPGEN/mcl_structures/build/witcher_house.we
Normal file
1
mods/MAPGEN/mcl_structures/build/witcher_house.we
Normal file
File diff suppressed because one or more lines are too long
11
mods/MAPGEN/mcl_structures/depends.txt
Normal file
11
mods/MAPGEN/mcl_structures/depends.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
mcl_core
|
||||
xpanes
|
||||
mcl_doors
|
||||
stairs
|
||||
mcl_colorblocks
|
||||
mcl_wool
|
||||
mcl_fences
|
||||
mcl_chests
|
||||
mcl_inventory
|
||||
mesecons_pressureplates
|
||||
mcl_tnt
|
286
mods/MAPGEN/mcl_structures/init.lua
Normal file
286
mods/MAPGEN/mcl_structures/init.lua
Normal file
|
@ -0,0 +1,286 @@
|
|||
local init = os.clock()
|
||||
mcl_structures ={}
|
||||
|
||||
mcl_structures.get_struct = function(file)
|
||||
local localfile = minetest.get_modpath("mcl_structures").."/build/"..file
|
||||
local file, errorload = io.open(localfile, "rb")
|
||||
if errorload ~= nil then
|
||||
minetest.log("error", '[mcl_structures] Could not open this struct: ' .. localfile)
|
||||
return nil
|
||||
end
|
||||
|
||||
local allnode = file:read("*a")
|
||||
file:close()
|
||||
|
||||
return allnode
|
||||
end
|
||||
|
||||
|
||||
-- World edit function
|
||||
|
||||
mcl_structures.valueversion_WE = function(value)
|
||||
if value:find("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)") and not value:find("%{") then --previous list format
|
||||
return 3
|
||||
elseif value:find("^[^\"']+%{%d+%}") then
|
||||
if value:find("%[\"meta\"%]") then --previous meta flat table format
|
||||
return 2
|
||||
end
|
||||
return 1 --original flat table format
|
||||
elseif value:find("%{") then --current nested table format
|
||||
return 4
|
||||
end
|
||||
return 0 --unknown format
|
||||
end
|
||||
mcl_structures.allocate_WE = function(originpos, value)
|
||||
local huge = math.huge
|
||||
local pos1x, pos1y, pos1z = huge, huge, huge
|
||||
local pos2x, pos2y, pos2z = -huge, -huge, -huge
|
||||
local originx, originy, originz = originpos.x, originpos.y, originpos.z
|
||||
local count = 0
|
||||
local version = mcl_structures.valueversion_WE (value)
|
||||
if version == 1 or version == 2 then --flat table format
|
||||
--obtain the node table
|
||||
local get_tables = loadstring(value)
|
||||
if get_tables then --error loading value
|
||||
return originpos, originpos, count
|
||||
end
|
||||
local tables = get_tables()
|
||||
|
||||
--transform the node table into an array of nodes
|
||||
for i = 1, #tables do
|
||||
for j, v in pairs(tables[i]) do
|
||||
if type(v) == "table" then
|
||||
tables[i][j] = tables[v[1]]
|
||||
end
|
||||
end
|
||||
end
|
||||
local nodes = tables[1]
|
||||
|
||||
--check the node array
|
||||
count = #nodes
|
||||
if version == 1 then --original flat table format
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
local pos = entry[1]
|
||||
local x, y, z = originx - pos.x, originy - pos.y, originz - pos.z
|
||||
if x < pos1x then pos1x = x end
|
||||
if y < pos1y then pos1y = y end
|
||||
if z < pos1z then pos1z = z end
|
||||
if x > pos2x then pos2x = x end
|
||||
if y > pos2y then pos2y = y end
|
||||
if z > pos2z then pos2z = z end
|
||||
end
|
||||
else --previous meta flat table format
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
local x, y, z = originx - entry.x, originy - entry.y, originz - entry.z
|
||||
if x < pos1x then pos1x = x end
|
||||
if y < pos1y then pos1y = y end
|
||||
if z < pos1z then pos1z = z end
|
||||
if x > pos2x then pos2x = x end
|
||||
if y > pos2y then pos2y = y end
|
||||
if z > pos2z then pos2z = z end
|
||||
end
|
||||
end
|
||||
elseif version == 3 then --previous list format
|
||||
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
|
||||
local x, y, z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
|
||||
if x < pos1x then pos1x = x end
|
||||
if y < pos1y then pos1y = y end
|
||||
if z < pos1z then pos1z = z end
|
||||
if x > pos2x then pos2x = x end
|
||||
if y > pos2y then pos2y = y end
|
||||
if z > pos2z then pos2z = z end
|
||||
count = count + 1
|
||||
end
|
||||
elseif version == 4 then --current nested table format
|
||||
--wip: this is a filthy hack that works surprisingly well
|
||||
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
|
||||
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
|
||||
local startpos, startpos1, endpos = 1, 1
|
||||
local nodes = {}
|
||||
while true do
|
||||
startpos, endpos = escaped:find("},%s*{", startpos)
|
||||
if not startpos then
|
||||
break
|
||||
end
|
||||
local current = value:sub(startpos1, startpos)
|
||||
table.insert(nodes, minetest.deserialize("return " .. current))
|
||||
startpos, startpos1 = endpos, endpos
|
||||
end
|
||||
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
|
||||
|
||||
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
|
||||
|
||||
count = #nodes
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
local x, y, z = originx + entry.x, originy + entry.y, originz + entry.z
|
||||
if x < pos1x then pos1x = x end
|
||||
if y < pos1y then pos1y = y end
|
||||
if z < pos1z then pos1z = z end
|
||||
if x > pos2x then pos2x = x end
|
||||
if y > pos2y then pos2y = y end
|
||||
if z > pos2z then pos2z = z end
|
||||
end
|
||||
end
|
||||
local pos1 = {x=pos1x, y=pos1y, z=pos1z}
|
||||
local pos2 = {x=pos2x, y=pos2y, z=pos2z}
|
||||
return pos1, pos2, count
|
||||
end
|
||||
mcl_structures.deserialise_WE = function(originpos, value)
|
||||
--make area stay loaded
|
||||
local pos1, pos2 = mcl_structures.allocate_WE(originpos, value)
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
|
||||
local originx, originy, originz = originpos.x, originpos.y, originpos.z
|
||||
local count = 0
|
||||
local add_node, get_meta = minetest.add_node, minetest.get_meta
|
||||
local version = mcl_structures.valueversion_WE(value)
|
||||
if version == 1 or version == 2 then --original flat table format
|
||||
--obtain the node table
|
||||
local get_tables = loadstring(value)
|
||||
if not get_tables then --error loading value
|
||||
return count
|
||||
end
|
||||
local tables = get_tables()
|
||||
|
||||
--transform the node table into an array of nodes
|
||||
for i = 1, #tables do
|
||||
for j, v in pairs(tables[i]) do
|
||||
if type(v) == "table" then
|
||||
tables[i][j] = tables[v[1]]
|
||||
end
|
||||
end
|
||||
end
|
||||
local nodes = tables[1]
|
||||
|
||||
--load the node array
|
||||
count = #nodes
|
||||
if version == 1 then --original flat table format
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
local pos = entry[1]
|
||||
pos.x, pos.y, pos.z = originx - pos.x, originy - pos.y, originz - pos.z
|
||||
add_node(pos, entry[2])
|
||||
end
|
||||
else --previous meta flat table format
|
||||
for index = 1, #nodes do
|
||||
local entry = nodes[index]
|
||||
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
|
||||
add_node(entry, entry) --entry acts both as position and as node
|
||||
get_meta(entry):from_table(entry.meta)
|
||||
end
|
||||
end
|
||||
elseif version == 3 then --previous list format
|
||||
local pos = {x=0, y=0, z=0}
|
||||
local node = {name="", param1=0, param2=0}
|
||||
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
|
||||
pos.x, pos.y, pos.z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
|
||||
node.name, node.param1, node.param2 = name, param1, param2
|
||||
add_node(pos, node)
|
||||
count = count + 1
|
||||
end
|
||||
elseif version == 4 then --current nested table format
|
||||
--wip: this is a filthy hack that works surprisingly well
|
||||
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
|
||||
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
|
||||
local startpos, startpos1, endpos = 1, 1
|
||||
local nodes = {}
|
||||
while true do
|
||||
startpos, endpos = escaped:find("},%s*{", startpos)
|
||||
if not startpos then
|
||||
break
|
||||
end
|
||||
local current = value:sub(startpos1, startpos)
|
||||
table.insert(nodes, minetest.deserialize("return " .. current))
|
||||
startpos, startpos1 = endpos, endpos
|
||||
end
|
||||
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
|
||||
|
||||
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
|
||||
|
||||
--load the nodes
|
||||
count = #nodes
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
|
||||
add_node(entry, entry) --entry acts both as position and as node
|
||||
end
|
||||
|
||||
--load the metadata
|
||||
for index = 1, count do
|
||||
local entry = nodes[index]
|
||||
get_meta(entry):from_table(entry.meta)
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
-- End of world edit deserialise part
|
||||
|
||||
|
||||
-- The call of Struct
|
||||
mcl_structures.call_struct= function(pos, struct_style)
|
||||
-- 1: Village , 2: Desert temple
|
||||
if struct_style == 1 then
|
||||
mcl_structures.geerate_village(pos)
|
||||
elseif struct_style == 2 then
|
||||
mcl_structures.generate_desert_temple(pos)
|
||||
end
|
||||
end
|
||||
|
||||
mcl_structures.generate_village = function(pos)
|
||||
-- No Generating for the moment only place it :D
|
||||
local city = mcl_structures.get_struct("pnj_town_1.we")
|
||||
local newpos = {x=pos.x,y=pos.y,z=pos.z}
|
||||
if newpos == nil then
|
||||
return
|
||||
end
|
||||
mcl_structures.deserialise_WE(newpos, city )
|
||||
end
|
||||
|
||||
mcl_structures.generate_desert_temple = function(pos)
|
||||
-- No Generating for the temple ... Why using it ? No Change
|
||||
local temple = mcl_structures.get_struct("desert_temple.we")
|
||||
local newpos = {x=pos.x,y=pos.y-12,z=pos.z}
|
||||
if newpos == nil then
|
||||
return
|
||||
end
|
||||
mcl_structures.deserialise_WE(newpos, temple)
|
||||
end
|
||||
|
||||
|
||||
-- Debug command
|
||||
minetest.register_chatcommand("spawnstruct", {
|
||||
params = "desert_temple | village",
|
||||
description = "Generate a pre-defined structure near your position.",
|
||||
privs = {debug = true},
|
||||
func = function(name, param)
|
||||
local pos= minetest.get_player_by_name(name):getpos()
|
||||
if not pos then
|
||||
return
|
||||
end
|
||||
local errord = false
|
||||
if param == "village" then
|
||||
mcl_structures.generate_village(pos)
|
||||
minetest.chat_send_player(name, "Village created.")
|
||||
elseif param == "desert_temple" then
|
||||
mcl_structures.generate_desert_temple(pos)
|
||||
minetest.chat_send_player(name, "Desert temple created.")
|
||||
elseif param == "" then
|
||||
minetest.chat_send_player(name, "Error: No structure type given. Please use “/spawnstruct <type>”.")
|
||||
errord = true
|
||||
else
|
||||
minetest.chat_send_player(name, "Error: Unknown structure type. Please use “/spawnstruct <type>”.")
|
||||
errord = true
|
||||
end
|
||||
if errord then
|
||||
minetest.chat_send_player(name, "Avaiable types: desert_temple, village")
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
local time_to_load= os.clock() - init
|
||||
print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))
|
1
mods/MAPGEN/mcl_structures/mod.conf
Normal file
1
mods/MAPGEN/mcl_structures/mod.conf
Normal file
|
@ -0,0 +1 @@
|
|||
name = mcl_structures
|
Loading…
Add table
Add a link
Reference in a new issue