forked from wintersknight94/NodeCore-Additions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sierpinski.lua
131 lines (125 loc) · 3.78 KB
/
sierpinski.lua
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore, pairs, vector
= minetest, nodecore, pairs, vector
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
------------------------------------------------------------------------
local carpetdirs = {
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1}
}
local carpetwet = modname .. ":carpet_wet"
------------------------------------------------------------------------
local function findwater(pos)
return nodecore.find_nodes_around(pos, "group:water")
end
local function soakup(pos)
local any
for _, p in pairs(findwater(pos)) do
nodecore.node_sound(p, "dig")
minetest.remove_node(p)
any = true
end
return any
end
------------------------------------------------------------------------
minetest.register_abm({
label = "carpet wet",
interval = 1,
chance = 10,
nodenames = {modname .. ":carpet"},
neighbors = {"group:water"},
action = function(pos)
if soakup(pos) then
nodecore.set_loud(pos, {name = modname .. ":carpet_wet"})
return nodecore.fallcheck(pos)
end
end
})
nodecore.register_aism({
label = "carpet stack wet",
interval = 1,
chance = 10,
itemnames = {modname .. ":carpet"},
action = function(stack, data)
if data.pos and soakup(data.pos) then
local taken = stack:take_item(1)
taken:set_name(modname .. ":carpet_wet")
if data.inv then taken = data.inv:add_item("main", taken) end
if not taken:is_empty() then nodecore.item_eject(data.pos, taken) end
return stack
end
end
})
minetest.register_abm({
label = "carpet sun dry",
interval = 1,
chance = 100,
nodenames = {modname .. ":carpet_wet"},
arealoaded = 1,
action = function(pos)
local above = {x = pos.x, y = pos.y + 1, z = pos.z}
if nodecore.is_full_sun(above) and #findwater(pos) < 1 then
nodecore.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = pos})
return minetest.set_node(pos, {name = modname .. ":carpet"})
end
end
})
nodecore.register_aism({
label = "carpet stack sun dry",
interval = 1,
chance = 100,
arealoaded = 1,
itemnames = {modname .. ":carpet_wet"},
action = function(stack, data)
if data.player and (data.list ~= "main"
or data.slot ~= data.player:get_wield_index()) then return end
if data.pos and nodecore.is_full_sun(data.pos)
and #findwater(data.pos) < 1 then
nodecore.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = data.pos})
local taken = stack:take_item(1)
taken:set_name(modname .. ":carpet")
if data.inv then taken = data.inv:add_item("main", taken) end
if not taken:is_empty() then nodecore.item_eject(data.pos, taken) end
return stack
end
end
})
minetest.register_abm({
label = "carpet fire dry",
interval = 1,
chance = 20,
nodenames = {modname .. ":carpet_wet"},
neighbors = {"group:igniter"},
action = function(pos)
nodecore.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = pos})
return minetest.set_node(pos, {name = modname .. ":carpet"})
end
})
------------------------------------------------------------------------
nodecore.register_craft({
label = "squeeze carpet",
action = "pummel",
toolgroups = {thumpy = 1},
indexkeys = {carpetwet},
nodes = {
{
match = carpetwet
}
},
after = function(pos)
local found
for _, d in pairs(carpetdirs) do
local p = vector.add(pos, d)
if nodecore.artificial_water(p, {
matchpos = pos,
match = spongewet,
minttl = 1,
maxttl = 10
}) then found = true end
end
if found then nodecore.node_sound(pos, "dig") end
end
})