From fb7a37e87c12cc2d35c2c27f219d9066dc74caf3 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 May 2024 15:56:32 +0200 Subject: [PATCH] Some minor clean ups --- ChatCommands.md | 9 +++++---- worldedit/common.lua | 6 +++--- worldedit/primitives.lua | 20 ++++++-------------- worldedit_commands/marker.lua | 4 ++-- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/ChatCommands.md b/ChatCommands.md index 07082fb..1b7a1c0 100644 --- a/ChatCommands.md +++ b/ChatCommands.md @@ -409,14 +409,15 @@ Load nodes from "(world folder)/schems/``.we" with position 1 of the curre ### `//lua ` -Executes `` as a Lua chunk in the global namespace. +Executes `` as a Lua chunk in the global namespace with the variables `name`, `player` and `pos` (= player position) available. - //lua worldedit.pos1["singleplayer"] = {x=0, y=0, z=0} - //lua worldedit.rotate(worldedit.pos1["singleplayer"], worldedit.pos2["singleplayer"], "y", 90) + //lua worldedit.pos1[name] = vector.new(0, 0, 0) + //lua worldedit.rotate(worldedit.pos1["jones"], worldedit.pos2["jones"], "y", 90) + //lua player:set_pos(worldedit.pos2[name]) ### `//luatransform ` -Executes `` as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region. +Executes `` as a Lua chunk in the global namespace with the variable `pos` available, for each node in the current WorldEdit region. //luatransform minetest.swap_node(pos, {name="default:stone"}) //luatransform if minetest.get_node(pos).name == "air" then minetest.add_node(pos, {name="default:water_source"}) end diff --git a/worldedit/common.lua b/worldedit/common.lua index 55b10f1..8289f66 100644 --- a/worldedit/common.lua +++ b/worldedit/common.lua @@ -14,8 +14,8 @@ end -- `pos1` is less than or equal to the corresponding component of `pos2`. -- Returns the new positions. function worldedit.sort_pos(pos1, pos2) - pos1 = vector.new(pos1.x, pos1.y, pos1.z) - pos2 = vector.new(pos2.x, pos2.y, pos2.z) + pos1 = vector.copy(pos1) + pos2 = vector.copy(pos2) if pos1.x > pos2.x then pos2.x, pos1.x = pos1.x, pos2.x end @@ -84,7 +84,7 @@ function mh.get_empty_data(area) -- only partially modified aren't overwriten. local data = {} local c_ignore = minetest.get_content_id("ignore") - for i = 1, worldedit.volume(area.MinEdge, area.MaxEdge) do + for i = 1, area:getVolume() do data[i] = c_ignore end return data diff --git a/worldedit/primitives.lua b/worldedit/primitives.lua index 8d1a3c3..07b175c 100644 --- a/worldedit/primitives.lua +++ b/worldedit/primitives.lua @@ -15,9 +15,9 @@ local mh = worldedit.manip_helpers function worldedit.cube(pos, width, height, length, node_name, hollow) -- Set up voxel manipulator local basepos = vector.subtract(pos, - {x = math.floor(width / 2), y = 0, z = math.floor(length / 2)}) + vector.new(math.floor(width / 2), 0, math.floor(length / 2))) local endpos = vector.add(basepos, - {x = width - 1, y = height - 1, z = length - 1}) + vector.new(width - 1, height - 1, length - 1)) local manip, area = mh.init(basepos, endpos) local data = mh.get_empty_data(area) @@ -158,11 +158,7 @@ function worldedit.cylinder(pos, axis, length, radius1, radius2, node_name, holl -- Add desired shape (anything inbetween cylinder & cone) local node_id = minetest.get_content_id(node_name) local stride = vector.new(1, area.ystride, area.zstride) - local offset = { - x = current_pos.x - area.MinEdge.x, - y = current_pos.y - area.MinEdge.y, - z = current_pos.z - area.MinEdge.z, - } + local offset = vector.subtract(current_pos, area.MinEdge) local count = 0 for i = 0, length - 1 do -- Calulate radius for this "height" in the cylinder @@ -221,11 +217,7 @@ function worldedit.pyramid(pos, axis, height, node_name, hollow) -- Add pyramid local node_id = minetest.get_content_id(node_name) local stride = vector.new(1, area.ystride, area.zstride) - local offset = { - x = pos.x - area.MinEdge.x, - y = pos.y - area.MinEdge.y, - z = pos.z - area.MinEdge.z, - } + local offset = vector.subtract(pos, area.MinEdge) local size = math.abs(height * step) local count = 0 -- For each level of the pyramid @@ -267,8 +259,8 @@ function worldedit.spiral(pos, length, height, spacer, node_name) -- Set up variables local node_id = minetest.get_content_id(node_name) local stride = vector.new(1, area.ystride, area.zstride) - local offset_x, offset_y, offset_z = pos.x - area.MinEdge.x, pos.y - area.MinEdge.y, pos.z - area.MinEdge.z - local i = offset_z * stride.z + offset_y * stride.y + offset_x + 1 + local offset = vector.subtract(pos, area.MinEdge) + local i = offset.z * stride.z + offset.y * stride.y + offset.x + 1 -- Add first column local count = height diff --git a/worldedit_commands/marker.lua b/worldedit_commands/marker.lua index 34f02c5..640f373 100644 --- a/worldedit_commands/marker.lua +++ b/worldedit_commands/marker.lua @@ -80,7 +80,7 @@ worldedit.mark_region = function(name) --XY plane markers for _, z in ipairs({pos1.z - 0.5, pos2.z + 0.5}) do - local entpos = {x=pos1.x + sizex - 0.5, y=pos1.y + sizey - 0.5, z=z} + local entpos = vector.new(pos1.x + sizex - 0.5, pos1.y + sizey - 0.5, z) local marker = minetest.add_entity(entpos, "worldedit:region_cube", init_sentinel) if marker ~= nil then marker:set_properties({ @@ -94,7 +94,7 @@ worldedit.mark_region = function(name) --YZ plane markers for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do - local entpos = {x=x, y=pos1.y + sizey - 0.5, z=pos1.z + sizez - 0.5} + local entpos = vector.new(x, pos1.y + sizey - 0.5, pos1.z + sizez - 0.5) local marker = minetest.add_entity(entpos, "worldedit:region_cube", init_sentinel) if marker ~= nil then marker:set_properties({