mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-25 02:00:39 +01:00
Added hollow pyramids
This commit is contained in:
parent
fc037e9c82
commit
5f9efb1205
@ -22,6 +22,9 @@ Many commands also have shorter names that can be typed faster. For example, if
|
|||||||
| `//hdo` | `//hollowdome` |
|
| `//hdo` | `//hollowdome` |
|
||||||
| `//do` | `//dome` |
|
| `//do` | `//dome` |
|
||||||
| `//hcyl` | `//hollowcylinder` |
|
| `//hcyl` | `//hollowcylinder` |
|
||||||
|
| `//cyl` | `//cylinder` |
|
||||||
|
| `//hpyr` | `//hollowpyramid` |
|
||||||
|
| `//pyr` | `//pyramid` |
|
||||||
|
|
||||||
### `//about`
|
### `//about`
|
||||||
|
|
||||||
@ -190,6 +193,15 @@ Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length `<length
|
|||||||
//cylinder z -12 3 mesecons:wire_00000000_off
|
//cylinder z -12 3 mesecons:wire_00000000_off
|
||||||
//cylinder ? 2 4 default:stone
|
//cylinder ? 2 4 default:stone
|
||||||
|
|
||||||
|
### `//hollowpyramid x/y/z? <height> <node>`
|
||||||
|
|
||||||
|
Add hollow pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height `<height>`, composed of `<node>`.
|
||||||
|
|
||||||
|
//hollowpyramid x 8 Diamond Block
|
||||||
|
//hollowpyramid y -5 glass
|
||||||
|
//hollowpyramid z 2 mesecons:wire_00000000_off
|
||||||
|
//hollowpyramid ? 12 mesecons:wire_00000000_off
|
||||||
|
|
||||||
### `//pyramid x/y/z? <height> <node>`
|
### `//pyramid x/y/z? <height> <node>`
|
||||||
|
|
||||||
Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height `<height>`, composed of `<node>`.
|
Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height `<height>`, composed of `<node>`.
|
||||||
|
@ -127,9 +127,9 @@ Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `
|
|||||||
|
|
||||||
Returns the number of nodes added.
|
Returns the number of nodes added.
|
||||||
|
|
||||||
### count = worldedit.pyramid(pos, axis, height, node_name)
|
### count = worldedit.pyramid(pos, axis, height, node_name, hollow)
|
||||||
|
|
||||||
Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`.
|
Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`, composed of `node_name`.
|
||||||
|
|
||||||
Returns the number of nodes added.
|
Returns the number of nodes added.
|
||||||
|
|
||||||
|
@ -150,8 +150,9 @@ end
|
|||||||
-- @param axis Axis ("x", "y", or "z")
|
-- @param axis Axis ("x", "y", or "z")
|
||||||
-- @param height Pyramid height.
|
-- @param height Pyramid height.
|
||||||
-- @param node_name Name of node to make pyramid of.
|
-- @param node_name Name of node to make pyramid of.
|
||||||
|
-- @param hollow Whether the pyramid should be hollow.
|
||||||
-- @return The number of nodes added.
|
-- @return The number of nodes added.
|
||||||
function worldedit.pyramid(pos, axis, height, node_name)
|
function worldedit.pyramid(pos, axis, height, node_name, hollow)
|
||||||
local other1, other2 = worldedit.get_axis_others(axis)
|
local other1, other2 = worldedit.get_axis_others(axis)
|
||||||
|
|
||||||
-- Set up voxel manipulator
|
-- Set up voxel manipulator
|
||||||
@ -187,10 +188,12 @@ function worldedit.pyramid(pos, axis, height, node_name)
|
|||||||
local new_index2 = new_index1 + (index2 + offset[other1]) * stride[other1]
|
local new_index2 = new_index1 + (index2 + offset[other1]) * stride[other1]
|
||||||
for index3 = -size, size do
|
for index3 = -size, size do
|
||||||
local i = new_index2 + (index3 + offset[other2]) * stride[other2]
|
local i = new_index2 + (index3 + offset[other2]) * stride[other2]
|
||||||
data[i] = node_id
|
if (not hollow or size - math.abs(index2) < 2 or size - math.abs(index3) < 2) then
|
||||||
|
data[i] = node_id
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
count = count + (size * 2 + 1) ^ 2
|
|
||||||
size = size - 1
|
size = size - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -516,6 +516,39 @@ minetest.register_chatcommand("/cylinder", {
|
|||||||
end, check_cylinder),
|
end, check_cylinder),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local check_pyramid = function(name, param)
|
||||||
|
if worldedit.pos1[name] == nil then
|
||||||
|
worldedit.player_notify(name, "no position 1 selected")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
|
||||||
|
if found == nil then
|
||||||
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local node = get_node(name, nodename)
|
||||||
|
if not node then return nil end
|
||||||
|
height = tonumber(height)
|
||||||
|
return math.ceil(((height * 2 + 1) ^ 2) * height / 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("/hollowpyramid", {
|
||||||
|
params = "x/y/z/? <height> <node>",
|
||||||
|
description = "Add hollow pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
|
||||||
|
privs = {worldedit=true},
|
||||||
|
func = safe_region(function(name, param)
|
||||||
|
local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
|
||||||
|
height = tonumber(height)
|
||||||
|
if axis == "?" then
|
||||||
|
axis, sign = worldedit.player_axis(name)
|
||||||
|
height = height * sign
|
||||||
|
end
|
||||||
|
local node = get_node(name, nodename)
|
||||||
|
local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node, true)
|
||||||
|
worldedit.player_notify(name, count .. " nodes added")
|
||||||
|
end, check_pyramid),
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("/pyramid", {
|
minetest.register_chatcommand("/pyramid", {
|
||||||
params = "x/y/z/? <height> <node>",
|
params = "x/y/z/? <height> <node>",
|
||||||
description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
|
description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",
|
||||||
@ -530,22 +563,7 @@ minetest.register_chatcommand("/pyramid", {
|
|||||||
local node = get_node(name, nodename)
|
local node = get_node(name, nodename)
|
||||||
local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)
|
local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)
|
||||||
worldedit.player_notify(name, count .. " nodes added")
|
worldedit.player_notify(name, count .. " nodes added")
|
||||||
end,
|
end, check_pyramid),
|
||||||
function(name, param)
|
|
||||||
if worldedit.pos1[name] == nil then
|
|
||||||
worldedit.player_notify(name, "no position 1 selected")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
|
|
||||||
if found == nil then
|
|
||||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
local node = get_node(name, nodename)
|
|
||||||
if not node then return nil end
|
|
||||||
height = tonumber(height)
|
|
||||||
return math.ceil(((height * 2 + 1) ^ 2) * height / 3)
|
|
||||||
end),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("/spiral", {
|
minetest.register_chatcommand("/spiral", {
|
||||||
|
@ -295,18 +295,21 @@ worldedit.register_gui_function("worldedit_gui_pyramid", {
|
|||||||
or "image[5.5,1.1;1,1;unknown_node.png]") ..
|
or "image[5.5,1.1;1,1;unknown_node.png]") ..
|
||||||
string.format("field[0.5,2.5;4,0.8;worldedit_gui_pyramid_length;Length;%s]", minetest.formspec_escape(length)) ..
|
string.format("field[0.5,2.5;4,0.8;worldedit_gui_pyramid_length;Length;%s]", minetest.formspec_escape(length)) ..
|
||||||
string.format("dropdown[4,2.18;2.5;worldedit_gui_pyramid_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
|
string.format("dropdown[4,2.18;2.5;worldedit_gui_pyramid_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
|
||||||
"button_exit[0,3.5;3,0.8;worldedit_gui_pyramid_submit;Pyramid]"
|
"button_exit[0,3.5;3,0.8;worldedit_gui_pyramid_submit_hollow;Hollow Pyramid]" ..
|
||||||
|
"button_exit[3.5,3.5;3,0.8;worldedit_gui_pyramid_submit_solid;Solid Pyramid]"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
worldedit.register_gui_handler("worldedit_gui_pyramid", function(name, fields)
|
worldedit.register_gui_handler("worldedit_gui_pyramid", function(name, fields)
|
||||||
if fields.worldedit_gui_pyramid_search or fields.worldedit_gui_pyramid_submit then
|
if fields.worldedit_gui_pyramid_search or fields.worldedit_gui_pyramid_submit_solid or fields.worldedit_gui_pyramid_submit_hollow or fields.worldedit_gui_pyramid_axis then
|
||||||
gui_nodename1[name] = tostring(fields.worldedit_gui_pyramid_node)
|
gui_nodename1[name] = tostring(fields.worldedit_gui_pyramid_node)
|
||||||
gui_axis1[name] = axis_indices[fields.worldedit_gui_pyramid_axis]
|
gui_axis1[name] = axis_indices[fields.worldedit_gui_pyramid_axis]
|
||||||
gui_distance1[name] = tostring(fields.worldedit_gui_pyramid_length)
|
gui_distance1[name] = tostring(fields.worldedit_gui_pyramid_length)
|
||||||
worldedit.show_page(name, "worldedit_gui_pyramid")
|
worldedit.show_page(name, "worldedit_gui_pyramid")
|
||||||
if fields.worldedit_gui_pyramid_submit then
|
if fields.worldedit_gui_pyramid_submit_solid then
|
||||||
minetest.chatcommands["/pyramid"].func(name, string.format("%s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_nodename1[name]))
|
minetest.chatcommands["/pyramid"].func(name, string.format("%s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_nodename1[name]))
|
||||||
|
elseif fields.worldedit_gui_pyramid_submit_hollow then
|
||||||
|
minetest.chatcommands["/hollowpyramid"].func(name, string.format("%s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_nodename1[name]))
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -31,6 +31,7 @@ worldedit.alias_chatcommand("/hdo", "/hollowdome")
|
|||||||
worldedit.alias_chatcommand("/do", "/dome")
|
worldedit.alias_chatcommand("/do", "/dome")
|
||||||
worldedit.alias_chatcommand("/hcyl", "/hollowcylinder")
|
worldedit.alias_chatcommand("/hcyl", "/hollowcylinder")
|
||||||
worldedit.alias_chatcommand("/cyl", "/cylinder")
|
worldedit.alias_chatcommand("/cyl", "/cylinder")
|
||||||
|
worldedit.alias_chatcommand("/hpyr", "/hollowpyramid")
|
||||||
worldedit.alias_chatcommand("/pyr", "/pyramid")
|
worldedit.alias_chatcommand("/pyr", "/pyramid")
|
||||||
worldedit.alias_chatcommand("/spl", "/spiral")
|
worldedit.alias_chatcommand("/spl", "/spiral")
|
||||||
worldedit.alias_chatcommand("/m", "/move")
|
worldedit.alias_chatcommand("/m", "/move")
|
||||||
@ -47,4 +48,4 @@ worldedit.alias_chatcommand("/hlt", "/highlight")
|
|||||||
worldedit.alias_chatcommand("/rsr", "/restore")
|
worldedit.alias_chatcommand("/rsr", "/restore")
|
||||||
worldedit.alias_chatcommand("/l", "/lua")
|
worldedit.alias_chatcommand("/l", "/lua")
|
||||||
worldedit.alias_chatcommand("/lt", "/luatransform")
|
worldedit.alias_chatcommand("/lt", "/luatransform")
|
||||||
worldedit.alias_chatcommand("/clro", "/clearobjects")
|
worldedit.alias_chatcommand("/clro", "/clearobjects")
|
||||||
|
Loading…
Reference in New Issue
Block a user