forked from VoxeLibre/VoxeLibre
Make every mob besides spiders get slowed down by cobwebs like players
This commit is contained in:
parent
7e8e63b0e3
commit
079811984c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue