Compare commits

...

6 Commits

Author SHA1 Message Date
Nils Dagsson Moskopp b0b8162051
Refucktor everything (WIP) 2021-09-04 05:04:44 +02:00
Nils Dagsson Moskopp c34099b92e
spede up water flow into air (WIP) 2021-09-04 03:40:19 +02:00
Nils Dagsson Moskopp bed865dc79
refactor (WIP) 2021-09-04 03:08:05 +02:00
Nils Dagsson Moskopp 0ba6b7a2d2
wip wöp (WIP) 2021-09-04 02:54:28 +02:00
Nils Dagsson Moskopp cc76a79a7d
work around bug in lava cooling (WIP) 2021-09-04 02:40:31 +02:00
Nils Dagsson Moskopp 4ca70a7af1
speed up water flow (WIP) 2021-09-04 02:10:35 +02:00
1 changed files with 95 additions and 0 deletions

View File

@ -48,6 +48,101 @@ minetest.register_abm({
end,
})
minetest.register_abm({
label="Speed up downwards water flow and cool lava",
nodenames = {"mcl_core:water_flowing"},
neighbors = {"air"},
interval = 0.5,
chance = 1,
action = function(pos, node)
-- I want to start with an important message to every
-- future programmer who wants to rewrite the code in
-- a recursive fashion: STACK OVERFLOWS MEAN CRASHES!
--
-- Your recursive approach will most likely crash the
-- game if not on your computer, then probably some
-- time later on some other computer. If you want the
-- questionable honor of being at fault when a bucket
-- of water can crash the server, go ahead: Refucktor
-- the code and be upset when it ruins someone's day.
--
-- After all, it really was not your fault, right? On
-- your computer everything worked and whoever has an
-- issue with your elegant solution just should buy a
-- new gaming rig or do something else beyond holding
-- you responsible for your utterly perfect solution.
--
-- In case this message offends you, I hereby ask you
-- to kindly fuck off, by which I mean: Stop reading.
local beside_pos_list
local beside_node
local lavatype
for i=1,80 do
-- In the first iteration of this loop, the
-- current position is guaranteed to have a
-- flowing water node. Later iterations can
-- assume a flowing water node since either
-- this loop ends or it replaces air with a
-- flowing water node below, then does that
-- same quit-or-replace dance a node lower.
local below_pos = {x=pos.x, y=pos.y-i, z=pos.z}
local below_node = minetest.get_node(below_pos)
-- TODO: Check here if that node below is lava
-- and turn it into cobblestone or obsidian if
-- that process does not affect performance in
-- a major way. But how to measure the impact?
if below_node.name ~= "air" then
return
end
minetest.set_node(
below_pos,
{name="mcl_core:water_flowing", param2=15}
)
-- One could assume that the lava cooling ABM
-- would now do its job if water nodes end up
-- next to lava nodes. Sadly, this is not the
-- case: The only way to get reliable cooling
-- of lava nodes is to do it ourselves here …
-- the lava nodes are just removed otherwise.
--
-- This is probably an engine bug (not sure).
beside_pos_list = {
{x=below_pos.x+1, y=below_pos.y, z=below_pos.z},
{x=below_pos.x-1, y=below_pos.y, z=below_pos.z},
{x=below_pos.x, y=below_pos.y, z=below_pos.z+1},
{x=below_pos.x, y=below_pos.y, z=below_pos.z-1},
}
for _, beside_pos in ipairs(beside_pos_list) do
beside_node = minetest.get_node(beside_pos)
if 1 == minetest.get_item_group(beside_node.name, "lava") then
lavatype = minetest.registered_nodes[beside_node.name].liquidtype
-- Lava flow →Cobblestone
if lavatype == "flowing" then
minetest.set_node(
beside_pos,
{name="mcl_core:cobble"}
)
-- Lava source →Obsidian
elseif lavatype == "source" then
minetest.set_node(
beside_pos,
{name="mcl_core:obsidian"}
)
end
-- Stone is generated if lava
-- ends up above water nodes,
-- this is handled elsewhere.
minetest.sound_play(
"fire_extinguish_flame",
{pos=beside_pos, gain=0.25, max_hear_distance=16},
true
)
end
end
end
end,
})
--
-- Papyrus and cactus growing
--