Add experimental particle-based water drips system

This commit is contained in:
Wuzzy 2014-06-23 14:02:21 +02:00
parent ef825e4a27
commit 26d553fb2c
2 changed files with 66 additions and 4 deletions

View File

@ -3,7 +3,7 @@ pedology.wetnames = {[0] = "dry", "wet", "watery", "sludgy", "muddy", "slurry"
dofile(minetest.get_modpath("pedology").."/settings.lua")
if pedology.USE_DRIPS == true then
if pedology.USE_DRIPS == 1 then
dofile(minetest.get_modpath("pedology").."/drip.lua")
end
@ -242,6 +242,43 @@ pedology.register_liquid("lava_3", "lava", 230, 4, 8, 6, {a=230, r=255, g=0, b
pedology.register_liquid("lava_4", "cold lava", 230, 5, 7, 6, {a=230, r=255, g=0, b=0}, {hot=3000, lava=1})
]]
--[[ Water drip function ]]
function pedology.drip_particle(pos, wet)
local below1 = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
local below2 = minetest.get_node({x=pos.x, y=pos.y-2, z=pos.z})
if(below1.name == "air" and below2.name == "air") then
return minetest.add_particlespawner(
wet, -- amount
0, -- time
{ x=pos.x -(45/100), y=pos.y - 0.5, z=pos.z -(45/100) }, -- minpos
{ x=pos.x +(45/100), y=pos.y - 0.5, z=pos.z +(45/100) }, -- maxpos
{ x=0, y=-9.80, z=0 }, { x=0, y=0, z=0 }, -- minvel, maxvel
{ x=0, y=-9.82, z=0 }, { x=0, y=0, z=0 }, -- minacc, maxacc
1, 3, -- minexptime, maxexptime
1, 1, -- minsize, maxsize
false, -- collisiondetection
"pedology_water_fresh.png" -- texture
-- playername
--[[ For future Lua API
{
amount = wet,
time = 0,
minpos = { pos.x -(45/100), pos.y - 0.5, pos.z -(45/100) },
maxpos = { pos.x +(45/100), pos.y - 0.5, pos.z +(45/100) },
minvel = { 0, -9.81, 0 },
maxvel = { 0, 0, 0 },
minexptime = 1,
maxexptime = 3,
collisiondetection = true,
vertical = true,
texture = "pedology_water_fresh.png",
}]]
)
else
return nil
end
end
--[[ register a sucky/oozing node to this mod ]]
function pedology.register_sucky(basename, description, wetness, oozing, sucky, melting_point, drop, sounds, additional_groups)
local wetname = basename.."_"..tostring(wetness)
@ -258,6 +295,24 @@ function pedology.register_sucky(basename, description, wetness, oozing, sucky,
-- If the node is not dry, do not add it into the creative inventory
if wetness == 0 then noncreative = 0 else noncreative = 1 end
if pedology.USE_DRIPS == 2 then
on_construct = function(pos)
local dripper = pedology.drip_particle(pos, wetness)
if(dripper ~= nil) then
local meta = minetest.get_meta(pos)
meta:set_int("dripper", dripper)
end
end
on_destruct = function(pos)
local meta = minetest.get_meta(pos)
local dripper = meta:get_int("dripper")
if(dripper ~= nil) then
minetest.delete_particlespawner(dripper)
end
end
else
on_construct, after_destruct = nil
end
local nodedef = {
description = description,
inventory_image = minetest.inventorycube("pedology_"..wetname..".png"),
@ -267,9 +322,13 @@ function pedology.register_sucky(basename, description, wetness, oozing, sucky,
groups = groups,
sounds = sounds,
is_ground_content = true,
on_construct = on_construct,
on_destruct = on_destruct,
}
minetest.register_node(name, nodedef)
end
@ -335,7 +394,7 @@ function pedology.register_sucky_group(basename, basedescription, lumpbasedescri
end
pedology.register_sucky(basename, (pedology.wetnames[w]).." "..basedescription, w, oozing, sucky, m, drop, sounds, groups)
-- register dripping
if(w>0 and pedology.USE_DRIPS == true) then
if(w>0 and pedology.USE_DRIPS == 1) then
minetest.register_abm({
nodenames = {"pedology:"..basename.."_"..tostring(w)},
neighbors = {"air"},

View File

@ -1,5 +1,8 @@
-- Create water drips. Warning: This feature is experimental and there are performance issues with it.
pedology.USE_DRIPS = false
--[[ Create water drips. This is still an experimental feature
0 = dont use water drips
1 = use entity-based water drips (3D, with sounds, slow)
2 = use particle-based water drips (2D, without sounds, fast) ]]
pedology.USE_DRIPS = 0
-- Minimum light level at which nodes dry out from light
pedology.DRY_LIGHT = 13