Skip to content

Commit

Permalink
Some minor clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed May 26, 2024
1 parent 57e7d4c commit fb7a37e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
9 changes: 5 additions & 4 deletions ChatCommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,15 @@ Load nodes from "(world folder)/schems/`<file>`.we" with position 1 of the curre

### `//lua <code>`

Executes `<code>` as a Lua chunk in the global namespace.
Executes `<code>` 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 <code>`

Executes `<code>` as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region.
Executes `<code>` 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
Expand Down
6 changes: 3 additions & 3 deletions worldedit/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 6 additions & 14 deletions worldedit/primitives.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions worldedit_commands/marker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down

0 comments on commit fb7a37e

Please sign in to comment.