2020-04-24 01:36:58 +02:00
|
|
|
local BLOCK_PREFIX = "regional_weather:puddle_"
|
2020-04-25 15:50:45 +02:00
|
|
|
local VARIANT_COUNT = 39
|
2020-05-29 21:53:33 +02:00
|
|
|
local CHECK_DISTANCE = 4
|
|
|
|
local MAX_AMOUNT = 3
|
2020-04-16 19:13:14 +02:00
|
|
|
|
2020-05-13 16:05:21 +02:00
|
|
|
local GROUND_COVERS = {
|
|
|
|
"group:soil",
|
|
|
|
"group:stone",
|
|
|
|
"group:sand",
|
|
|
|
"group:wood",
|
|
|
|
"default:permafrost",
|
|
|
|
"default:permafrost_with_moss",
|
|
|
|
"default:permafrost_with_stones"
|
|
|
|
}
|
|
|
|
|
2020-05-29 22:02:12 +02:00
|
|
|
local S = regional_weather.i18n
|
|
|
|
|
2020-05-29 21:53:33 +02:00
|
|
|
-- clean up puddles if disabled
|
2020-04-16 19:13:14 +02:00
|
|
|
if not regional_weather.settings.puddles then
|
2020-05-29 21:53:33 +02:00
|
|
|
-- set all puddle nodes to air
|
|
|
|
minetest.register_alias("regional_weather:puddle", "air")
|
|
|
|
for i = 1, VARIANT_COUNT do
|
|
|
|
for flip = 0, 1 do
|
|
|
|
local name = BLOCK_PREFIX .. i
|
|
|
|
if flip == 1 then
|
|
|
|
name = name .. "_flipped"
|
|
|
|
end
|
|
|
|
minetest.register_alias(name, "air")
|
2020-04-24 01:36:58 +02:00
|
|
|
end
|
|
|
|
end
|
2020-05-29 21:53:33 +02:00
|
|
|
|
|
|
|
-- return air instead of a puddle
|
|
|
|
function regional_weather.get_random_puddle()
|
|
|
|
return { name = "air" }
|
|
|
|
end
|
|
|
|
|
|
|
|
-- end puddle execution
|
2020-04-16 19:13:14 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local node_box = {
|
|
|
|
type = "fixed",
|
2020-05-29 21:53:33 +02:00
|
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, -0.49, 0.5 }
|
2020-04-16 19:13:14 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 05:02:01 +02:00
|
|
|
local apply_water_group
|
|
|
|
if regional_weather.settings.puddles_water then
|
|
|
|
apply_water_group = 1
|
|
|
|
end
|
|
|
|
|
2020-05-29 21:53:33 +02:00
|
|
|
for i = 1, VARIANT_COUNT do
|
|
|
|
for flip = 0, 1 do
|
2020-05-13 16:05:21 +02:00
|
|
|
local name = BLOCK_PREFIX .. i
|
|
|
|
local index = i
|
|
|
|
if i < 10 then index = "0" .. i end
|
|
|
|
local texture = "weather_puddle_" .. index .. ".png^[opacity:128"
|
|
|
|
if flip == 1 then
|
|
|
|
name = name .. "_flipped"
|
|
|
|
texture = texture .. "^[transformFX"
|
2020-04-24 01:36:58 +02:00
|
|
|
end
|
2020-05-13 16:05:21 +02:00
|
|
|
minetest.register_node(name, {
|
2020-05-29 22:02:12 +02:00
|
|
|
description = S("Puddle"),
|
2020-05-13 16:05:21 +02:00
|
|
|
tiles = { texture },
|
|
|
|
drawtype = "nodebox",
|
|
|
|
pointable = false,
|
|
|
|
buildable_to = true,
|
|
|
|
floodable = true,
|
|
|
|
walkable = false,
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
use_texture_alpha = true,
|
|
|
|
node_box = node_box,
|
|
|
|
groups = {
|
|
|
|
not_in_creative_inventory = 1,
|
|
|
|
crumbly = 3,
|
|
|
|
attached_node = 1,
|
|
|
|
slippery = 1,
|
|
|
|
flora = 1,
|
2020-05-16 05:02:01 +02:00
|
|
|
water = apply_water_group,
|
2020-05-13 16:05:21 +02:00
|
|
|
weather_puddle = 1
|
|
|
|
},
|
|
|
|
drop = "",
|
|
|
|
sounds = {
|
|
|
|
footstep = {
|
|
|
|
name = "weather_puddle",
|
|
|
|
gain = 0.8
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-04-24 01:36:58 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-13 16:05:21 +02:00
|
|
|
minetest.register_alias("regional_weather:puddle", BLOCK_PREFIX .. "14")
|
2020-04-24 01:36:58 +02:00
|
|
|
|
2020-05-29 21:53:33 +02:00
|
|
|
function regional_weather.get_random_puddle()
|
2020-04-24 01:36:58 +02:00
|
|
|
local index = math.random(1, VARIANT_COUNT)
|
|
|
|
local rotation = math.random(0, 3) * 90
|
|
|
|
local flip = math.random(0, 1)
|
2020-05-13 16:05:21 +02:00
|
|
|
local name = BLOCK_PREFIX .. index
|
2020-04-24 01:36:58 +02:00
|
|
|
if flip == 1 then
|
|
|
|
name = name .. "_flipped"
|
|
|
|
end
|
2020-05-13 16:05:21 +02:00
|
|
|
local param2 = minetest.dir_to_facedir(minetest.yaw_to_dir(rotation))
|
|
|
|
return { name = name, param2 = param2 }
|
2020-04-24 01:36:58 +02:00
|
|
|
end
|
2020-04-16 19:13:14 +02:00
|
|
|
|
|
|
|
-- Makes Puddles when raining
|
|
|
|
climate_api.register_abm({
|
|
|
|
label = "create rain puddles",
|
2020-05-13 16:05:21 +02:00
|
|
|
nodenames = GROUND_COVERS,
|
2020-04-16 19:13:14 +02:00
|
|
|
neighbors = { "air" },
|
2020-05-13 16:05:21 +02:00
|
|
|
interval = 8,
|
|
|
|
chance = 150,
|
2020-04-24 01:36:58 +02:00
|
|
|
catch_up = false,
|
2020-04-16 19:13:14 +02:00
|
|
|
|
|
|
|
conditions = {
|
|
|
|
min_height = regional_weather.settings.min_height,
|
|
|
|
max_height = regional_weather.settings.max_height,
|
|
|
|
min_humidity = 55,
|
|
|
|
min_heat = 30,
|
2020-04-18 17:26:01 +02:00
|
|
|
daylight = 15
|
2020-04-16 19:13:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
pos_override = function(pos)
|
|
|
|
return vector.add(pos, { x = 0, y = 1, z = 0 })
|
|
|
|
end,
|
|
|
|
|
|
|
|
action = function (pos, node, env)
|
2020-05-29 21:53:33 +02:00
|
|
|
-- only override air nodes
|
2020-04-16 19:13:14 +02:00
|
|
|
if minetest.get_node(pos).name ~= "air" then return end
|
2020-05-29 21:53:33 +02:00
|
|
|
-- do not place puddle if area is not fully loaded
|
|
|
|
if minetest.find_node_near(pos, CHECK_DISTANCE, "ignore") then return end
|
|
|
|
-- do not place puddle if already enpugh puddles
|
|
|
|
local pos1 = vector.add(pos, { x = -CHECK_DISTANCE, y = -1, z = -CHECK_DISTANCE })
|
|
|
|
local pos2 = vector.add(pos, { x = CHECK_DISTANCE, y = 1, z = CHECK_DISTANCE })
|
|
|
|
local preplaced = minetest.find_nodes_in_area(pos1, pos2, "group:weather_puddle")
|
|
|
|
if preplaced ~= nil and #preplaced >= MAX_AMOUNT then return end
|
|
|
|
minetest.set_node(pos, regional_weather.get_random_puddle())
|
2020-04-16 19:13:14 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Makes puddles dry up when not raining
|
|
|
|
climate_api.register_abm({
|
|
|
|
label = "remove rain puddles",
|
2020-05-29 21:53:33 +02:00
|
|
|
nodenames = { "group:weather_puddle" },
|
2020-10-08 15:42:43 +02:00
|
|
|
interval = 25,
|
|
|
|
chance = 30,
|
2020-04-24 01:36:58 +02:00
|
|
|
catch_up = true,
|
2020-04-16 19:13:14 +02:00
|
|
|
|
|
|
|
action = function (pos, node, env)
|
2020-10-08 15:42:43 +02:00
|
|
|
minetest.remove_node(pos)
|
2020-04-16 19:13:14 +02:00
|
|
|
end
|
2020-04-24 01:36:58 +02:00
|
|
|
})
|