From 060c153c7828cf062acb7c7b41dfdbb515537122 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Sun, 26 Feb 2023 13:24:06 -0300 Subject: [PATCH] added wind support from climate_api --- init.lua | 1 + wind.lua | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 wind.lua diff --git a/init.lua b/init.lua index b6839c7..6f5667b 100644 --- a/init.lua +++ b/init.lua @@ -32,6 +32,7 @@ end if not minetest.settings:get_bool('airutils.disable_repair') then dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_repair.lua") end +airutils.get_wind = dofile(minetest.get_modpath("airutils") .. DIR_DELIM ..'/wind.lua') dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "inventory_management.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "light.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "physics_lib.lua") diff --git a/wind.lua b/wind.lua new file mode 100644 index 0000000..0b4d80a --- /dev/null +++ b/wind.lua @@ -0,0 +1,58 @@ +--[[ +MIT License + +Copyright (c) 2019 TheTermos, TestificateMods + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +]]-- + +local get_wind + +if minetest.get_modpath("climate_api") then + get_wind = function(pos, multiplier) + multiplier = multiplier or 0.1 + local wind = climate_api.environment.get_wind({x=0,y=0,z=0}) + return vector.multiply(wind, multiplier) + end + +else + local yaw = math.random()*math.pi*2-math.pi + airutils.wind={} + airutils.wind.wind = vector.multiply(minetest.yaw_to_dir(yaw),4) + airutils.wind.timer = 0 + airutils.wind.ttime = math.random()*5*60+1*60 + + get_wind = function(pos, multiplier) + local retVal = vector.multiply(airutils.wind.wind, multiplier) + return retVal + end + + minetest.register_globalstep( + function(dtime) + airutils.wind.timer=airutils.wind.timer+dtime + if airutils.wind.timer >= airutils.wind.ttime then + local yaw = minetest.dir_to_yaw(airutils.wind.wind) + local yaw = yaw+math.random()-0.5 + airutils.wind.wind = vector.multiply(minetest.yaw_to_dir(yaw),4) + airutils.wind.ttime = wind.timer+math.random()*5*60+1*60 + end + end) +end + +return get_wind