mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2025-01-12 19:10:29 +01:00
Replace //homogenize with //replaceinverse (//homogenize x is equivalent to //replaceinverse air x), add documentation for it.
This commit is contained in:
parent
e2f1c4ef17
commit
7cf84045d4
@ -51,13 +51,22 @@ Set the current WorldEdit region to <node>.
|
|||||||
|
|
||||||
### //replace <search node> <replace node>
|
### //replace <search node> <replace node>
|
||||||
|
|
||||||
Replace all instances of <search node> with <place node> in the current WorldEdit region.
|
Replace all instances of <search node> with <replace node> in the current WorldEdit region.
|
||||||
|
|
||||||
//replace cobble stone
|
//replace cobble stone
|
||||||
//replace default:steelblock glass
|
//replace default:steelblock glass
|
||||||
//replace dirt flowers:flower_waterlily
|
//replace dirt flowers:flower_waterlily
|
||||||
//replace flowers:flower_rose flowers:flower_tulip
|
//replace flowers:flower_rose flowers:flower_tulip
|
||||||
|
|
||||||
|
### //replaceinverse <search node> <replace node>
|
||||||
|
|
||||||
|
Replace all nodes other than <search node> with <replace node> in the current WorldEdit region.
|
||||||
|
|
||||||
|
//replaceinverse air stone
|
||||||
|
//replaceinverse water_source default:dirt
|
||||||
|
//replaceinverse mesecons:mesecon air
|
||||||
|
//replaceinverse default:steelblock default:glass
|
||||||
|
|
||||||
### //hollowsphere <radius> <node>
|
### //hollowsphere <radius> <node>
|
||||||
|
|
||||||
Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>.
|
Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>.
|
||||||
|
@ -20,6 +20,12 @@ Replaces all instances of `searchnode` with `replacenode` in a region defined by
|
|||||||
|
|
||||||
Returns the number of nodes replaced.
|
Returns the number of nodes replaced.
|
||||||
|
|
||||||
|
### count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)
|
||||||
|
|
||||||
|
Replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.
|
||||||
|
|
||||||
|
Returns the number of nodes replaced.
|
||||||
|
|
||||||
### count = worldedit.copy(pos1, pos2, axis, amount)
|
### count = worldedit.copy(pos1, pos2, axis, amount)
|
||||||
|
|
||||||
Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.
|
Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.
|
||||||
|
@ -74,6 +74,37 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode)
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced
|
||||||
|
worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
local env = minetest.env
|
||||||
|
|
||||||
|
if minetest.registered_nodes[searchnode] == nil then
|
||||||
|
searchnode = "default:" .. searchnode
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos = {x=pos1.x, y=0, z=0}
|
||||||
|
local node = {name=replacenode}
|
||||||
|
local count = 0
|
||||||
|
while pos.x <= pos2.x do
|
||||||
|
pos.y = pos1.y
|
||||||
|
while pos.y <= pos2.y do
|
||||||
|
pos.z = pos1.z
|
||||||
|
while pos.z <= pos2.z do
|
||||||
|
local name = env:get_node(pos).name
|
||||||
|
if name ~= "ignore" and name ~= searchnode then
|
||||||
|
env:add_node(pos, node)
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
pos.z = pos.z + 1
|
||||||
|
end
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
end
|
||||||
|
pos.x = pos.x + 1
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied
|
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied
|
||||||
worldedit.copy = function(pos1, pos2, axis, amount)
|
worldedit.copy = function(pos1, pos2, axis, amount)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
@ -197,9 +197,9 @@ minetest.register_chatcommand("/replace", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("/homogenize", {
|
minetest.register_chatcommand("/replaceinverse", {
|
||||||
params = "<node>",
|
params = "<search node> <replace node>",
|
||||||
description = "Replace all non-air nodes with <node> in the current WorldEdit region",
|
description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",
|
||||||
privs = {worldedit=true},
|
privs = {worldedit=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||||
@ -208,13 +208,22 @@ minetest.register_chatcommand("/homogenize", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if not worldedit.node_is_valid(param) then
|
local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")
|
||||||
minetest.chat_send_player(name, "Invalid node name: " .. param)
|
if found == nil then
|
||||||
|
minetest.chat_send_player(name, "Invalid usage: " .. param)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not worldedit.node_is_valid(searchnode) then
|
||||||
|
minetest.chat_send_player(name, "Invalid search node name: " .. searchnode)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not worldedit.node_is_valid(replacenode) then
|
||||||
|
minetest.chat_send_player(name, "Invalid replace node name: " .. replacenode)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local count = worldedit.homogenize(pos1, pos2, param)
|
local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)
|
||||||
minetest.chat_send_player(name, count .. " nodes homogenized")
|
minetest.chat_send_player(name, count .. " nodes replaced")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user