1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2025-07-03 00:20:39 +02:00

Some minor clean ups

This commit is contained in:
sfan5
2024-05-26 15:56:32 +02:00
parent 57e7d4c488
commit fb7a37e87c
4 changed files with 16 additions and 23 deletions

View File

@ -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

View File

@ -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