diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 4cc49e3222..f1497c4741 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 a2e48ba2ae..b79eaf665d 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 9165638320..dbc9848198 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 09cbba5a7f..67de9250d8 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, diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index ab79edfec0..e6892253e0 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -961,9 +961,11 @@ mobs:register_mob("mobs_mc:villager", { }, }, visual_size = {x=2.75, y=2.75}, + rotate = 270, + skittish = true, makes_footstep_sound = true, walk_velocity = 1.2, - run_velocity = 2.4, + run_velocity = 3, drops = {}, can_despawn = false, -- TODO: sounds