forked from VoxeLibre/VoxeLibre
Delete unused WorldEdit code in mcl_structures
This commit is contained in:
parent
b8461596a3
commit
bc1e16fbc6
|
@ -15,130 +15,6 @@ mcl_structures.get_struct = function(file)
|
||||||
return allnode
|
return allnode
|
||||||
end
|
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 == 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
|
|
||||||
else
|
|
||||||
minetest.log("error", "[mcl_structures] Unsupported WorldEdit file format ("..version..")")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local pos1 = {x=pos1x, y=pos1y, z=pos1z}
|
|
||||||
local pos2 = {x=pos2x, y=pos2y, z=pos2z}
|
|
||||||
return pos1, pos2, count
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Deserialize WorldEdit string and set the nodes in the world.
|
|
||||||
Returns: count, chests
|
|
||||||
* count: Number of nodes set
|
|
||||||
* chests: Table of chest positions (use these to spawn treasures
|
|
||||||
]]
|
|
||||||
mcl_structures.deserialise_WE = function(originpos, value)
|
|
||||||
--make area stay loaded
|
|
||||||
local pos1, pos2 = mcl_structures.allocate_WE(originpos, value)
|
|
||||||
local count = 0
|
|
||||||
local chests = {} -- Remember positions of all chests
|
|
||||||
if not pos1 then
|
|
||||||
return count, chests
|
|
||||||
end
|
|
||||||
local manip = minetest.get_voxel_manip()
|
|
||||||
manip:read_from_map(pos1, pos2)
|
|
||||||
|
|
||||||
local originx, originy, originz = originpos.x, originpos.y, originpos.z
|
|
||||||
local add_node, get_meta = minetest.add_node, minetest.get_meta
|
|
||||||
local version = mcl_structures.valueversion_WE(value)
|
|
||||||
if 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 and remember chests
|
|
||||||
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
|
|
||||||
if entry.name == "mcl_chests:chest" then
|
|
||||||
table.insert(chests, {x=entry.x, y=entry.y, z=entry.z})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--load the metadata
|
|
||||||
for index = 1, count do
|
|
||||||
local entry = nodes[index]
|
|
||||||
get_meta(entry):from_table(entry.meta)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return count, chests
|
|
||||||
end
|
|
||||||
|
|
||||||
-- End of world edit deserialise part
|
|
||||||
|
|
||||||
|
|
||||||
-- The call of Struct
|
-- The call of Struct
|
||||||
mcl_structures.call_struct = function(pos, struct_style, rotation)
|
mcl_structures.call_struct = function(pos, struct_style, rotation)
|
||||||
if not rotation then
|
if not rotation then
|
||||||
|
@ -362,4 +238,4 @@ minetest.register_chatcommand("spawnstruct", {
|
||||||
})
|
})
|
||||||
|
|
||||||
local time_to_load= os.clock() - init
|
local time_to_load= os.clock() - init
|
||||||
print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))
|
minetest.log("action", (string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load)))
|
||||||
|
|
Loading…
Reference in New Issue