From d65b80fa51478bdc03b7c022f258c07f9d828091 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Sun, 28 Jun 2020 20:36:38 +0100 Subject: [PATCH] fluid viscocity checks standing node against fly_in table/string --- api.lua | 28 +++++++++++++++++++++++++--- readme.MD | 4 ++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/api.lua b/api.lua index 2aff851..d6ac467 100644 --- a/api.lua +++ b/api.lua @@ -228,6 +228,28 @@ function mob_class:collision() end +-- check string against another string or table +local check_for = function(look_for, look_inside) + + if type(look_inside) == "string" and look_inside == look_for then + + return true + + elseif type(look_inside) == "table" then + + for _, str in pairs(look_inside) do + + if str == look_for then + + return true + end + end + end + + return false +end + + -- move mob in facing direction function mob_class:set_velocity(v) @@ -263,9 +285,9 @@ function mob_class:set_velocity(v) -- check if standing in water and use liquid viscocity to slow mob local visc = minetest.registered_nodes[self.standing_in].liquid_viscosity - -- assume any mob not flying will slow down in water as mobs flying in air - -- wont be near water, and mobs flying in water will swim at full speed - if not self.fly_in and (visc and visc > 0) then + -- if mob standing inside fluid with viscocity which isn't in self.fly_in + -- then slow down mob accordingly + if visc and visc > 0 and not check_for(self.standing_in, self.fly_in)then new_vel.x = new_vel.x ~= 0 and new_vel.x / visc or 0 new_vel.y = new_vel.y ~= 0 and new_vel.y / visc or 0 diff --git a/readme.MD b/readme.MD index 12869c4..d6982e8 100644 --- a/readme.MD +++ b/readme.MD @@ -23,8 +23,8 @@ Lucky Blocks: 9 Changelog: -- 1.52 - Added 'mob_active_limit' in settings to set number of mobs in game -(default is 0 for unlimited), removed {immortal} from mob armor +- 1.52 - Added 'mob_active_limit' in settings to set number of mobs in game +(default is 0 for unlimited), removed {immortal} from mob armor, fluid viscocity slows mobs - 1.51 - Added some node checks for dangerous nodes, jumping and falling tweaks, spawn area check (thx for idea wuzzy), re-enabled mob suffocation, add 'mob_nospawn_range' setting - 1.50 - Added new line_of_sight function that uses raycasting if mt5.0 is found, (thanks Astrobe), dont spawn mobs if world anchor nearby (technic or simple_anchor mods), chinese local added - 1.49- Added mobs:force_capture(self, player) function, api functions now use metatables thanks to bell07