Implement ABM system and damage effect

This commit is contained in:
Till Affeldt 2020-04-16 19:13:14 +02:00
parent 6d3e33bf9f
commit 9084bdf4b2
17 changed files with 328 additions and 18 deletions

21
abms/fire.lua Normal file
View 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
View 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
})

View File

137
abms/snow_cover.lua Normal file
View 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
})

View File

View File

@ -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

View File

@ -0,0 +1,17 @@
if not regional_weather.settings.damage then return end
local EFFECT_NAME = "regional_weather:damage"
local function handle_effect(player_data)
for playername, data in pairs(player_data) do
local player = minetest.get_player_by_name(playername)
local hp = player:get_hp()
for weather, value in pairs(data) do
hp = hp - value
end
player:set_hp(hp, "weather damage")
end
end
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.LONG_CYCLE)

View File

@ -2,7 +2,7 @@ local name = "regional_weather:deep_cave"
local conditions = {
max_light = 14,
--max_height = -100
max_height = -100
}
local effects = {}

View File

@ -11,9 +11,7 @@ local conditions = {
local effects = {}
effects["regional_weather:spawn_puddles"] = true
effects["regional_weather:lightning"] = true
effects["climate_api:damage"] = 1
effects["regional_weather:damage"] = 1
effects["climate_api:sound"] = {
name = "weather_hail",

View File

@ -10,8 +10,6 @@ local conditions = {
}
local effects = {}
effects["regional_weather:spawn_puddles"] = true
effects["regional_weather:wetten_farmland"] = true
effects["climate_api:sound"] = {
name = "weather_rain"

View File

@ -10,10 +10,6 @@ local conditions = {
local effects = {}
effects["regional_weather:spawn_puddles"] = true
effects["regional_weather:wetten_farmland"] = true
effects["regional_weather:lightning"] = true
effects["climate_api:sound"] = {
name = "weather_rain",
gain = 1

View File

@ -11,8 +11,6 @@ local conditions = {
local effects = {}
effects["regional_weather:spawn_snow"] = true
effects["climate_api:particles"] = {
min_pos = {x=-20, y= 3, z=-20},
max_pos = {x= 20, y=12, z= 20},

View File

@ -2,11 +2,15 @@ local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local function get_setting_bool(name, default)
return minetest.is_yes(minetest.settings:get_bool("regional_weather_" .. name) or default)
local value = minetest.settings:get_bool("regional_weather_" .. name)
if type(value) == "nil" then value = default end
return minetest.is_yes(value)
end
local function get_setting_number(name, default)
return tonumber(minetest.settings:get("regional_weather_" .. name) or default)
local value = minetest.settings:get("regional_weather_" .. name)
if type(value) == "nil" then value = default end
return tonumber(value)
end
regional_weather = {}
@ -15,6 +19,7 @@ regional_weather.settings.damage = get_setting_bool("damage", true)
regional_weather.settings.snow = get_setting_bool("snow_layers", true)
regional_weather.settings.puddles = get_setting_bool("puddles", true)
regional_weather.settings.soil = get_setting_bool("soil", true)
regional_weather.settings.fire = get_setting_bool("fire", true)
regional_weather.settings.max_height = get_setting_number("max_height", 120)
regional_weather.settings.min_height = get_setting_number("min_height", -50)
@ -31,5 +36,12 @@ dofile(modpath.."/ca_weathers/snow_heavy.lua")
dofile(modpath.."/ca_weathers/storm.lua")
-- register environment effects
dofile(modpath.."/ca_effects/damage.lua")
dofile(modpath.."/ca_effects/lightning.lua")
dofile(modpath.."/ca_effects/speed_buff.lua")
dofile(modpath.."/ca_effects/speed_buff.lua")
-- register ABM cycles and custom nodes
dofile(modpath .. "/abms/puddle.lua")
dofile(modpath .. "/abms/snow_cover.lua")
dofile(modpath .. "/abms/fire.lua")
dofile(modpath .. "/abms/soil.lua")

View File

@ -2,8 +2,8 @@ name = regional_weather
title = Regional Weather
author = TestificateMods
release = 1
depends = climate_api
optional_depends = lightning
depends = default, climate_api
optional_depends = lightning, farming
description = """
Not every biome is the same and neither should their weather be.
Regional Weather controls it's effects with the local climate in mind.

View File

@ -1,6 +1,7 @@
regional_weather_damage (Storms and hail cause damage to players) bool true
regional_weather_snow_layers (Place snow layers on ground) bool true
regional_weather_puddles (Place rain puddles on ground) bool true
regional_weather_soil (Soil turns wet during rain) bool true
regional_weather_soil (Turn farmland wet during rain) bool true
regional_weather_fire (Extinguish fire during rain) bool true
regional_weather_max_height (Maximum height of weather effects) int 120
regional_weather_min_height (Minimum height of weather effects) int -50

Binary file not shown.

Before

Width:  |  Height:  |  Size: 556 B

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 647 B