1
0
Fork 0

make cooling lava an API as well

mineclone_compatibility
FaceDeer 2022-08-16 12:51:33 -06:00
parent 849660e6d4
commit b35240a53a
3 changed files with 68 additions and 45 deletions

View File

@ -1,9 +1,14 @@
if not minetest.get_modpath("default") then return end
dynamic_liquid.cooling_lava = function(def)
local new_lava_cooling = minetest.settings:get_bool("dynamic_liquid_new_lava_cooling", true)
if not new_lava_cooling then return end
local lava_source = def.lava_source
local lava_flowing = def.lava_flowing
local obsidian = def.obsidian
local flowing_destroys = def.flowing_destroys or {}
local source_destroys = def.source_destroys or {}
local cooling_sound = def.cooling_sound
local falling_obsidian = dynamic_liquid.config.falling_obsidian
local falling_obsidian = minetest.settings:get_bool("dynamic_liquid_falling_obsidian", false)
-- The existing cool_lava ABM is hard-coded to respond to water nodes
-- and overriding node groups doesn't appear to work:
@ -20,7 +25,6 @@ local falling_obsidian = minetest.settings:get_bool("dynamic_liquid_falling_obsi
-- to nodes that should be destroyed by proximity to lava.
local particles = minetest.settings:get_bool("enable_particles", true)
local steam = function(pos)
if particles then
minetest.add_particlespawner({
@ -43,22 +47,19 @@ local steam = function(pos)
end
end
default.cool_lava = function(pos, node)
-- no-op disables default cooling ABM
end
-------------------------------------------------------------------------------------------------
local dynamic_cools_lava_flowing = {"group:dynamic_cools_lava_flowing", "group:cools_lava"}
-- Flowing lava will turn these blocks into steam.
local dynamic_lava_flowing_destroys = {
"group:dynamic_lava_flowing_destroys",
"default:water_flowing",
"default:river_water_flowing",
"default:snow",
"default:snowblock"
}
for _, node_name in pairs(flowing_destroys) do
table.insert(dynamic_lava_flowing_destroys, node_name)
end
local all_flowing_nodes = {unpack(dynamic_cools_lava_flowing)}
for i = 1, #dynamic_lava_flowing_destroys do
@ -71,9 +72,9 @@ local cool_lava_flowing = function(pos, node)
if cooler_adjacent ~= nil then
-- pulling nearby sources into position is necessary to break certain classes of
-- flow "deadlock". Weird, but what're you gonna do.
local nearby_source = minetest.find_node_near(pos, 1, "default:lava_source")
local nearby_source = minetest.find_node_near(pos, 1, lava_source)
if nearby_source then
minetest.set_node(pos, {name="default:lava_source"})
minetest.set_node(pos, {name=lava_source})
minetest.set_node(nearby_source, {name="air"})
steam(nearby_source)
else
@ -92,13 +93,13 @@ local cool_lava_flowing = function(pos, node)
steam(loc)
end
minetest.sound_play("default_cool_lava",
minetest.sound_play(cooling_sound,
{pos = pos, max_hear_distance = 16, gain = 0.25})
end
minetest.register_abm({
label = "Lava flowing cooling",
nodenames = {"default:lava_flowing"},
nodenames = {lava_flowing},
neighbors = all_flowing_nodes,
interval = 1,
chance = 1,
@ -122,14 +123,11 @@ end
-- lava source blocks will turn these blocks into steam.
local dynamic_lava_source_destroys = {
"group:dynamic_lava_source_destroys",
"default:water_source",
"default:river_water_source",
"default:water_flowing",
"default:river_water_flowing",
"default:ice",
"default:snow",
"default:snowblock"
}
for _, node_name in pairs(source_destroys) do
table.insert(dynamic_lava_source_destroys, node_name)
end
local all_source_nodes = {unpack(dynamic_cools_lava_source)}
for i = 1, #dynamic_lava_source_destroys do
@ -193,8 +191,8 @@ local cool_lava_source = function(pos, node)
if obsidian_location ~= nil then
minetest.set_node(pos, {name = "air"})
minetest.set_node(obsidian_location, {name = "default:obsidian"})
if minetest.spawn_falling_node and falling_obsidian then -- TODO cutting-edge dev function, so check if it exists for the time being. Remove check when 0.4.16 is released.
minetest.set_node(obsidian_location, {name = obsidian})
if falling_obsidian then
minetest.spawn_falling_node(obsidian_location)
end
elseif #evaporate_list > 0 then
@ -202,18 +200,18 @@ local cool_lava_source = function(pos, node)
local loc = evaporate_list[math.random(1,#evaporate_list)]
if loc.y <= pos.y then
minetest.set_node(pos, {name = "air"})
minetest.set_node(loc, {name = "default:lava_source"})
minetest.set_node(loc, {name = lava_source})
end
end
minetest.sound_play("default_cool_lava",
minetest.sound_play(cooling_sound,
{pos = pos, max_hear_distance = 16, gain = 0.25})
end
minetest.register_abm({
label = "Lava source cooling",
nodenames = {"default:lava_source"},
nodenames = {lava_source},
neighbors = all_source_nodes,
interval = 1,
chance = 1,
@ -221,4 +219,7 @@ minetest.register_abm({
action = function(...)
cool_lava_source(...)
end,
})
})
end

View File

@ -1,37 +1,33 @@
local S = minetest.get_translator(minetest.get_current_modname())
local water = dynamic_liquid.config.water
local river_water = dynamic_liquid.config.river_water
local lava = dynamic_liquid.config.lava
local water_probability = dynamic_liquid.config.water_probability
local river_water_probability = dynamic_liquid.config.river_water_probability
local lava_probability = dynamic_liquid.config.lava_probability
local water_level = dynamic_liquid.config.water_level
local springs = dynamic_liquid.config.springs
local flow_through = dynamic_liquid.config.flow_through
local mapgen_prefill = dynamic_liquid.config.mapgen_prefill
if water then
if dynamic_liquid.config.lava then
dynamic_liquid.liquid_abm("default:lava_source", "default:lava_flowing", lava_probability)
end
if dynamic_liquid.config.water then
-- override water_source and water_flowing with liquid_renewable set to false
local override_def = {liquid_renewable = false}
minetest.override_item("default:water_source", override_def)
minetest.override_item("default:water_flowing", override_def)
end
if lava then
dynamic_liquid.liquid_abm("default:lava_source", "default:lava_flowing", lava_probability)
end
if water then
dynamic_liquid.liquid_abm("default:water_source", "default:water_flowing", water_probability)
end
if river_water then
if dynamic_liquid.config.river_water then
dynamic_liquid.liquid_abm("default:river_water_source", "default:river_water_flowing", river_water_probability)
end
-- Flow-through nodes
-----------------------------------------------------------------------------------------------------------------------
if flow_through then
if dynamic_liquid.config.flow_through then
local flow_through_nodes = {"group:flow_through", "group:leaves", "group:sapling", "group:grass", "group:dry_grass", "group:flora", "groups:rail", "groups:flower",
@ -51,7 +47,7 @@ if flow_through then
dynamic_liquid.flow_through_abm({nodenames = flow_through_nodes})
end
if mapgen_prefill then
if dynamic_liquid.config.mapgen_prefill then
dynamic_liquid.mapgen_prefill({liquid="default:water_source", liquid_level=water_level})
end
@ -168,4 +164,30 @@ if springs then
end
end
})
end
--------------------------------------------------------
-- Cooling lava
if dynamic_liquid.config.new_lava_cooling then
default.cool_lava = function(pos, node)
-- no-op disables default cooling ABM
end
dynamic_liquid.cooling_lava({
flowing_destroys = {"default:water_flowing", "default:river_water_flowing", "default:snow", "default:snowblock"},
source_destroys = { "default:water_source",
"default:river_water_source",
"default:water_flowing",
"default:river_water_flowing",
"default:ice",
"default:snow",
"default:snowblock",
},
lava_source = "default:lava_source",
lava_flowing = "default:lava_flowing",
obsidian = "default:obsidian",
cooling_sound = "default_cool_lava",
})
end

View File

@ -15,8 +15,8 @@ dynamic_liquid.config.flow_through = minetest.settings:get_bool("dynamic_liquid_
dynamic_liquid.config.mapgen_prefill = minetest.settings:get_bool("dynamic_liquid_mapgen_prefill", true)
dynamic_liquid.config.disable_flow_above = tonumber(minetest.settings:get("dynamic_liquid_disable_flow_above")) -- this one can be nil
dynamic_liquid.config.displace_liquid = minetest.settings:get_bool("dynamic_liquid_displace_liquid", true)
dynamic_liquid.config.new_lava_cooling = minetest.settings:get_bool("dynamic_liquid_new_lava_cooling", true)
dynamic_liquid.config.falling_obsidian = minetest.settings:get_bool("dynamic_liquid_falling_obsidian", false)
dynamic_liquid.registered_liquids = {} -- used by the flow-through node abm
dynamic_liquid.registered_liquid_neighbors = {}