mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-23 23:53:44 +01:00
wireframe corner
This commit is contained in:
parent
7f9c8796d0
commit
f7323afe10
32
worldeditadditions/lib/wireframe/corner_set.lua
Normal file
32
worldeditadditions/lib/wireframe/corner_set.lua
Normal file
@ -0,0 +1,32 @@
|
||||
-- ██████ ██████ ██████ ███ ██ ███████ ██████ ███████ ███████ ████████
|
||||
-- ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ██ ██ ██████ ██ ██ ██ █████ ██████ ███████ █████ ██
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██████ ██████ ██ ██ ██ ████ ███████ ██ ██ ███████ ███████ ██
|
||||
|
||||
--- Puts a node at each corner of selection box.
|
||||
-- @param {Position} pos1 The 1st position defining the WorldEdit selection
|
||||
-- @param {Position} pos2 The 2nd positioon defining the WorldEdit selection
|
||||
-- @param {string} node Name of the node to place
|
||||
function worldeditadditions.corner_set(pos1,pos2,node)
|
||||
local node_id_replace = minetest.get_content_id(node)
|
||||
|
||||
-- Fetch the nodes in the specified area
|
||||
local manip, area = worldedit.manip_helpers.init(pos1, pos2)
|
||||
local data = manip:get_data()
|
||||
|
||||
-- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array)
|
||||
local counts = { replaced = 0 }
|
||||
for k,z in pairs({pos1.z,pos2.z}) do
|
||||
for k,y in pairs({pos1.y,pos2.y}) do
|
||||
for k,x in pairs({pos1.x,pos2.x}) do
|
||||
data[area:index(x, y, z)] = node_id_replace
|
||||
counts.replaced = counts.replaced + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Save the modified nodes back to disk & return
|
||||
worldedit.manip_helpers.finish(manip, data)
|
||||
|
||||
return true, counts.replaced
|
||||
end
|
@ -0,0 +1,30 @@
|
||||
-- ██ ██ ██████ ██████ ██████ ███ ██ ███████ ██████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██
|
||||
-- ██ █ ██ ██ ██ ██ ██████ ██ ██ ██ █████ ██████
|
||||
-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ███ ███ ██████ ██████ ██ ██ ██ ████ ███████ ██ ██
|
||||
local wea = worldeditadditions
|
||||
worldedit.register_command("wcorner", {
|
||||
params = "<node>",
|
||||
description = "Set the corners of the current selection to <node>",
|
||||
privs = {worldedit=true},
|
||||
require_pos = 2,
|
||||
parse = function(param)
|
||||
local node = worldedit.normalize_nodename(param)
|
||||
if not node then
|
||||
return false, "invalid node name: " .. param
|
||||
end
|
||||
return true, node
|
||||
end,
|
||||
nodes_needed = function(name)
|
||||
local p1, p2, total = worldedit.pos1[name], worldedit.pos2[name], 1
|
||||
for k,v in pairs({"x","y","z"}) do
|
||||
if p1[v] ~= p2[v] then total = total*2 end
|
||||
end
|
||||
return total
|
||||
end,
|
||||
func = function(name, node)
|
||||
local _, count = wea.corner_set(worldedit.pos1[name], worldedit.pos2[name], node)
|
||||
return _, count .. " nodes set"
|
||||
end,
|
||||
})
|
Loading…
Reference in New Issue
Block a user