From 079811984cd952714e6cf85297c91830c0790a1d Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sat, 24 Apr 2021 23:29:56 -0400 Subject: [PATCH] Make every mob besides spiders get slowed down by cobwebs like players --- mods/ENTITIES/mcl_mobs/api/api.lua | 2 ++ .../mcl_mobs/api/mob_functions/ai.lua | 24 +++++++++++++++++++ .../mcl_mobs/api/mob_functions/movement.lua | 15 ++++++++++++ mods/ENTITIES/mobs_mc/spider.lua | 1 + 4 files changed, 42 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 4cc49e322..f1497c474 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -359,6 +359,8 @@ function mobs:register_mob(name, def) --fire timer burn_timer = 0, + + ignores_cobwebs = def.ignores_cobwebs, --end j4i stuff -- MCL2 extensions diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index a2e48ba2a..b79eaf665 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -1035,6 +1035,30 @@ mobs.mob_step = function(self, dtime) mobs.collision(self) end + --overrides absolutely everything + --mobs get stuck in cobwebs like players + if not self.ignores_cobwebs then + + local pos = self.object:get_pos() + local node = minetest_get_node(pos).name + + if node == "mcl_core:cobweb" then + + --fight the rest of the api + if self.object:get_acceleration().y ~= 0 then + self.object:set_acceleration(vector_new(0,0,0)) + end + + mobs.stick_in_cobweb(self) + + else + --return the mob back to normal + if self.object:get_acceleration().y == 0 and not self.swim and not self.fly then + self.object:set_acceleration(vector_new(0,-self.gravity,0)) + end + end + end + self.old_velocity = self.object:get_velocity() self.old_pos = self.object:get_pos() end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua index 916563832..dbc984819 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua @@ -10,6 +10,7 @@ local vector_new = vector.new local vector_length = vector.length local vector_multiply = vector.multiply local vector_distance = vector.distance +local vector_normalize = vector.normalize local minetest_yaw_to_dir = minetest.yaw_to_dir local minetest_dir_to_yaw = minetest.dir_to_yaw @@ -19,6 +20,20 @@ local DEFAULT_FLOAT_SPEED = 4 local DEFAULT_CLIMB_SPEED = 3 +mobs.stick_in_cobweb = function(self) + local current_velocity = self.object:get_velocity() + + local goal_velocity = vector_multiply(vector_normalize(current_velocity), 0.4) + + goal_velocity.y = -0.5 + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end +end --this is a generic float function mobs.float = function(self) diff --git a/mods/ENTITIES/mobs_mc/spider.lua b/mods/ENTITIES/mobs_mc/spider.lua index 09cbba5a7..67de9250d 100644 --- a/mods/ENTITIES/mobs_mc/spider.lua +++ b/mods/ENTITIES/mobs_mc/spider.lua @@ -26,6 +26,7 @@ local spider = { reach = 2, hp_min = 16, hp_max = 16, + ignores_cobwebs = true, xp_min = 5, xp_max = 5, eye_height = 0.475,