From 5b5cbb32746eb59e042d6908b1fc55d1d2248cef Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Sun, 26 Feb 2023 18:14:08 -0300 Subject: [PATCH] added a wind indicator --- airutils_wind.lua | 193 +++++++++++++++++++++++++++++++++++++++ init.lua | 1 + models/airutils_wind.b3d | Bin 0 -> 12669 bytes 3 files changed, 194 insertions(+) create mode 100644 airutils_wind.lua create mode 100755 models/airutils_wind.b3d diff --git a/airutils_wind.lua b/airutils_wind.lua new file mode 100644 index 0000000..52c6926 --- /dev/null +++ b/airutils_wind.lua @@ -0,0 +1,193 @@ +local function check_protection(pos, name) + if minetest.is_protected(pos, name) then + minetest.log("action", name + .. " tried to place a Wind Indicator" + .. " at protected position " + .. minetest.pos_to_string(pos) + ) + minetest.record_protection_violation(pos, name) + return true + end + return false +end + +function airutils.WindDplace(player,pos) + if not player then + return + end + + local dir = minetest.dir_to_facedir(vector.new()) + local pos1 = vector.new(pos) + + local player_name = player:get_player_name() + if check_protection(pos, player_name) then + return + end + + core.set_node(pos1, {name="airutils:wind", param2=dir}) + local meta = core.get_meta(pos) + meta:set_string("infotext", "Wind Indicator\rOwned by: "..player_name) + meta:set_string("owner", player_name) + meta:set_string("dont_destroy", "false") + return true +end + +airutils.wind_collision_box = { + type = "fixed", + fixed={{-0.5,0,-0.5,0.5,5.0,0.5},}, +} + +airutils.wind_selection_box = { + type = "fixed", + fixed={{-0.5,0,-0.5,0.5,5.0,0.5},}, +} + +local function get_smooth(angle_initial, reference, last_ref, value) + local range = reference-last_ref + local retVal = (value*angle_initial)/range + retval = angle_initial - retVal + if retval < 0 then retval = 0 end + return retval +end + +minetest.register_entity("airutils:wind_indicator",{ + -- common props + physical = true, + stepheight = 0.5, + collide_with_objects = true, + collisionbox = {-0.5, 0, -0.5, 0.5, 5.0, 0.5}, + visual = "mesh", + mesh = "airutils_wind.b3d", + textures = {"airutils_red.png", "airutils_black.png", "airutils_white.png", "airutils_metal.png"}, + static_save = true, + makes_footstep_sound = false, + _pos = nil, + + on_activate = function(self, staticdata, dtime_s) + self._pos = self.object:get_pos() + end, + + on_step = function(self,dtime,colinfo) + self.object:set_pos(self._pos) + + local wind = airutils.get_wind(pos, 2.0) + local wind_yaw = minetest.dir_to_yaw(wind) + self.object:set_bone_position("ajuste", {x=0,y=42,z=0}, {x=0,y=0,z=90}) + self.object:set_bone_position("b_a", {x=0,y=0,z=0}, {x=math.deg(wind_yaw),y=0,z=0}) + + local false_div = 1 --trying to make it more o minus sensible + local vel = ((vector.dot(vector.multiply(wind,dtime),wind))/false_div)*100 + --minetest.chat_send_all(vel) + local b_b = 65 + if vel > 11 then + b_b = get_smooth(65, 11, 0, vel) + end + self.object:set_bone_position("b_b", {x=0,y=8.25,z=0}, {x=0,y=0,z=-b_b}) + + local b_c = 15 + if vel > 16 then + b_c = get_smooth(15, 16, 11, vel) + end + self.object:set_bone_position("b_c", {x=0,y=6.0,z=0}, {x=0,y=0,z=-b_c}) + + local b_d = 5 + if vel > 22 then + b_d = get_smooth(5, 22, 16, vel) + end + self.object:set_bone_position("b_d", {x=0,y=4.5,z=0}, {x=0,y=0,z=-b_d}) + + local b_e = 2 + if vel > 28 then + b_e = get_smooth(2, 28, 22, vel) + end + self.object:set_bone_position("b_e", {x=0,y=3,z=0}, {x=0,y=0,z=-b_e}) + + --minetest.chat_send_all("Wind Direction: "..math.deg(wind_yaw)) + end, -- required + --on_activate = mobkit.actfunc, -- required + --get_staticdata = mobkit.statfunc, + max_hp = 65535, + timeout = 0, + on_punch=function(self, puncher) + return + end, + + on_rightclick = function(self, clicker) + local wind = airutils.get_wind(pos, 2.0) + local wind_yaw = minetest.dir_to_yaw(wind) + minetest.chat_send_player(clicker:get_player_name(),core.colorize('#00ff00', " >>> The wind direction now is "..math.deg(wind_yaw))) + return + end, + +}) + + + +-- Wind Indicator node (default left) +minetest.register_node("airutils:wind",{ + description = "Wind Direction Indicator", + waving = 1, + tiles = {"default_tin_block.png","default_tin_block.png","default_tin_block.png","default_tin_block.png","default_tin_block.png","default_tin_block.png"}, + paramtype = "light", + paramtype2 = "leveled", + is_ground_content = false, + groups = {cracky = 1, level = 2}, + walkable = true, + selection_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + {-0.1, 0.5, -0.1, 0.1, 2.0, 0.1} + } + }, + + node_dig_prediction = "default:dirt", + node_placement_prediction = "airutils:wind", + + on_place = function(itemstack, placer, pointed_thing) + + local pos = pointed_thing.above + + local player_name = placer:get_player_name() + + + if not minetest.is_protected(pos, player_name) and not minetest.is_protected(pos, player_name) then + minetest.set_node(pos, {name = "airutils:wind",param2 = 1 }) + minetest.add_entity({x=pos.x, y=pos.y, z=pos.z},"airutils:wind_indicator") + local meta = minetest.get_meta(pos) + if not (creative and creative.is_enabled_for and creative.is_enabled_for(player_name)) then + itemstack:take_item() + end + else + minetest.chat_send_player(player_name, "Node is protected") + minetest.record_protection_violation(pos, player_name) + end + + + return itemstack + end, + + on_destruct = function(pos) + local meta=minetest.get_meta(pos) + if meta then + local cpos = {x=pos.x, y= pos.y, z=pos.z} + local object = minetest.get_objects_inside_radius(cpos, 1) + for _,obj in ipairs(object) do + local entity = obj:get_luaentity() + if entity and entity.name == "airutils:wind_indicator" then + obj:remove() + end + end + end + end, +}) + +-- WIND craft +minetest.register_craft({ + output = 'airutils:wind', + recipe = { + {'wool:white', 'wool:white', 'wool:white'}, + {'wool:white', 'default:steel_ingot' , 'wool:white'}, + {'' , 'default:steel_ingot' , ''}, + } +}) diff --git a/init.lua b/init.lua index 028a210..5d9428f 100644 --- a/init.lua +++ b/init.lua @@ -33,6 +33,7 @@ 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 .. "airutils_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/models/airutils_wind.b3d b/models/airutils_wind.b3d new file mode 100755 index 0000000000000000000000000000000000000000..e2ad3ad793fe5933bf15d6426fffe5bdda04f7ba GIT binary patch literal 12669 zcmeHNTaZ=773~>De4)G?#b9($1cE4|gQ!7nUq*-^uaV*9llM!|LBO}h=Aj~@A_z#C zq^y{#u!P{sVm{G=+C z?z4OMxqEsJ)85`T_nF(BYjDoBFI&<1GcfJ0UF)9OvdQ(FUE~v-3m%`ukIB6l>vyc% zuzkR*p4+-@&%kp%xo-EKU0nlCwq)ttd4FnkZrReM%b7-QFuy#qj~Fz5nsXbvp4ybD z(aHzd0@DSH=XK8iWTY*0<+A0S|GL~hVSO5b|Mqs3d(Jku|GU?BJNHqEH#e;^XIK^0M zt$vu>8Rr}2%34R#n%gri_~WM*l-t_IX>A?;C#SwF{q)p=3N^c~BhGhHTBG|_#WtkX zf2i1RdVd);##&v9>#fhZHW%hxDb?3L)u33HV(qPd^?MX%7i+*>3bXU;-MV>_|KQXM zu?AZ<-yUl~ZR_TlHG6I~E#_ynXRR2^T77V8Ta3-uj~ee`xun|f#Ck)`9#L!ceZ}^b zb6>gibq~hYuC1?}i?y;`iZ!(w+!uD*Y4a#e9tSfznIo4&7P}FV?Ur)_E{`7#`dRi zzAU!EmC>*An)9YHmo#60T3@k+oJ-k!8`IkQ(TcIzdKt_0vPaj}Dz7nThZ^*kbD_>P zwP$Qle#NzAx$quqnTu+la;BD#O*seLVJZgF()c~>7Zk5Khg`AdRxtA%HTH4=l z(>Pxi+u%lFfAbpaLXEkk`TEoPiY?@fTBZ4_YwJfV#@5$>dzsdj=F4l$Iqh${Z(r+3 zv9+~N`&(a^EEmp~_BX#rX@65J?-BQ{^i6MfchA}DQPWSgN5PvmRhsQ@rlr`ju48P< zxj&8bWwDK}fmdv z9a%2L`D}mts!Ns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