mirror of
https://github.com/t-affeldt/regional_weather.git
synced 2025-07-17 07:50:27 +02:00
Implement ABM system and damage effect
This commit is contained in:
21
abms/fire.lua
Normal file
21
abms/fire.lua
Normal file
@ -0,0 +1,21 @@
|
||||
if not regional_weather.settings.fire then return end
|
||||
if not minetest.get_modpath("fire") then return end
|
||||
|
||||
climate_api.register_abm({
|
||||
label = "extinguish fire at high humidity",
|
||||
nodenames = { "fire:basic_flame" },
|
||||
interval = 10,
|
||||
chance = 2,
|
||||
|
||||
conditions = {
|
||||
min_height = regional_weather.settings.min_height,
|
||||
max_height = regional_weather.settings.max_height,
|
||||
min_humidity = 55,
|
||||
max_heat = 85,
|
||||
min_light = 15
|
||||
},
|
||||
|
||||
action = function (pos, node, env)
|
||||
minetest.set_node(pos, { name = "air" })
|
||||
end
|
||||
})
|
86
abms/puddle.lua
Normal file
86
abms/puddle.lua
Normal file
@ -0,0 +1,86 @@
|
||||
-- code of this file is partially taken from and otherwise inspired by
|
||||
-- mymonths on https://github.com/minetest-mods/mymonths (licensed under DWYWPL)
|
||||
-- contributers available at https://github.com/minetest-mods/mymonths/graphs/contributors
|
||||
-- all changes of mine remain under LGPL v3
|
||||
|
||||
local BLOCK_NAME = "regional_weather:puddle"
|
||||
local MIN_DISTANCE = 12
|
||||
|
||||
if not regional_weather.settings.puddles then
|
||||
minetest.register_alias(BLOCK_NAME, "air")
|
||||
return
|
||||
end
|
||||
|
||||
--Puddle node
|
||||
local node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.1875, -0.5, -0.375, 0.125, -0.4875, 0.3125},
|
||||
{-0.25, -0.5, -0.3125, 0.3125, -0.4925, 0.25},
|
||||
{-0.3125, -0.5, -0.1875, 0.375, -0.4975, 0.1875},
|
||||
}
|
||||
}
|
||||
|
||||
minetest.register_node(BLOCK_NAME, {
|
||||
tiles = { "weather_puddle.png" },
|
||||
drawtype = "nodebox",
|
||||
pointable = false,
|
||||
buildable_to = true,
|
||||
floodable = true,
|
||||
walkable = false,
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
alpha = 50,
|
||||
node_box = node_box,
|
||||
groups = {
|
||||
not_in_creative_inventory = 1,
|
||||
crumbly = 3,
|
||||
attached_node = 1,
|
||||
slippery = 1,
|
||||
replaceable_by_snow = 1
|
||||
},
|
||||
drop = "",
|
||||
})
|
||||
|
||||
-- Makes Puddles when raining
|
||||
climate_api.register_abm({
|
||||
label = "create rain puddles",
|
||||
nodenames = { "group:soil", "group:stone" },
|
||||
neighbors = { "air" },
|
||||
interval = 10,
|
||||
chance = 50,
|
||||
|
||||
conditions = {
|
||||
min_height = regional_weather.settings.min_height,
|
||||
max_height = regional_weather.settings.max_height,
|
||||
min_humidity = 55,
|
||||
min_heat = 30,
|
||||
min_light = 15
|
||||
},
|
||||
|
||||
pos_override = function(pos)
|
||||
return vector.add(pos, { x = 0, y = 1, z = 0 })
|
||||
end,
|
||||
|
||||
action = function (pos, node, env)
|
||||
if minetest.get_node(pos).name ~= "air" then return end
|
||||
if minetest.find_node_near(pos, MIN_DISTANCE, BLOCK_NAME) then return end
|
||||
minetest.set_node(pos, {name = BLOCK_NAME})
|
||||
end
|
||||
})
|
||||
|
||||
-- Makes puddles dry up when not raining
|
||||
climate_api.register_abm({
|
||||
label = "remove rain puddles",
|
||||
nodenames = { BLOCK_NAME },
|
||||
interval = 5,
|
||||
chance = 5,
|
||||
|
||||
action = function (pos, node, env)
|
||||
if env.humidity < 55 then
|
||||
minetest.remove_node(pos)
|
||||
elseif env.heat < 30 and regional_weather.settings.snow_cover then
|
||||
minetest.set_node(pos, {name = "regional_weather:snow_cover_1"})
|
||||
end
|
||||
end
|
||||
})
|
137
abms/snow_cover.lua
Normal file
137
abms/snow_cover.lua
Normal file
@ -0,0 +1,137 @@
|
||||
-- code of this file is partially taken from and otherwise inspired by
|
||||
-- mymonths on https://github.com/minetest-mods/mymonths (licensed under DWYWPL)
|
||||
-- contributers available at https://github.com/minetest-mods/mymonths/graphs/contributors
|
||||
-- all changes of mine remain under LGPL v3
|
||||
|
||||
local BLOCK_PREFIX = "regional_weather:snow_cover_"
|
||||
|
||||
if not regional_weather.settings.puddles then
|
||||
for i = 1,5 do
|
||||
minetest.register_alias(BLOCK_PREFIX .. i, "air")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
for i = 1,5 do
|
||||
local node_box = {
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, 0.2*i - 0.5, 0.5}
|
||||
}
|
||||
|
||||
minetest.register_node(BLOCK_PREFIX .. i, {
|
||||
tiles = { "default_snow.png" },
|
||||
drawtype = "nodebox",
|
||||
buildable_to = i < 3,
|
||||
floodable = true,
|
||||
walkable = i > 3,
|
||||
paramtype = "light",
|
||||
node_box = node_box,
|
||||
groups = {
|
||||
not_in_creative_inventory = 1,
|
||||
crumbly = 3,
|
||||
falling_node = 1,
|
||||
snowy = 1,
|
||||
regional_weather_snow_cover = i
|
||||
},
|
||||
sounds = default.node_sound_snow_defaults(),
|
||||
drop = "default:snow " .. math.ceil(i / 2),
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
||||
minetest.set_node(pos, {name = "default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
climate_api.register_abm({
|
||||
label = "create snow covers",
|
||||
nodenames = {
|
||||
"group:soil",
|
||||
"group:leaves",
|
||||
"group:stone",
|
||||
"default:snowblock",
|
||||
"group:coverable_by_snow"
|
||||
},
|
||||
neighbors = { "air" },
|
||||
interval = 15,
|
||||
chance = 20,
|
||||
|
||||
conditions = {
|
||||
min_height = regional_weather.settings.min_height,
|
||||
max_height = regional_weather.settings.max_height,
|
||||
min_humidity = 55,
|
||||
max_heat = 30,
|
||||
min_light = 15
|
||||
},
|
||||
|
||||
pos_override = function(pos)
|
||||
return vector.add(pos, { x = 0, y = 1, z = 0 })
|
||||
end,
|
||||
|
||||
action = function (pos, node, env)
|
||||
if minetest.get_node(pos).name ~= "air" then return end
|
||||
local base = minetest.get_node(vector.add(pos, {x=0, y=-1, z=0})).name
|
||||
local is_soil = minetest.get_item_group(base, "soil") or 0
|
||||
local is_stone = minetest.get_item_group(base, "stone") or 0
|
||||
if not (is_soil == 0 and is_stone == 0) then
|
||||
minetest.set_node(pos, { name = BLOCK_PREFIX .. "1" })
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
climate_api.register_abm({
|
||||
label = "replace flora with snow covers and stack covers higher",
|
||||
nodenames = {
|
||||
"group:flora",
|
||||
"group:grass",
|
||||
"group:plant",
|
||||
"group:replaceable_by_snow",
|
||||
"group:regional_weather_snow_cover"
|
||||
},
|
||||
interval = 15,
|
||||
chance = 15,
|
||||
|
||||
conditions = {
|
||||
min_height = regional_weather.settings.min_height,
|
||||
max_height = regional_weather.settings.max_height,
|
||||
min_humidity = 55,
|
||||
max_heat = 30,
|
||||
min_light = 15
|
||||
},
|
||||
|
||||
action = function (pos, node, env)
|
||||
local node_name = minetest.get_node(pos).name
|
||||
local value = minetest.get_item_group(node_name, "regional_weather_snow_cover")
|
||||
if value == nil then value = 0 end
|
||||
if value < 5 then
|
||||
minetest.set_node(pos, { name = BLOCK_PREFIX .. (value + 1) })
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
climate_api.register_abm({
|
||||
label = "melt snow covers",
|
||||
nodenames = { "group:regional_weather_snow_cover" },
|
||||
interval = 15,
|
||||
chance = 10,
|
||||
|
||||
conditions = {
|
||||
min_height = regional_weather.settings.min_height,
|
||||
max_height = regional_weather.settings.max_height,
|
||||
min_heat = 30
|
||||
},
|
||||
|
||||
action = function (pos, node, env)
|
||||
local node_name = minetest.get_node(pos).name
|
||||
local value = minetest.get_item_group(node_name, "regional_weather_snow_cover")
|
||||
if value == nil then value = 0 end
|
||||
if value > 1 then
|
||||
minetest.set_node(pos, { name = BLOCK_PREFIX .. (value - 1) })
|
||||
elseif regional_weather.settings.puddles then
|
||||
minetest.set_node(pos, { name = "regional_weather:puddle" })
|
||||
else
|
||||
minetest.set_node(pos, { name = "air" })
|
||||
end
|
||||
end
|
||||
})
|
@ -0,0 +1,46 @@
|
||||
if not regional_weather.settings.soil then return end
|
||||
if not minetest.get_modpath("farming") then return end
|
||||
|
||||
if farming ~= nil and farming.mod == "redo" then
|
||||
climate_api.register_abm({
|
||||
label = "wetten soil at high humidity",
|
||||
nodenames = { "farming:soil" },
|
||||
interval = 8,
|
||||
chance = 2,
|
||||
|
||||
conditions = {
|
||||
min_height = regional_weather.settings.min_height,
|
||||
max_height = regional_weather.settings.max_height,
|
||||
min_humidity = 55,
|
||||
min_heat = 30,
|
||||
min_light = 15
|
||||
},
|
||||
|
||||
action = function (pos, node, env)
|
||||
minetest.set_node(pos, { name = "farming:soil_wet" })
|
||||
end
|
||||
})
|
||||
|
||||
else
|
||||
climate_api.register_abm({
|
||||
label = "wetten fields at high humidity",
|
||||
nodenames = { "group:field" },
|
||||
interval = 8,
|
||||
chance = 2,
|
||||
|
||||
conditions = {
|
||||
min_height = regional_weather.settings.min_height,
|
||||
max_height = regional_weather.settings.max_height,
|
||||
min_humidity = 55,
|
||||
min_heat = 30,
|
||||
min_light = 15
|
||||
},
|
||||
|
||||
action = function (pos, node, env)
|
||||
local node_def = minetest.registered_nodes[node.name] or nil
|
||||
local wet_soil = node_def.soil.wet or nil
|
||||
if wet_soil == nil then return end
|
||||
minetest.set_node(pos, { name = wet_soil })
|
||||
end
|
||||
})
|
||||
end
|
Reference in New Issue
Block a user