diff options
author | sfan5 <sfan5@live.de> | 2016-10-13 17:51:01 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2016-10-13 17:51:01 +0200 |
commit | 6e2e2385e90ddc74ad68d129fbb7a94d6ee53a7f (patch) | |
tree | 824560648f64df53234e61087eee7448cbd01df5 | |
parent | 152707a32243cf33fb0f4ff740147d0cb268246b (diff) | |
parent | 5f9efb1205fe9802f859548fc9220f98dd0fd12e (diff) |
Merge remote-tracking branch 'tmp/hollowpyramid'
-rw-r--r-- | ChatCommands.md | 12 | ||||
-rw-r--r-- | WorldEdit API.md | 4 | ||||
-rw-r--r-- | worldedit/primitives.lua | 9 | ||||
-rw-r--r-- | worldedit_commands/init.lua | 50 | ||||
-rw-r--r-- | worldedit_gui/functionality.lua | 9 | ||||
-rw-r--r-- | worldedit_shortcommands/init.lua | 3 |
6 files changed, 62 insertions, 25 deletions
diff --git a/ChatCommands.md b/ChatCommands.md index b26e894..be885c0 100644 --- a/ChatCommands.md +++ b/ChatCommands.md @@ -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>`.
diff --git a/WorldEdit API.md b/WorldEdit API.md index 7b99c8b..5867dfc 100644 --- a/WorldEdit API.md +++ b/WorldEdit API.md @@ -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.
diff --git a/worldedit/primitives.lua b/worldedit/primitives.lua index 962a02f..fe22fff 100644 --- a/worldedit/primitives.lua +++ b/worldedit/primitives.lua @@ -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]
- 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
- count = count + (size * 2 + 1) ^ 2
size = size - 1
end
diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index f3a57a3..b9313cc 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -517,9 +517,25 @@ minetest.register_chatcommand("/cylinder", { end, check_cylinder),
})
-minetest.register_chatcommand("/pyramid", {
+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 pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <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+(.+)$")
@@ -529,24 +545,26 @@ minetest.register_chatcommand("/pyramid", { height = height * sign
end
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, true)
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
+ 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>",
+ privs = {worldedit=true},
+ func = safe_region(function(name, param)
local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")
- if found == nil then
- worldedit.player_notify(name, "invalid usage: " .. param)
- return nil
+ height = tonumber(height)
+ if axis == "?" then
+ axis, sign = worldedit.player_axis(name)
+ height = height * sign
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),
+ local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)
+ worldedit.player_notify(name, count .. " nodes added")
+ end, check_pyramid),
})
minetest.register_chatcommand("/spiral", {
diff --git a/worldedit_gui/functionality.lua b/worldedit_gui/functionality.lua index 535c5ce..7010b14 100644 --- a/worldedit_gui/functionality.lua +++ b/worldedit_gui/functionality.lua @@ -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
diff --git a/worldedit_shortcommands/init.lua b/worldedit_shortcommands/init.lua index a3cbb67..a4350ae 100644 --- a/worldedit_shortcommands/init.lua +++ b/worldedit_shortcommands/init.lua @@ -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")
@@ -47,4 +48,4 @@ worldedit.alias_chatcommand("/hlt", "/highlight") worldedit.alias_chatcommand("/rsr", "/restore")
worldedit.alias_chatcommand("/l", "/lua")
worldedit.alias_chatcommand("/lt", "/luatransform")
-worldedit.alias_chatcommand("/clro", "/clearobjects")
\ No newline at end of file +worldedit.alias_chatcommand("/clro", "/clearobjects")
|