Compare commits
5 Commits
819559d471
...
bc6513a3e5
Author | SHA1 | Date |
---|---|---|
sloantothebone | bc6513a3e5 | |
proller | ab2ded7512 | |
proller | 31b3dd0e41 | |
proller | 60bec3ca0d | |
proller | 7c9db48770 |
63
finite.lua
63
finite.lua
|
@ -36,6 +36,12 @@ waterplus.register_step = function(a,height)
|
|||
diggable = false,
|
||||
climbable = true,
|
||||
buildable_to = true,
|
||||
liquid_viscosity = 1, --added water-like viscosity
|
||||
liquidtype = "source",
|
||||
liquid_alternative_flowing = "waterplus:finite_"..a,
|
||||
liquid_alternative_source = "waterplus:finite_"..a,
|
||||
liquid_renewable = false,
|
||||
liquid_range = 0,
|
||||
post_effect_color = {a=64, r=100, g=100, b=200},
|
||||
groups = {water=3,finite_water=((a/waterplus.finite_water_steps)*100), puts_out_fire=1},
|
||||
node_box = {
|
||||
|
@ -104,10 +110,10 @@ minetest.register_abm({
|
|||
local source_id = getNumberFromName(source_name) or 0
|
||||
local coords = {
|
||||
|
||||
{x=pos.x-1,y=pos.y-1,z=pos.z, f=1}, -- vertical drop
|
||||
{x=pos.x+1,y=pos.y-1,z=pos.z, f=1}, -- f= can flow or drop
|
||||
{x=pos.x,y=pos.y-1,z=pos.z-1, f=1},
|
||||
{x=pos.x,y=pos.y-1,z=pos.z+1, f=1},
|
||||
{x=pos.x-1,y=pos.y-1,z=pos.z, f=1, d=1,}, -- vertical drop
|
||||
{x=pos.x+1,y=pos.y-1,z=pos.z, f=1, d=1,}, -- f= can flow or drop
|
||||
{x=pos.x,y=pos.y-1,z=pos.z-1, f=1, d=1,}, -- d= can drop
|
||||
{x=pos.x,y=pos.y-1,z=pos.z+1, f=1, d=1,},
|
||||
|
||||
{x=pos.x-1,y=pos.y,z=pos.z,h=1, f=1, wi=1, iw=1,}, -- h=horisontal flow
|
||||
{x=pos.x+1,y=pos.y,z=pos.z,h=1, f=1, wi=1, iw=1,}, -- wi= standard water infect
|
||||
|
@ -119,6 +125,8 @@ minetest.register_abm({
|
|||
local can = 0
|
||||
local can_water = 1
|
||||
local can_max = 0
|
||||
local can_min = 0
|
||||
local infected = 0
|
||||
--local high_nearby = 0;
|
||||
-- step1: calculate possibility of flow with volumes
|
||||
for i = 1,9 do
|
||||
|
@ -126,15 +134,17 @@ minetest.register_abm({
|
|||
coords[i].n = name
|
||||
local target_id = getNumberFromName(name)
|
||||
dPrint("test nei "..name ..' = '.. (target_id or 'NO'))
|
||||
if coords[i].wi and name=="default:water_source" and source_id<waterplus.finite_water_max_id then
|
||||
if infected < 1 and coords[i].wi and name=="default:water_source" and source_id<waterplus.finite_water_max_id then
|
||||
dPrint('convert up='..(coords[i].u or '')..' me=' .. source_id)
|
||||
minetest.env:set_node(coords[i],{name = waterplus.finite_water_max_name})
|
||||
target_id = waterplus.finite_water_max_id
|
||||
--high_nearby = waterplus.finite_water_max_id
|
||||
infected = infected + 1
|
||||
end
|
||||
if coords[i].f and name == "air" then
|
||||
coords[i].v = waterplus.finite_water_max_id
|
||||
coords[i].t = 0
|
||||
can = 1
|
||||
--elseif name=="default:water_flowing" then
|
||||
-- minetest.env:set_node(coords[i],{name = "waterplus:finite_10"})
|
||||
--high_nearby = math.max(high_nearby, 10);
|
||||
|
@ -151,16 +161,19 @@ dPrint('convert up='..(coords[i].u or '')..' me=' .. source_id)
|
|||
coords[i].v = waterplus.finite_water_max_id - target_id
|
||||
end
|
||||
dPrint('test water ' .. (coords[i].wi or 'nwi') .. ' t=' .. target_id)
|
||||
if coords[i].iw and (target_id < waterplus.finite_water_max_id or name == "air") then
|
||||
-- do not convert to standard water if flow possible
|
||||
can_water = 0
|
||||
dPrint('cant water ' .. target_id .. ' n='..name)
|
||||
end
|
||||
if coords[i].v and coords[i].v > 0 then can = 1 end
|
||||
--high_nearby = math.max(high_nearby, target_id);
|
||||
if coords[i].h and target_id >= waterplus.finite_water_max_id then can_max = can_max + 1 end
|
||||
if coords[i].h and coords[i].t >= waterplus.finite_water_max_id then can_max = can_max + 1 end
|
||||
end
|
||||
end
|
||||
if coords[i].d and (name=="default:water_source") then can_min = can_min + 1 end
|
||||
--print('cmt me=' .. source_id .. ' to='.. (coords[i].d or 'no') .. ' n=' .. name .. ' r=' .. can_min )
|
||||
if coords[i].h and coords[i].iw and ((target_id and target_id < waterplus.finite_water_max_id-1) or name == "air") then
|
||||
-- do not convert to standard water if flow possible
|
||||
can_water = 0
|
||||
dPrint('cant water ' .. (target_id or 0) .. ' n='..name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- step2: perform flow and drop twice: first for drop then flow if something rest
|
||||
for pass=0,1 do
|
||||
|
@ -171,6 +184,7 @@ dPrint('cant water ' .. target_id .. ' n='..name)
|
|||
--print('testpress ' .. (coords[i].h or 'vertical') .. ' p='.. pressure)
|
||||
if coords[i].h and pressure <= 1 then
|
||||
min = coords[i].t or 0
|
||||
min = min + 1
|
||||
-- trick: flow more if have higher nearby watre level: bad idea for now
|
||||
--if high_nearby > source_id then
|
||||
--min = math.ceil((high_nearby + source_id + min)/3)
|
||||
|
@ -178,15 +192,15 @@ dPrint('cant water ' .. target_id .. ' n='..name)
|
|||
--end
|
||||
if not min or min < 1 then min = 1 end
|
||||
end
|
||||
dPrint ('flowto '.. (coords[i].v or'NO') .. ' s='.. source_id .. ' min='.. min)
|
||||
dPrint ('flowto p='..pass..' i='..i.. ' v='..(coords[i].v or'NO') .. ' s='.. source_id .. ' min='.. min)
|
||||
-- perform one-level flow
|
||||
if coords[i].v and coords[i].v > 0 and source_id > min then
|
||||
coords[i].v = coords[i].v - 1
|
||||
source_id = source_id - 1
|
||||
coords[i].a = 1 -- (coords[i].a or 0) + 1
|
||||
coords[i].a = (coords[i].a or 0) + 1
|
||||
coords[i].t = coords[i].t + 1
|
||||
flowed = 1
|
||||
dPrint ('flow v=' .. coords[i].v ..' t='.. coords[i].t .. ' s='..source_id.. ' min='..min)
|
||||
dPrint('flow p='..pass..' i='..i.. ' v=' .. coords[i].v ..' t='.. coords[i].t .. ' s='..source_id.. ' min='..min .. ' fl='..coords[i].a)
|
||||
if source_id < 1 then break end
|
||||
end
|
||||
end
|
||||
|
@ -210,13 +224,24 @@ dPrint ('repl '..(coords[i].o or 'air') ..' to' .. coords[i].t)
|
|||
minetest.env:set_node(coords[i],{name = "waterplus:finite_"..coords[i].t})
|
||||
end
|
||||
end
|
||||
--canmax: trick for reduce finite blocks, add one if cant flow and max nearby 21+22 = 22+22
|
||||
dPrint('canmax=' .. can_max..' s='..source_id.. ' cw='..can_water)
|
||||
if can_max >= 1 and source_id == waterplus.finite_water_max_id - 1 then
|
||||
--print('canmax '..source_id)
|
||||
source_id = waterplus.finite_water_max_id
|
||||
end
|
||||
--canmin: remove last level if down nearby is full 1+22 = 22
|
||||
--print('canmin=' .. can_min..' s='..source_id.. ' cw='..can_water)
|
||||
if can_min >= 1 and source_id == 1 then
|
||||
--print('canmin '..source_id)
|
||||
source_id = 0
|
||||
end
|
||||
|
||||
local set = "waterplus:finite_"..source_id
|
||||
if source_id < 1 then set = "air" end
|
||||
-- can_max - cheat for decreasing finite blocks at top of ocean
|
||||
dPrint('canmax=' .. can_max..' s='..source_id.. ' cw='..can_water)
|
||||
if can_max > 1 and source_id == waterplus.finite_water_max_id - 1 then source_id = waterplus.finite_water_max_id end
|
||||
dPrint('test canwater' .. can_water ..' me='.. source_id)
|
||||
if can_water and source_id == waterplus.finite_water_max_id then
|
||||
if can_water>0 and source_id == waterplus.finite_water_max_id then
|
||||
set = "default:water_source"
|
||||
end
|
||||
if set ~= source_name then
|
||||
|
@ -403,7 +428,7 @@ minetest.register_abm({
|
|||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos,node)
|
||||
local level = (waterplus.finite_water_max_id / (node.param2 or 1)) * 15
|
||||
local level = math.floor((node.param2/15)*waterplus.finite_water_max_id)
|
||||
if level < 1 then level = 1 end
|
||||
if level > waterplus.finite_water_max_id-3 then level = waterplus.finite_water_max_id-3 end
|
||||
dPrint("Waterplus [finite] - transforming float water to finite ".." at "..pos.x..","..pos.y..","..pos.z .. ' p1='.. node.param1 .. ' p2='.. node.param2 .. ' level='.. level)
|
||||
|
|
Loading…
Reference in New Issue