forked from stujones11/clothing
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdirty_water.lua
171 lines (161 loc) · 4.38 KB
/
dirty_water.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
local S = clothing.translator;
minetest.register_node("clothing:dirty_water_source", {
description = S("Dirty water source"),
drawtype = "liquid",
waving = 3,
tiles = {
{
name = "clothing_dirty_water_source_animated.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 2.0,
},
},
{
name = "clothing_dirty_water_source_animated.png",
backface_culling = true,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 2.0,
},
},
},
use_texture_alpha = "blend",
paramtype = "light",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 2,
liquidtype = "source",
liquid_alternative_flowing = "clothing:dirty_water_flowing",
liquid_alternative_source = "clothing:dirty_water_source",
liquid_viscosity = 1,
post_effect_color = {a = 225, r = 80, g = 65, b = 51},
groups = {liquid = 3, cools_lava = 1},
sounds = default.node_sound_water_defaults(),
})
minetest.register_node("clothing:dirty_water_flowing", {
description = S("Flowing dirty water"),
drawtype = "flowingliquid",
waving = 3,
tiles = {"clothing_dirty_water.png"},
special_tiles = {
{
name = "clothing_dirty_water_flowing_animated.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.5,
},
},
{
name = "clothing_dirty_water_flowing_animated.png",
backface_culling = true,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 0.5,
},
},
},
use_texture_alpha = "blend",
paramtype = "light",
paramtype2 = "flowingliquid",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
is_ground_content = false,
drop = "",
drowning = 2,
liquidtype = "flowing",
liquid_alternative_flowing = "clothing:dirty_water_flowing",
liquid_alternative_source = "clothing:dirty_water_source",
liquid_viscosity = 1,
post_effect_color = {a = 225, r = 80, g = 65, b = 51},
groups = {liquid = 3, not_in_creative_inventory = 1,
cools_lava = 1},
sounds = default.node_sound_water_defaults(),
})
bucket.register_liquid(
"clothing:dirty_water_source",
"clothing:dirty_water_flowing",
"clothing:bucket_dirty_water",
"clothing_bucket_dirty_water.png",
S("Dirty water bucket").."\n"..
S("Put dirty water on gravel and wait for cleaning it."),
{tool = 1}
)
minetest.register_abm({
label = "Cleaning dirty water by gravel",
nodenames = {"clothing:dirty_water_source"},
neighbors = {"default:gravel"},
interval = 30,
chance = 60, -- etc 1800 sconds to clean 60 dirty water near gravel
action = function(pos, node)
node.name = "default:river_water_source";
local near = minetest.find_node_near(pos, 2, "group:water");
if near then
near = minetest.get_node(near);
node.name = minetest.registered_nodes[near.name].liquid_alternative_source;
end
minetest.set_node(pos, node);
end,
});
local random_gen = PcgRandom(os.clock())
local function mixing_water(pos, node)
local pos1 = {x=pos.x-1,y=pos.y-1,z=pos.z-1};
local pos2 = {x=pos.x+1,y=pos.y+1,z=pos.z+1};
local look_for = {"clothing:dirty_water_source","default:water_source","default:river_water_source"};
local finds = minetest.find_nodes_in_area(pos1, pos2, look_for, true);
local sum = 0;
local nodes = {};
for key, found in pairs(finds) do
nodes[key] = table.getn(found);
sum = sum + nodes[key];
end
local num = sum;
if (sum>1) then
num = random_gen:next(1,sum);
end
--local num = random_gen:next(1,27)-27+sum;
if (num>1) then
for key,number in pairs(nodes) do
if (num<=number) then
if (node.name ~= key) then
node.name = key;
minetest.set_node(pos, node);
end
break;
end
num = num - number;
end
end
end
minetest.register_abm({
label = "Mixing dirty water and water",
nodenames = {"clothing:dirty_water_source"},
neighbors = {"default:water_source", "default:river_water_source"},
interval = 5,
chance = 5,
action = mixing_water,
});
minetest.register_abm({
label = "Mixing water and dirty water",
nodenames = {"default:water_source", "default:river_water_source"},
neighbors = {"clothing:dirty_water_source"},
interval = 5,
chance = 5,
action = mixing_water,
});