-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
84 lines (73 loc) · 2.39 KB
/
init.lua
File metadata and controls
84 lines (73 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
local fill = {}
local pos1 = {}
local pos2 = {}
local selected_node = {}
local function sort_pos(p1, p2)
return {
x = math.min(p1.x, p2.x),
y = math.min(p1.y, p2.y),
z = math.min(p1.z, p2.z)
},
{
x = math.max(p1.x, p2.x),
y = math.max(p1.y, p2.y),
z = math.max(p1.z, p2.z)
}
end
minetest.register_chatcommand("pos1", {
privs = {server=true},
func = function(name)
local player = minetest.get_player_by_name(name)
if not player then return end
pos1[name] = vector.round(player:get_pos())
return true, "Position 1 set to "..minetest.pos_to_string(pos1[name])
end
})
minetest.register_chatcommand("pos2", {
privs = {server=true},
func = function(name)
local player = minetest.get_player_by_name(name)
if not player then return end
pos2[name] = vector.round(player:get_pos())
return true, "Position 2 set to "..minetest.pos_to_string(pos2[name])
end
})
minetest.register_chatcommand("setnode", {
privs = {server=true},
func = function(name)
local player = minetest.get_player_by_name(name)
if not player then return end
local item = player:get_wielded_item()
if item:is_empty() then
return false, "Hold a node in your hand."
end
selected_node[name] = item:get_name()
return true, "Selected node: "..selected_node[name]
end
})
minetest.register_chatcommand("fill", {
description = "Fill selected area",
privs = {server=true},
func = function(name)
if not pos1[name] or not pos2[name] then
return false, "Set pos1 and pos2 first."
end
if not selected_node[name] then
return false, "Use /setnode first."
end
local p1, p2 = sort_pos(pos1[name], pos2[name])
local count = 0
for x = p1.x, p2.x do
for y = p1.y, p2.y do
for z = p1.z, p2.z do
local current_node = minetest.get_node({x=x,y=y,z=z})
if current_node.name ~= "air" and not current_node.name:find("water") then
minetest.set_node({x=x,y=y,z=z}, {name=selected_node[name]})
count = count + 1
end
end
end
end
return true, "Filled "..count.." nodes with "..selected_node[name]
end
})