mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2025-01-10 06:47:31 +01:00
parent
e356f4521c
commit
870873ad15
@ -17,6 +17,7 @@ Many commands also have shorter names that can be typed faster. For example, if
|
|||||||
| `//s` | `//set` |
|
| `//s` | `//set` |
|
||||||
| `//r` | `//replace` |
|
| `//r` | `//replace` |
|
||||||
| `//ri` | `//replaceinverse` |
|
| `//ri` | `//replaceinverse` |
|
||||||
|
| `//hcube` | `//hollowcube` |
|
||||||
| `//hspr` | `//hollowsphere` |
|
| `//hspr` | `//hollowsphere` |
|
||||||
| `//spr` | `//sphere` |
|
| `//spr` | `//sphere` |
|
||||||
| `//hdo` | `//hollowdome` |
|
| `//hdo` | `//hollowdome` |
|
||||||
@ -143,6 +144,19 @@ Replace all nodes other than `<search node>` with `<replace node>` in the curren
|
|||||||
//replaceinverse dirt Bronze Block
|
//replaceinverse dirt Bronze Block
|
||||||
//replaceinverse mesecons:wire_00000000_off flowers:flower_tulip
|
//replaceinverse mesecons:wire_00000000_off flowers:flower_tulip
|
||||||
|
|
||||||
|
### `//hollowcube <width> <height> <length> <node>`
|
||||||
|
|
||||||
|
Adds a hollow cube with its ground level centered at WorldEdit position 1 with dimensions `<width>` x `<height>` x `<length>`, composed of `<node>`.
|
||||||
|
|
||||||
|
//hollowcube 6 5 6 Diamond Block
|
||||||
|
|
||||||
|
### `//cube <width> <height> <length> <node>`
|
||||||
|
|
||||||
|
Adds a cube with its ground level centered at WorldEdit position 1 with dimensions `<width>` x `<height>` x `<length>`, composed of `<node>`.
|
||||||
|
|
||||||
|
//cube 6 5 6 Diamond Block
|
||||||
|
//cube 7 2 1 default:cobble
|
||||||
|
|
||||||
### `//hollowsphere <radius> <node>`
|
### `//hollowsphere <radius> <node>`
|
||||||
|
|
||||||
Add hollow sphere centered at WorldEdit position 1 with radius `<radius>`, composed of `<node>`.
|
Add hollow sphere centered at WorldEdit position 1 with radius `<radius>`, composed of `<node>`.
|
||||||
|
@ -115,6 +115,12 @@ Primitives
|
|||||||
----------
|
----------
|
||||||
Contained in primitives.lua, this module allows the creation of several geometric primitives.
|
Contained in primitives.lua, this module allows the creation of several geometric primitives.
|
||||||
|
|
||||||
|
### count = worldedit.cube(pos, width, height, length, node_name, hollow)
|
||||||
|
|
||||||
|
Adds a cube with its ground level centered at `pos`, the dimensions `width` x `height` x `length`, composed of `node_name`.
|
||||||
|
|
||||||
|
Returns the number of nodes added.
|
||||||
|
|
||||||
### count = worldedit.sphere(pos, radius, node_name, hollow)
|
### count = worldedit.sphere(pos, radius, node_name, hollow)
|
||||||
|
|
||||||
Adds a sphere centered at `pos` with radius `radius`, composed of `node_name`.
|
Adds a sphere centered at `pos` with radius `radius`, composed of `node_name`.
|
||||||
|
@ -4,6 +4,47 @@
|
|||||||
local mh = worldedit.manip_helpers
|
local mh = worldedit.manip_helpers
|
||||||
|
|
||||||
|
|
||||||
|
--- Adds a cube
|
||||||
|
-- @param pos Position of ground level center of cube
|
||||||
|
-- @param width Cube width. (x)
|
||||||
|
-- @param height Cube height. (y)
|
||||||
|
-- @param length Cube length. (z)
|
||||||
|
-- @param node_name Name of node to make cube of.
|
||||||
|
-- @param hollow Whether the cube should be hollow.
|
||||||
|
-- @return The number of nodes added.
|
||||||
|
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)})
|
||||||
|
local manip, area = mh.init(basepos, vector.add(basepos, {x=width, y=height, z=length}))
|
||||||
|
local data = mh.get_empty_data(area)
|
||||||
|
|
||||||
|
-- Add cube
|
||||||
|
local node_id = minetest.get_content_id(node_name)
|
||||||
|
local stride = {x=1, y=area.ystride, z=area.zstride}
|
||||||
|
local offset = vector.subtract(basepos, area.MinEdge)
|
||||||
|
local count = 0
|
||||||
|
|
||||||
|
for z = 0, length-1 do
|
||||||
|
local index_z = (offset.z + z) * stride.z + 1 -- +1 for 1-based indexing
|
||||||
|
for y = 0, height-1 do
|
||||||
|
local index_y = index_z + (offset.y + y) * stride.y
|
||||||
|
for x = 0, width-1 do
|
||||||
|
local is_wall = z == 0 or z == length-1
|
||||||
|
or y == 0 or y == height-1
|
||||||
|
or x == 0 or x == width-1
|
||||||
|
if not hollow or is_wall then
|
||||||
|
local i = index_y + (offset.x + x)
|
||||||
|
data[i] = node_id
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
mh.finish(manip, data)
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
--- Adds a sphere of `node_name` centered at `pos`.
|
--- Adds a sphere of `node_name` centered at `pos`.
|
||||||
-- @param pos Position to center sphere at.
|
-- @param pos Position to center sphere at.
|
||||||
-- @param radius Sphere radius.
|
-- @param radius Sphere radius.
|
||||||
|
@ -455,6 +455,45 @@ minetest.register_chatcommand("/replaceinverse", {
|
|||||||
end, check_replace),
|
end, check_replace),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local check_cube = function(name, param)
|
||||||
|
if worldedit.pos1[name] == nil then
|
||||||
|
worldedit.player_notify(name, "no position 1 selected")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%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
|
||||||
|
return tonumber(w) * tonumber(h) * tonumber(l)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("/hollowcube", {
|
||||||
|
params = "<width> <height> <length> <node>",
|
||||||
|
description = "Add a hollow cube with its ground level centered at WorldEdit position 1 with dimensions <width> x <height> x <length>, composed of <node>.",
|
||||||
|
privs = {worldedit=true},
|
||||||
|
func = safe_region(function(name, param)
|
||||||
|
local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
|
||||||
|
local node = get_node(name, nodename)
|
||||||
|
local count = worldedit.cube(worldedit.pos1[name], tonumber(w), tonumber(h), tonumber(l), node, true)
|
||||||
|
worldedit.player_notify(name, count .. " nodes added")
|
||||||
|
end, check_cube),
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_chatcommand("/cube", {
|
||||||
|
params = "<width> <height> <length> <node>",
|
||||||
|
description = "Add a cube with its ground level centered at WorldEdit position 1 with dimensions <width> x <height> x <length>, composed of <node>.",
|
||||||
|
privs = {worldedit=true},
|
||||||
|
func = safe_region(function(name, param)
|
||||||
|
local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
|
||||||
|
local node = get_node(name, nodename)
|
||||||
|
local count = worldedit.cube(worldedit.pos1[name], tonumber(w), tonumber(h), tonumber(l), node)
|
||||||
|
worldedit.player_notify(name, count .. " nodes added")
|
||||||
|
end, check_cube),
|
||||||
|
})
|
||||||
|
|
||||||
local check_sphere = function(name, param)
|
local check_sphere = function(name, param)
|
||||||
if worldedit.pos1[name] == nil then
|
if worldedit.pos1[name] == nil then
|
||||||
worldedit.player_notify(name, "no position 1 selected")
|
worldedit.player_notify(name, "no position 1 selected")
|
||||||
|
@ -25,6 +25,7 @@ worldedit.alias_chatcommand("/v", "/volume")
|
|||||||
worldedit.alias_chatcommand("/s", "/set")
|
worldedit.alias_chatcommand("/s", "/set")
|
||||||
worldedit.alias_chatcommand("/r", "/replace")
|
worldedit.alias_chatcommand("/r", "/replace")
|
||||||
worldedit.alias_chatcommand("/ri", "/replaceinverse")
|
worldedit.alias_chatcommand("/ri", "/replaceinverse")
|
||||||
|
worldedit.alias_chatcommand("/hcube", "/hollowcube")
|
||||||
worldedit.alias_chatcommand("/hspr", "/hollowsphere")
|
worldedit.alias_chatcommand("/hspr", "/hollowsphere")
|
||||||
worldedit.alias_chatcommand("/spr", "/sphere")
|
worldedit.alias_chatcommand("/spr", "/sphere")
|
||||||
worldedit.alias_chatcommand("/hdo", "/hollowdome")
|
worldedit.alias_chatcommand("/hdo", "/hollowdome")
|
||||||
|
Loading…
Reference in New Issue
Block a user