parent
30d60bd914
commit
af6df74b74
94
extender.lua
94
extender.lua
|
@ -18,8 +18,8 @@ local jit_available = jit ~= nil
|
||||||
-- `pos1` is less than or equal to the corresponding component of `pos2`.
|
-- `pos1` is less than or equal to the corresponding component of `pos2`.
|
||||||
-- @return the new positions.
|
-- @return the new positions.
|
||||||
local function sort_pos(pos1, pos2)
|
local function sort_pos(pos1, pos2)
|
||||||
pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
|
pos1 = {x = pos1.x, y = pos1.y, z = pos1.z}
|
||||||
pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
|
pos2 = {x = pos2.x, y = pos2.y, z = pos2.z}
|
||||||
if pos1.x > pos2.x then
|
if pos1.x > pos2.x then
|
||||||
pos2.x, pos1.x = pos1.x, pos2.x
|
pos2.x, pos1.x = pos1.x, pos2.x
|
||||||
end
|
end
|
||||||
|
@ -67,33 +67,35 @@ local function load_schematic(value)
|
||||||
-- This is broken for larger tables in the current version of LuaJIT
|
-- This is broken for larger tables in the current version of LuaJIT
|
||||||
nodes = minetest.deserialize(content)
|
nodes = minetest.deserialize(content)
|
||||||
else
|
else
|
||||||
-- XXX: This is a filthy hack that works surprisingly well - in LuaJIT, `minetest.deserialize` will fail due to the register limit
|
-- XXX: This is a filthy hack that works surprisingly well - in LuaJIT,
|
||||||
|
-- `minetest.deserialize` will fail due to the register limit
|
||||||
content = content:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1) -- remove the starting and ending values to leave only the node data
|
content = content:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1) -- remove the starting and ending values to leave only the node data
|
||||||
local escaped = content:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
|
local escaped = content:gsub("\\\\", "@@"):gsub(
|
||||||
local startpos, startpos1, endpos = 1, 1
|
"\\\"", "@@"):gsub("(\"[^\"] * \")", function(s) return string.rep("@", #s) end)
|
||||||
while true do -- go through each individual node entry (except the last)
|
local startpos, startpos1, endpos = 1, 1
|
||||||
startpos, endpos = escaped:find("},%s*{", startpos)
|
while true do -- go through each individual node entry (except the last)
|
||||||
if not startpos then
|
startpos, endpos = escaped:find("},%s*{", startpos)
|
||||||
break
|
if not startpos then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
local current = content:sub(startpos1, startpos)
|
||||||
|
local entry = minetest.deserialize("return " .. current)
|
||||||
|
table.insert(nodes, entry)
|
||||||
|
startpos, startpos1 = endpos, endpos
|
||||||
end
|
end
|
||||||
local current = content:sub(startpos1, startpos)
|
local entry = minetest.deserialize("return " .. content:sub(startpos1)) -- process the last entry
|
||||||
local entry = minetest.deserialize("return " .. current)
|
|
||||||
table.insert(nodes, entry)
|
table.insert(nodes, entry)
|
||||||
startpos, startpos1 = endpos, endpos
|
|
||||||
end
|
end
|
||||||
local entry = minetest.deserialize("return " .. content:sub(startpos1)) -- process the last entry
|
else
|
||||||
table.insert(nodes, entry)
|
return nil
|
||||||
end
|
end
|
||||||
else
|
return nodes
|
||||||
return nil
|
|
||||||
end
|
|
||||||
return nodes
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function allocate_with_nodes(origin_pos, nodes)
|
local function allocate_with_nodes(origin_pos, nodes)
|
||||||
local huge = math.huge
|
local huge = math.huge
|
||||||
local pos1x, pos1y, pos1z = huge, huge, huge
|
local pos1x, pos1y, pos1z = huge, huge, huge
|
||||||
local pos2x, pos2y, pos2z = -huge, -huge, -huge
|
local pos2x, pos2y, pos2z = -huge, - huge, - huge
|
||||||
local origin_x, origin_y, origin_z = origin_pos.x, origin_pos.y, origin_pos.z
|
local origin_x, origin_y, origin_z = origin_pos.x, origin_pos.y, origin_pos.z
|
||||||
for i, entry in ipairs(nodes) do
|
for i, entry in ipairs(nodes) do
|
||||||
local x, y, z = origin_x + entry.x, origin_y + entry.y, origin_z + entry.z
|
local x, y, z = origin_x + entry.x, origin_y + entry.y, origin_z + entry.z
|
||||||
|
@ -104,8 +106,8 @@ local function allocate_with_nodes(origin_pos, nodes)
|
||||||
if y > pos2y then pos2y = y end
|
if y > pos2y then pos2y = y end
|
||||||
if z > pos2z then pos2z = z end
|
if z > pos2z then pos2z = z end
|
||||||
end
|
end
|
||||||
local pos1 = {x=pos1x, y=pos1y, z=pos1z}
|
local pos1 = {x = pos1x, y = pos1y, z = pos1z}
|
||||||
local pos2 = {x=pos2x, y=pos2y, z=pos2z}
|
local pos2 = {x = pos2x, y = pos2y, z = pos2z}
|
||||||
return pos1, pos2, #nodes
|
return pos1, pos2, #nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,8 +118,8 @@ end
|
||||||
local function volume(pos1, pos2)
|
local function volume(pos1, pos2)
|
||||||
local p1, p2 = sort_pos(pos1, pos2)
|
local p1, p2 = sort_pos(pos1, pos2)
|
||||||
return (p2.x - p1.x + 1) *
|
return (p2.x - p1.x + 1) *
|
||||||
(p2.y - p1.y + 1) *
|
(p2.y - p1.y + 1) *
|
||||||
(p2.z - p1.z + 1)
|
(p2.z - p1.z + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Slice a region along the midpoint of an axis
|
--- Slice a region along the midpoint of an axis
|
||||||
|
@ -190,7 +192,7 @@ end
|
||||||
local function init(pos1, pos2)
|
local function init(pos1, pos2)
|
||||||
local manip = minetest.get_voxel_manip()
|
local manip = minetest.get_voxel_manip()
|
||||||
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||||
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
local area = VoxelArea:new({MinEdge = emerged_pos1, MaxEdge = emerged_pos2})
|
||||||
return manip, area
|
return manip, area
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -214,22 +216,22 @@ local function shield(pos, vol, remove)
|
||||||
node_2 = minetest.get_content_id("eggwars:kill")
|
node_2 = minetest.get_content_id("eggwars:kill")
|
||||||
msg = "Warning: Area now shielded"
|
msg = "Warning: Area now shielded"
|
||||||
end
|
end
|
||||||
local stride = {x=1, y=area.ystride, z=area.zstride}
|
local stride = {x = 1, y = area.ystride, z = area.zstride}
|
||||||
local offset = vector.subtract(pos, area.MinEdge)
|
local offset = vector.subtract(pos, area.MinEdge)
|
||||||
local count = 0
|
local count = 0
|
||||||
|
|
||||||
-- add the nodes
|
-- add the nodes
|
||||||
for z = 0, vol.z-1 do
|
for z = 0, vol.z - 1 do
|
||||||
local index_z = (offset.z + z) * stride.z + 1
|
local index_z = (offset.z + z) * stride.z + 1
|
||||||
for y = 0, vol.y-1 do
|
for y = 0, vol.y - 1 do
|
||||||
local index_y = index_z + (offset.y + y) * stride.y
|
local index_y = index_z + (offset.y + y) * stride.y
|
||||||
for x = 0, vol.x-1 do
|
for x = 0, vol.x - 1 do
|
||||||
local is_clip = z == 0 or z == vol.z-1
|
local is_clip = z == 0 or z == vol.z - 1
|
||||||
or y == 0 or y == vol.y-1
|
or y == 0 or y == vol.y - 1
|
||||||
or x == 0 or x == vol.x-1
|
or x == 0 or x == vol.x - 1
|
||||||
local is_kill = z == 1 or z == vol.z-2 or z == vol.z-3
|
local is_kill = z == 1 or z == vol.z - 2 or z == vol.z - 3
|
||||||
or y == 1 or y == 2 or y == vol.y-2 or y == vol.y-3
|
or y == 1 or y == 2 or y == vol.y - 2 or y == vol.y - 3
|
||||||
or x == 1 or x == 2 or x == vol.x-2 or x == vol.x-3
|
or x == 1 or x == 2 or x == vol.x - 2 or x == vol.x - 3
|
||||||
if is_clip then
|
if is_clip then
|
||||||
local i = index_y + (offset.x + x)
|
local i = index_y + (offset.x + x)
|
||||||
data[i] = node_1
|
data[i] = node_1
|
||||||
|
@ -295,17 +297,17 @@ function eggwars.clear_objects(pos1, pos2)
|
||||||
}
|
}
|
||||||
-- Bounding sphere radius
|
-- Bounding sphere radius
|
||||||
local radius = math.sqrt(
|
local radius = math.sqrt(
|
||||||
(center.x - pos1x) ^ 2 +
|
(center.x - pos1x) ^ 2 +
|
||||||
(center.y - pos1y) ^ 2 +
|
(center.y - pos1y) ^ 2 +
|
||||||
(center.z - pos1z) ^ 2)
|
(center.z - pos1z) ^ 2)
|
||||||
local count = 0
|
local count = 0
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(center, radius)) do
|
for _, obj in pairs(minetest.get_objects_inside_radius(center, radius)) do
|
||||||
-- Avoid players
|
-- Avoid players
|
||||||
if not obj:is_player() then
|
if not obj:is_player() then
|
||||||
local pos = obj:getpos()
|
local pos = obj:getpos()
|
||||||
if pos.x >= pos1x and pos.x <= pos2x and
|
if pos.x >= pos1x and pos.x <= pos2x and
|
||||||
pos.y >= pos1y and pos.y <= pos2y and
|
pos.y >= pos1y and pos.y <= pos2y and
|
||||||
pos.z >= pos1z and pos.z <= pos2z then
|
pos.z >= pos1z and pos.z <= pos2z then
|
||||||
-- Inside region
|
-- Inside region
|
||||||
obj:remove()
|
obj:remove()
|
||||||
count = count + 1
|
count = count + 1
|
||||||
|
@ -331,13 +333,13 @@ function eggwars.clear_nodes(pos1, pos2)
|
||||||
"group:crumbly",
|
"group:crumbly",
|
||||||
"group:oddly_breakable_by_hand"
|
"group:oddly_breakable_by_hand"
|
||||||
}
|
}
|
||||||
local slices = region_slicer(pos1, pos2, 'y')
|
local slices = region_slicer(p1, p2, 'y')
|
||||||
local n = 0
|
local n = 0
|
||||||
|
|
||||||
for _, slice in ipairs(slices) do
|
for _, slice in ipairs(slices) do
|
||||||
local found = minetest.find_nodes_in_area(slice.p1, slice.p2, nodenames)
|
local found = minetest.find_nodes_in_area(slice.p1, slice.p2, nodenames)
|
||||||
for _,v in ipairs(found) do
|
for _, v in ipairs(found) do
|
||||||
minetest.set_node(v, {name="air"})
|
minetest.set_node(v, {name = "air"})
|
||||||
end
|
end
|
||||||
n = n + #found
|
n = n + #found
|
||||||
end
|
end
|
||||||
|
@ -397,7 +399,7 @@ function eggwars.serialize_meta(pos1, pos2)
|
||||||
pos1, pos2 = sort_pos(pos1, pos2)
|
pos1, pos2 = sort_pos(pos1, pos2)
|
||||||
keep_loaded(pos1, pos2)
|
keep_loaded(pos1, pos2)
|
||||||
|
|
||||||
local pos = {x=pos1.x, y=0, z=0}
|
local pos = {x = pos1.x, y = 0, z = 0}
|
||||||
local count = 0
|
local count = 0
|
||||||
local result = {}
|
local result = {}
|
||||||
local get_node, get_meta = minetest.get_node, minetest.get_meta
|
local get_node, get_meta = minetest.get_node, minetest.get_meta
|
||||||
|
@ -479,9 +481,9 @@ eggwars.protect = function(pos1, pos2, remove)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- unsign if reqd
|
-- unsign if reqd
|
||||||
for k,v in pairs(dims) do
|
for k, v in pairs(dims) do
|
||||||
if v < 0 then
|
if v < 0 then
|
||||||
dims[k] = (v*v)^0.5
|
dims[k] = (v * v)^0.5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -510,7 +512,7 @@ if eggwars.armor then
|
||||||
if not name then
|
if not name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for i=1, armor_inv:get_size("armor") do
|
for i = 1, armor_inv:get_size("armor") do
|
||||||
local stack = armor_inv:get_stack("armor", i)
|
local stack = armor_inv:get_stack("armor", i)
|
||||||
if stack:get_count() > 0 then
|
if stack:get_count() > 0 then
|
||||||
armor:run_callbacks("on_unequip", player, i, stack)
|
armor:run_callbacks("on_unequip", player, i, stack)
|
||||||
|
|
Loading…
Reference in New Issue