1
2
3
4
5
6
7
8
..
14
15
16
17
18
19
20
21
|
return {
purge_container = function(pos,node,meta,user)
local offset = function(pos,range)
local r = function(min,max)
return (math.random() * (max - min)) + min
end
return {
x = pos.x + r(0 - range, range);
................................................................................
for _, item in pairs(inv) do
if not item:is_empty() then
minetest.add_item(offset(pos,0.4), item)
end
end
end
end;
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
..
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
85
86
87
88
89
90
91
92
93
94
95
|
local ofs = {
neighbors = {
{x = 1, y = 0, z = 0};
{x = -1, y = 0, z = 0};
{x = 0, y = 1, z = 0};
{x = 0, y = -1, z = 0};
{x = 0, y = 0, z = 1};
{x = 0, y = 0, z = -1};
};
planecorners = {
{x = 1, y = 0, z = 1};
{x = -1, y = 0, z = 1};
{x = -1, y = 0, z = -1};
{x = 1, y = 0, z = -1};
{x = 1, y = 1, z = 0};
{x = -1, y = 1, z = 0};
{x = -1, y = -1, z = 0};
{x = 1, y = -1, z = 0};
};
cubecorners = {
{x = 1, y = 1, z = 1};
{x = -1, y = 1, z = 1};
{x = -1, y = -1, z = 1};
{x = -1, y = -1, z = -1};
{x = 1, y = -1, z = -1};
{x = 1, y = 1, z = -1};
{x = 1, y = -1, z = 1};
{x = -1, y = 1, z = -1};
};
nextto = {
{x = 1, y = 0, z = 0};
{x = -1, y = 0, z = 0};
{x = 0, y = 0, z = 1};
{x = 0, y = 0, z = -1};
};
}
ofs.adjoining = sorcery.lib.tbl.append(sorcery.lib.tbl.append(
ofs.neighbors,ofs.planecorners),ofs.cubecorners)
return {
offsets = ofs;
purge_container = function(pos,node,meta,user)
local offset = function(pos,range)
local r = function(min,max)
return (math.random() * (max - min)) + min
end
return {
x = pos.x + r(0 - range, range);
................................................................................
for _, item in pairs(inv) do
if not item:is_empty() then
minetest.add_item(offset(pos,0.4), item)
end
end
end
end;
amass = function(startpoint,names,directions)
if not directions then directions = ofs.neighbors end
local nodes, positions, checked = {},{},{}
local checkedp = function(pos)
for _,v in pairs(checked) do
if vector.equals(pos,v) then return true end
end
return false
end
local i,stack = 1,{startpoint} repeat
local pos = stack[i]
local n = minetest.get_node(pos).name
if sorcery.lib.tbl.has(names, n) then -- match found
-- record the find
nodes[pos] = n
if positions[n] then positions[n][#positions[n]] = pos
else positions[n] = {pos} end
-- check selected neighbors to see if any need scanning
for _,d in pairs(directions) do
local sum = vector.add(pos, d)
if not checkedp(sum) then
stack[#stack + 1] = sum
end
end
end
checked[#checked+1] = pos
i = i + 1
until i > #stack
return nodes, positions
end;
}
|