1
0
Fork 0

Merge pull request 'Make every mob besides spiders get slowed down by cobwebs like players' (#1643) from jordan4ibanez/MineClone2:mineclone5 into mineclone5

Reviewed-on: MineClone2/MineClone2#1643
This commit is contained in:
jordan4ibanez 2021-04-25 03:34:44 +00:00
commit 24df0271d4
5 changed files with 45 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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