Merge remote-tracking branch 'tmp/hollowpyramid'

This commit is contained in:
sfan5 2016-10-13 17:51:01 +02:00
commit 6e2e2385e9
6 changed files with 62 additions and 25 deletions

View File

@ -22,6 +22,9 @@ Many commands also have shorter names that can be typed faster. For example, if
| `//hdo` | `//hollowdome` |
| `//do` | `//dome` |
| `//hcyl` | `//hollowcylinder` |
| `//cyl` | `//cylinder` |
| `//hpyr` | `//hollowpyramid` |
| `//pyr` | `//pyramid` |
### `//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 ? 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>`
Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height `<height>`, composed of `<node>`.

View File

@ -133,9 +133,9 @@ Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `
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.

View File

@ -150,8 +150,9 @@ end
-- @param axis Axis ("x", "y", or "z")
-- @param height Pyramid height.
-- @param node_name Name of node to make pyramid of.
-- @param hollow Whether the pyramid should be hollow.
-- @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)
-- 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]
for index3 = -size, size do
local i = new_index2 + (index3 + offset[other2]) * stride[other2]
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
count = count + (size * 2 + 1) ^ 2
size = size - 1
end

View File

@ -517,6 +517,39 @@ minetest.register_chatcommand("/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", {
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>",
@ -531,22 +564,7 @@ minetest.register_chatcommand("/pyramid", {
local node = get_node(name, nodename)
local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)
worldedit.player_notify(name, count .. " nodes added")
end,
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),
end, check_pyramid),
})
minetest.register_chatcommand("/spiral", {

View File

@ -300,18 +300,21 @@ worldedit.register_gui_function("worldedit_gui_pyramid", {
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("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,
})
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_axis1[name] = axis_indices[fields.worldedit_gui_pyramid_axis]
gui_distance1[name] = tostring(fields.worldedit_gui_pyramid_length)
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]))
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
return true
end

View File

@ -31,6 +31,7 @@ worldedit.alias_chatcommand("/hdo", "/hollowdome")
worldedit.alias_chatcommand("/do", "/dome")
worldedit.alias_chatcommand("/hcyl", "/hollowcylinder")
worldedit.alias_chatcommand("/cyl", "/cylinder")
worldedit.alias_chatcommand("/hpyr", "/hollowpyramid")
worldedit.alias_chatcommand("/pyr", "/pyramid")
worldedit.alias_chatcommand("/spl", "/spiral")
worldedit.alias_chatcommand("/m", "/move")