2 pedology
.wetnames
= {[0] = "dry", "wet", "watery", "sludgy", "muddy", "slurry" }
4 dofile(minetest
.get_modpath("pedology").."/settings.lua")
6 if pedology
.USE_DRIPS
== true then
7 dofile(minetest
.get_modpath("pedology").."/drip.lua")
12 function pedology
.ooze(pos
, node
, active_object_count
, active_object_wider
)
13 local wet
= minetest
.get_item_group(node
.name
, "wet")
14 if wet
== 0 then return end
16 --[[ This table contain the nodes which are either neighbors
17 of node or which touch the node at an edge or corner and which are
18 not on a heigher y-level than
22 { -- neighbor directly below
23 {x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
},
27 { -- touching the lower sides
28 {x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
-1},
29 {x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
+1},
30 {x
=pos
.x
-1, y
=pos
.y
-1, z
=pos
.z
},
31 {x
=pos
.x
+1, y
=pos
.y
-1, z
=pos
.z
},
34 { -- touching the lower corners
35 {x
=pos
.x
-1, y
=pos
.y
-1, z
=pos
.z
-1},
36 {x
=pos
.x
-1, y
=pos
.y
-1, z
=pos
.z
+1},
37 {x
=pos
.x
-1, y
=pos
.y
-1, z
=pos
.z
-1},
38 {x
=pos
.x
+1, y
=pos
.y
-1, z
=pos
.z
+1},
39 {x
=pos
.x
+1, y
=pos
.y
-1, z
=pos
.z
+1},
42 { -- sides on the same level
43 {x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
}, -- left
44 {x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
}, -- right
45 {x
=pos
.x
, y
=pos
.y
, z
=pos
.z
-1}, -- before
46 {x
=pos
.x
, y
=pos
.y
, z
=pos
.z
+1}, -- behind
49 { -- touching at the side on the same level
50 {x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
-1},
51 {x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
+1},
52 {x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
-1},
53 {x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
+1},
59 for j
=1,#neighbors
[i
] do
60 local node
= minetest
.get_node(neighbors
[i
][j
])
61 local name
= node
.name
62 local destwet
= minetest
.get_item_group(name
, "wet")
65 (minetest
.get_item_group(name
, "sucky") >= 1)) and
66 (neighbors
[i
].minwet
<= (wet
- destwet
)) then
67 pedology
.wetten(neighbors
[i
][j
])
75 --[[ This is an ABM action which wettens the node iff many water nodes
76 are neighbors of it or touching it at an edge or corner.]]
77 function pedology
.suck(pos
, node
, active_object_count
, active_object_wider
)
78 local wet
= minetest
.get_item_group(node
.name
, "wet")
82 -- These three tables contain the positions of all nodes around node
85 {x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
}, -- below
86 {x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
}, -- left
87 {x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
}, -- right
88 {x
=pos
.x
, y
=pos
.y
+1, z
=pos
.z
}, -- above
89 {x
=pos
.x
, y
=pos
.y
, z
=pos
.z
-1}, -- before
90 {x
=pos
.x
, y
=pos
.y
, z
=pos
.z
+1}, -- behind
94 {x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
-1},
95 {x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
+1},
96 {x
=pos
.x
, y
=pos
.y
+1, z
=pos
.z
-1},
97 {x
=pos
.x
, y
=pos
.y
+1, z
=pos
.z
+1},
98 {x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
-1},
99 {x
=pos
.x
-1, y
=pos
.y
, z
=pos
.z
+1},
100 {x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
-1},
101 {x
=pos
.x
+1, y
=pos
.y
, z
=pos
.z
+1},
102 {x
=pos
.x
-1, y
=pos
.y
-1, z
=pos
.z
},
103 {x
=pos
.x
-1, y
=pos
.y
+1, z
=pos
.z
},
104 {x
=pos
.x
+1, y
=pos
.y
-1, z
=pos
.z
},
105 {x
=pos
.x
+1, y
=pos
.y
+1, z
=pos
.z
},
109 {x
=pos
.x
-1, y
=pos
.y
-1, z
=pos
.z
-1},
110 {x
=pos
.x
-1, y
=pos
.y
-1, z
=pos
.z
+1},
111 {x
=pos
.x
-1, y
=pos
.y
+1, z
=pos
.z
-1},
112 {x
=pos
.x
-1, y
=pos
.y
+1, z
=pos
.z
+1},
113 {x
=pos
.x
-1, y
=pos
.y
-1, z
=pos
.z
-1},
114 {x
=pos
.x
+1, y
=pos
.y
+1, z
=pos
.z
+1},
115 {x
=pos
.x
+1, y
=pos
.y
+1, z
=pos
.z
-1},
116 {x
=pos
.x
+1, y
=pos
.y
-1, z
=pos
.z
+1},
117 {x
=pos
.x
+1, y
=pos
.y
-1, z
=pos
.z
+1},
122 for i
=1,#neighbors
do
123 for j
=1,#neighbors
[i
] do
124 local neighbor
= minetest
.get_node(neighbors
[i
][j
])
125 local name
= neighbor
.name
126 local water
= minetest
.get_item_group(name
, "water")
128 score
= score
+ neighbors
[i
].rating
134 if(wet
== 0 and score
>= 1) then
136 elseif(wet
== 1 and score
>= 2) then
138 elseif(wet
== 2 and score
>= 3) then
140 elseif(wet
== 3 and score
>= 5) then
142 elseif(wet
== 4 and score
>= 8) then
144 elseif(wet
== 5 and score
>= 11) then
145 -- erosion: turn node into water
146 -- TODO: Also drop the drops
147 minetest
.set_node(pos
, {name
="pedology:water_fresh_source"})
151 if(wetten
==true) then
156 --[[ ABM action which dries out a node when it is in direct sunlight ]]
157 function pedology
.sun_dry(pos
, node
, active_object_count
, active_object_wider
)
158 if(minetest
.get_item_group(node
.name
, "wet") < 6) then
159 -- don’t dry off if there is water nearby
160 if(not minetest
.find_node_near(pos
, 1, {"group:water"})) then
161 local light
= minetest
.get_node_light(pos
, minetest
.get_timeofday())
162 if light
>= pedology
.DRY_LIGHT
then
171 --[[ air and vacuum]]
172 minetest
.register_node("pedology:vacuum", {
173 description
= "vacuum",
174 inventory_image
="unknown_node.png",
175 wield_image
="unknown_node.png",
180 sunlight_propagates
=true,
185 groups
={not_in_creative_inventory
=1}
188 minetest
.register_node("pedology:thinair2", {
189 description
= "very thin air",
190 inventory_image
="unknown_node.png",
191 wield_image
="unknown_node.png",
194 sunlight_propagates
=true,
199 groups
={not_in_creative_inventory
=1}
202 minetest
.register_node("pedology:thinair1", {
203 description
= "thin air",
204 inventory_image
="unknown_node.png",
205 wield_image
="unknown_node.png",
208 sunlight_propagates
=true,
213 groups
={not_in_creative_inventory
=1}
218 function pedology
.register_liquid(basename
, description
, alpha
, viscosity
, drowning
, damage_per_second
, post_effect_color
, additional_groups
)
219 flowing_groups
= {wet
=6,not_in_creative_inventory
=1}
220 source_groups
= {wet
=6}
221 for k
,v
in pairs(additional_groups
) do
222 flowing_groups
[k
] = v
226 local tile
= "pedology_"..basename
..".png"
227 local nodedef_source
= {
228 description
= description
.." source",
229 inventory_image
= minetest
.inventorycube(tile
),
238 liquid_alternative_flowing
= "pedology:"..basename
.."_flowing",
239 liquid_alternative_source
= "pedology:"..basename
.."_source",
240 liquid_viscosity
= viscosity
,
241 post_effect_color
= post_effect_color
,
243 damage_per_second
= damage_per_second
,
246 liquidtype
= "source",
247 groups
= source_groups
,
249 minetest
.register_node("pedology:"..basename
.."_source", nodedef_source
)
251 local nodedef_flowing
= {
252 description
= description
.." flowing",
253 inventory_image
= minetest
.inventorycube(tile
),
262 liquid_alternative_flowing
= "pedology:"..basename
.."_flowing",
263 liquid_alternative_source
= "pedology:"..basename
.."_source",
264 liquid_viscosity
= viscosity
,
265 post_effect_color
= post_effect_color
,
267 damage_per_second
= damage_per_second
,
269 drawtype
= "flowingliquid",
270 liquidtype
= "flowing",
271 groups
= flowing_groups
,
272 paramtype2
= "flowingliquid",
275 minetest
.register_node("pedology:"..basename
.."_flowing", nodedef_flowing
)
279 pedology
.register_liquid("water_fresh", "freshwater", 100, 1, 2, 0, {a
=60, r
=100, b
=200, g
=100}, {water
=1})
280 --pedology.register_liquid("water_salt", "salt water", 180, 2, 4, 0, {a=80, r=120, b=200, g=120}, {water=1})
281 pedology
.register_liquid("water_ponding", "ponding water", 234, 4, 3, 0, {a
=128, r
=85, g
=85, g
=60}, {water
=1})
284 TODO: Decide wheather to keep or to remove lava
285 pedology.register_liquid("lava_1", "very hot lava", 230, 2, 10, 8, {a=230, r=255, g=0, b=0}, {hot=6000, lava=1})
286 pedology.register_liquid("lava_2", "hot lava", 230, 3, 9, 7, {a=230, r=255, g=0, b=0}, {hot=5000, lava=1})
287 pedology.register_liquid("lava_3", "lava", 230, 4, 8, 6, {a=230, r=255, g=0, b=0}, {hot=4000, lava=1})
288 pedology.register_liquid("lava_4", "cold lava", 230, 5, 7, 6, {a=230, r=255, g=0, b=0}, {hot=3000, lava=1})
291 --[[ register a sucky/oozing node to this mod ]]
292 function pedology
.register_sucky(basename
, description
, wetness
, oozing
, sucky
, melting_point
, dropcount
, sounds
, additional_groups
)
293 local wetname
= basename
.."_"..tostring(wetness
)
295 local groups
= { sucky
=sucky
, oozing
=oozing
, wet
=wetness
, melting_point
=melting_point
, not_in_creative_inventory
= noncreative
, [basename
]=1 }
296 if additional_groups
~= nil then
297 for k
,v
in pairs(additional_groups
) do
302 local name
= "pedology:"..wetname
304 if(dropcount
> 0) then
305 itemname
= "pedology:"..basename
.."_lump"
306 drop
= itemname
.. " " .. tostring(dropcount
)
311 -- If the node is not dry, do not add it into the creative inventory
312 if wetness
== 0 then noncreative
= 0 else noncreative
= 1 end
314 description
= description
,
315 inventory_image
= minetest
.inventorycube("pedology_"..wetname
..".png"),
316 tiles
= {"pedology_"..wetname
..".png"},
322 minetest
.register_node(name
, nodedef
)
327 This function registers a couple of sucky/oozing nodes, including all their “wet” variants.
328 It also registers an ABM.
331 basename: The internal name piece from which the concrete basenames will be build. The wetness level will be appended.
332 basedescription. The description of the nodes. A proper wetness adjective (“dry”, “wet”, …) will be prepended.
333 lumpdescription. The description component of the “lump” of the node. If nil, no lump is used
334 maxwet: The maximum wetness level of this node group (minimum: 0, maximum: 5)
335 oozeinterval: The interval in seconds in which it the node may ooze. the Minimal value: 1
336 oozechance: The inverted chance (1/x) to ooze
337 melttable: Table of melting_point values for each wetness level
338 dropcount: How many lumps nodes of this group drop. If 0, the nodes simply drop themselves (not recommended!)
339 sounds: Sound specification for all nodes
340 additional_groups: table of additional groups of all the nodes. May be empty or nil (meaning no additional groups).
342 function pedology
.register_sucky_group(basename
, basedescription
, lumpdescription
, maxwet
, oozeinterval
, oozechance
, melttable
, dropcount
, sounds
, additional_groups
)
343 local oozing
, dripinterval
344 local m
-- melting_point
346 -- Register drops (if available)
347 if(dropcount
> 0) then
349 description
= lumpdescription
,
350 inventory_image
= "pedology_lump_"..basename
..".png"
352 minetest
.register_craftitem("pedology:"..basename
.."_lump", itemdef
)
356 if(w
==0) then oozing
=0 else oozing
=1 end
357 if (w
==maxwet
and w
~= 5) then sucky
=0 else sucky
=1 end
358 if melttable
== nil then m
= 0 else m
= melttable
[w
] end
359 pedology
.register_sucky(basename
, (pedology
.wetnames
[w
]).." "..basedescription
, w
, oozing
, sucky
, m
, dropcount
, sounds
, additional_groups
)
361 if(w
>0 and pedology
.USE_DRIPS
== true) then
362 minetest
.register_abm({
363 nodenames
= {"pedology:"..basename
.."_"..tostring(w
)},
365 interval
= math
.max(oozeinterval
/4,2),
366 chance
= math
.max(oozechance
,22),
367 action
= pedology
.create_drip
,
372 minetest
.register_abm({
373 nodenames
= {"group:"..basename
},
374 neighbors
= {"group:sucky"},
375 interval
= oozeinterval
,
377 action
= pedology
.ooze
,
385 local sound_clay
= {footstep
= {name
="pedology_clay_footstep", gain
=0.5}}
386 local sound_silt_fine
= {footstep
= {name
="pedology_silt_footstep", gain
=0.3}}
387 local sound_silt_medium
= {footstep
= {name
="pedology_silt_footstep", gain
=0.35}}
388 local sound_silt_coarse
= {footstep
= {name
="pedology_silt_footstep", gain
=0.4}}
389 local sound_sand_fine
= {footstep
= {name
="pedology_sand_footstep", gain
=0.2}}
390 local sound_sand_medium
= {footstep
= {name
="pedology_sand_footstep", gain
=0.25}}
391 local sound_sand_coarse
= {footstep
= {name
="pedology_sand_footstep", gain
=0.3}}
392 local sound_gravel_fine
= {footstep
= {name
="pedology_gravel_footstep", gain
=1}}
393 local sound_gravel_medium
= {footstep
= {name
="pedology_gravel_footstep", gain
=1}}
394 local sound_gravel_coarse
= {footstep
= {name
="pedology_gravel_footstep", gain
=1}}
396 --[[ register sucky and oozing nodes ]]
398 pedology
.register_sucky_group("clay", "clay", "clay lump",
399 5, 60, 1.25, {3000, 3100, 3200, 3500, 3550, 3600}, 4, sound_clay
, { crumbly
= 3, sun_dry
= 1})
400 pedology
.register_sucky_group("silt_fine", "fine silt", "fine silt lump",
401 5, 45, 1.25, {2800, 2900, 3000, 3100, 3200, 3300}, 4, sound_silt_fine
, { crumbly
= 3, sun_dry
= 1 })
402 pedology
.register_sucky_group("silt_medium", "medium silt", "medium silt lump",
403 4, 30, 1.25, {2600, 2800, 3200, 3800, 4200}, 4, sound_silt_medium
, { crumbly
= 3, sun_dry
= 1 })
404 pedology
.register_sucky_group("silt_coarse", "coarse silt", "coarse silt lump",
405 3, 20, 1.25, {2000, 2200, 2400, 2800}, 4, sound_silt_coarse
, { crumbly
= 3, sun_dry
= 1 })
406 pedology
.register_sucky_group("sand_fine", "fine sand", nil,
407 2, 10, 1.111111, {1100, 1200, 1300}, 0, sound_sand_fine
, { crumbly
= 3, sand
= 1, sun_dry
= 1 })
408 pedology
.register_sucky_group("sand_medium", "medium sand", nil,
409 1, 5, 1.111111, {990, 1100}, 0, sound_sand_medium
, { crumbly
= 3, sand
= 1, sun_dry
= 1 })
410 pedology
.register_sucky_group("sand_coarse", "coarse sand", nil,
411 0, nil, nil, {900}, 0, sound_sand_coarse
, { crumbly
= 3, sand
= 1, sun_dry
= 1 })
412 pedology
.register_sucky_group("gravel_fine", "fine gravel", "pebble",
413 1, 2, 1, {670, 770}, 9, sound_gravel_fine
, { crumbly
= 2, sun_dry
= 1 })
414 pedology
.register_sucky_group("gravel_medium", "medium gravel", "medium stone",
415 2, 1.5, 1, {600, 800, 1250}, 3, sound_gravel_medium
, { crumbly
= 2, sun_dry
= 1})
416 pedology
.register_sucky_group("gravel_coarse", "coarse gravel", "big stone",
417 2, 1, 1, {500, 750, 1000}, 1, sound_gravel_coarse
, { crumbly
= 1, sun_dry
= 1 })
421 pedology.register_liquid("clay_3", "sludgy clay", 192, 6, 5, 0, {a=192, r=104, g=23, b=0}, {oozing=1})
422 pedology.register_liquid("clay_4", "muddy clay", 156, 4, 5, 0, {a=156, r=123, g=57, b=6}, {oozing=1})
423 pedology.register_liquid("clay_5", "slurry clay", 128, 2, 5, 0, {a=128, r=146, g=85, b=73}, {oozing=1})
427 --[[pedology.register_sucky_group("turf_fibric", "fibric turf",
428 2, 120, 1.25, {1000, 1100, 1200}, sound_silt_coarse, { crumbly = 3, flammable = 1 } )
429 pedology.register_sucky_group("turf_hemic", "hemic turf",
430 2, 180, 1.225, {1100, 1200, 1300}, sound_silt_coarse, { crumbly = 3, flammable = 1 } )
431 pedology.register_sucky_group("turf_sapric", "sapric turf",
432 2, 240, 1.2, {1200, 1300, 1400}, sound_silt_coarse, { crumbly = 3, flammable = 1 } )]]
434 --[[ TODO (v5.0): Write registration function for turf to condense redundant code. It’s a mess! ]]
435 pedology
.register_sucky("turf_fibric", "dry fibric turf", 0, 0, 1, 1000, 4, sound_silt_coarse
, { crumbly
= 3, flammable
= 1 } )
436 pedology
.register_sucky("turf_fibric", "wet fibric turf", 1, 1, 1, 1100, 4, sound_silt_coarse
, { crumbly
= 3 } )
437 pedology
.register_sucky("turf_fibric", "watery fibric turf", 2, 1, 0, 1200, 4, sound_silt_coarse
, { crumbly
= 3 } )
439 pedology
.register_sucky("turf_hemic", "dry hemic turf", 0, 0, 1, 1100, 3, sound_silt_coarse
, { crumbly
= 3, flammable
= 1 } )
440 pedology
.register_sucky("turf_hemic", "wet hemic turf", 1, 1, 1, 1200, 3, sound_silt_coarse
, { crumbly
= 3 } )
441 pedology
.register_sucky("turf_hemic", "watery hemic turf", 2, 1, 0, 1300, 3, sound_silt_coarse
, { crumbly
= 3 } )
443 pedology
.register_sucky("turf_sapric", "dry sapric turf", 0, 0, 1, 1200, 2, sound_silt_coarse
, { crumbly
= 3, flammable
= 1 } )
444 pedology
.register_sucky("turf_sapric", "wet sapric turf", 1, 1, 1, 1300, 2, sound_silt_coarse
, { crumbly
= 3 } )
445 pedology
.register_sucky("turf_sapric", "watery sapric turf", 2, 1, 0, 1400, 2, sound_silt_coarse
, { crumbly
= 3 } )
447 minetest
.register_abm({
448 nodenames
= {"group:turf_fibric"}, neighbors
= {"group:sucky"}, interval
= 120, chance
= 1.25, action
= pedology
.ooze
450 minetest
.register_abm({
451 nodenames
= {"group:turf_hemic"}, neighbors
= {"group:sucky"}, interval
= 180, chance
= 1.225, action
= pedology
.ooze
453 minetest
.register_abm({
454 nodenames
= {"group:turf_sapric"}, neighbors
= {"group:sucky"}, interval
= 240, chance
= 1.5, action
= pedology
.ooze
457 minetest
.register_craftitem("pedology:turf_fibric_lump", {
458 description
= "fibric turf lump",
459 inventory_image
= "pedology_lump_turf_fibric.png"
461 minetest
.register_craftitem("pedology:turf_hemic_lump", {
462 description
= "hemic turf lump",
463 inventory_image
= "pedology_lump_turf_hemic.png"
465 minetest
.register_craftitem("pedology:turf_sapric_lump", {
466 description
= "sapric turf lump",
467 inventory_image
= "pedology_lump_turf_sapric.png"
473 pedology
.maxwet
.clay
= 5
474 pedology
.maxwet
.silt_fine
= 5
475 pedology
.maxwet
.silt_medium
= 4
476 pedology
.maxwet
.silt_coarse
= 3
477 pedology
.maxwet
.sand_fine
= 2
478 pedology
.maxwet
.sand_medium
= 1
479 pedology
.maxwet
.sand_coarse
= 0
480 pedology
.maxwet
.gravel_fine
= 1
481 pedology
.maxwet
.gravel_medium
= 2
482 pedology
.maxwet
.gravel_coarse
= 2
484 pedology
.maxwet
.turf_fibric
= 2
485 pedology
.maxwet
.turf_hemic
= 2
486 pedology
.maxwet
.turf_sapric
= 2
488 --[[ “API” functions ]]
489 --[[ Replace the node at <pos> with a node with a “drier” version of it, if available ]]
490 function pedology
.dry(pos
)
491 local node
= minetest
.get_node(pos
)
492 local wet
= minetest
.get_item_group(node
.name
, "wet")
493 local dried
= tostring(wet
- 1)
497 local newbasename
= string.sub(node
.name
,1,#node
.name
-1)
498 newbasename
= newbasename
.. dried
499 minetest
.set_node(pos
, {name
=newbasename
, param1
=0, param2
=0})
502 --[[ Replace the node at <pos> with a “wetter” version of it, if available ]]
503 function pedology
.wetten(pos
)
504 local node
= minetest
.get_node(pos
)
505 local wet
= minetest
.get_item_group(node
.name
, "wet")
506 local cutbasename
= string.sub(node
.name
,9,#node
.name
-2)
507 if pedology
.maxwet
[cutbasename
] == nil then
509 elseif wet
> pedology
.maxwet
[cutbasename
] then
513 local newbasename
= string.sub(node
.name
,1,#node
.name
-1) .. tostring(wet
+1)
514 minetest
.set_node(pos
, {name
=newbasename
, param1
=0, param2
=0})
517 --[[ register ABMs ]]
518 minetest
.register_abm({
519 nodenames
= {"group:sun_dry"},
523 action
= pedology
.sun_dry
,
526 minetest
.register_abm({
527 nodenames
= {"group:sucky"},
528 neighbors
= {"group:water"},
531 action
= pedology
.suck
,
534 minetest
.register_abm({
535 nodenames
= {"group:melting_point"},
536 neighbors
= {"group:hot"},
539 action
= function(pos
,node
,...)
540 minetest
.set_node(pos
,node
)