Compare commits

...

1 Commits

Author SHA1 Message Date
Nils Dagsson Moskopp 32bc8bf28b
Speed up water flow to make lavacasting possible
Minecraft-style lavacasting involves making a lavafall and pouring water
over it to solidify the flowing lava. The Minetest engine make this hard
to do, since water that flows beside lava flows at similar speed as lava
disappaers. Therefore, making a lava curtain and pouring water over that
can not create a solid wall of cobblestone as it does in Minecraft if no
code is added to speed up downwards water flow.

This patch adds an ABM that speeds up downwards water flows, turning any
lava nodes next to the newly spawned water into cobblestone or obsidian.
2021-09-04 05:38:41 +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
--