1
0
Fork 0

Merge pull request 'Fix wolves and make chickens slow fall' (#1614) from jordan4ibanez/MineClone2:mineclone5 into mineclone5

Reviewed-on: MineClone2/MineClone2#1614
This commit is contained in:
jordan4ibanez 2021-04-23 17:07:11 +00:00
commit 3788886518
9 changed files with 113 additions and 12 deletions

View File

@ -355,6 +355,7 @@ function mobs:register_mob(name, def)
hostile_cooldown = def.hostile_cooldown or 15, hostile_cooldown = def.hostile_cooldown or 15,
tilt_fly = def.tilt_fly, tilt_fly = def.tilt_fly,
tilt_swim = def.tilt_swim, tilt_swim = def.tilt_swim,
fall_slow = def.fall_slow,
-- End of MCL2 extensions -- End of MCL2 extensions
on_spawn = def.on_spawn, on_spawn = def.on_spawn,

View File

@ -1,5 +1,7 @@
local math_random = math.random local math_random = math.random
local math_pi = math.pi local math_pi = math.pi
local math_floor = math.floor
local math_round = math.round
local vector_multiply = vector.multiply local vector_multiply = vector.multiply
local vector_add = vector.add local vector_add = vector.add
@ -22,6 +24,12 @@ local quick_rotate = function(self,dtime)
end end
end end
--a simple helper function for rounding
--http://lua-users.org/wiki/SimpleRound
function round2(num, numDecimalPlaces)
return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end
--[[ --[[
_ _ _ _
@ -89,6 +97,21 @@ local land_state_execution = function(self,dtime)
float_now = true float_now = true
end end
--make slow falling mobs fall slow
if self.fall_slow then
if self.object:get_velocity().y < 0 then
--lua is acting really weird so we have to help it
if round2(self.object:get_acceleration().y, 1) == -self.gravity then
self.object:set_acceleration(vector_new(0,0,0))
mobs.mob_fall_slow(self)
end
else
if round2(self.object:get_acceleration().y, 1) == 0 then
self.object:set_acceleration(vector_new(0,-self.gravity,0))
end
end
end
if self.state == "stand" then if self.state == "stand" then
--do animation --do animation
@ -102,6 +125,8 @@ local land_state_execution = function(self,dtime)
mobs.reverse_explosion_animation(self,dtime) mobs.reverse_explosion_animation(self,dtime)
end end
mobs.lock_yaw(self)
elseif self.state == "walk" then elseif self.state == "walk" then
self.walk_timer = self.walk_timer - dtime self.walk_timer = self.walk_timer - dtime
@ -275,6 +300,8 @@ local swim_state_execution = function(self,dtime)
mobs.set_static_pitch(self) mobs.set_static_pitch(self)
end end
mobs.lock_yaw(self)
elseif self.state == "swim" then elseif self.state == "swim" then
self.walk_timer = self.walk_timer - dtime self.walk_timer = self.walk_timer - dtime
@ -307,6 +334,9 @@ local swim_state_execution = function(self,dtime)
if self.tilt_swim then if self.tilt_swim then
mobs.set_dynamic_pitch(self) mobs.set_dynamic_pitch(self)
end end
--enable rotation locking
mobs.movement_rotation_lock(self)
end end
--flop around if not inside swim node --flop around if not inside swim node
else else
@ -415,6 +445,8 @@ local fly_state_execution = function(self,dtime)
mobs.set_static_pitch(self) mobs.set_static_pitch(self)
end end
mobs.lock_yaw(self)
elseif self.state == "fly" then elseif self.state == "fly" then
self.walk_timer = self.walk_timer - dtime self.walk_timer = self.walk_timer - dtime
@ -446,6 +478,10 @@ local fly_state_execution = function(self,dtime)
end end
mobs.set_fly_velocity(self,self.walk_velocity) mobs.set_fly_velocity(self,self.walk_velocity)
--enable rotation locking
mobs.movement_rotation_lock(self)
elseif self.state == "attack" then elseif self.state == "attack" then
--execute mob attack type --execute mob attack type
@ -544,6 +580,8 @@ local jump_state_execution = function(self,dtime)
--set the velocity of the mob --set the velocity of the mob
mobs.set_velocity(self,0) mobs.set_velocity(self,0)
mobs.lock_yaw(self)
elseif self.state == "jump" then elseif self.state == "jump" then
self.walk_timer = self.walk_timer - dtime self.walk_timer = self.walk_timer - dtime

View File

@ -136,6 +136,20 @@ mobs.set_yaw_while_attacking = function(self)
self.yaw = new_yaw self.yaw = new_yaw
end end
--this is used to unlock a mob's yaw after attacking
mobs.unlock_yaw = function(self)
if self.object:get_properties().automatic_face_movement_dir == false then
self.object:set_properties{automatic_face_movement_dir = self.rotate}
end
end
--this is used to lock a mob's yaw when they're standing
mobs.lock_yaw = function(self)
if self.object:get_properties().automatic_face_movement_dir then
self.object:set_properties{automatic_face_movement_dir = false}
end
end
local calculate_pitch = function(self) local calculate_pitch = function(self)
local pos = self.object:get_pos() local pos = self.object:get_pos()

View File

@ -129,7 +129,14 @@ end
mobs.group_attack_initialization = function(self) mobs.group_attack_initialization = function(self)
--get basic data --get basic data
local friends_list = table_copy(self.group_attack) local friends_list
if self.group_attack == true then
friends_list = {self.name}
else
friends_list = table_copy(self.group_attack)
end
local objects_in_area = minetest_get_objects_inside_radius(self.object:get_pos(), self.view_range) local objects_in_area = minetest_get_objects_inside_radius(self.object:get_pos(), self.view_range)
--get the player's name --get the player's name
@ -146,8 +153,8 @@ mobs.group_attack_initialization = function(self)
if detected_mob._cmi_is_mob and detected_mob.state ~= "attack" and detected_mob.owner ~= name then if detected_mob._cmi_is_mob and detected_mob.state ~= "attack" and detected_mob.owner ~= name then
if detected_mob.name == self.name then if detected_mob.name == self.name then
turn_hostile(self,detected_mob) turn_hostile(self,detected_mob)
elseif type(detected_mob.group_attack) == "table" then else
for _,id in pairs(self.group_attack) do for _,id in pairs(friends_list) do
if detected_mob.name == id then if detected_mob.name == id then
turn_hostile(self,detected_mob) turn_hostile(self,detected_mob)
break break

View File

@ -113,8 +113,36 @@ mobs.jump = function(self, velocity)
self.object:add_velocity(vector_new(0,velocity,0)) self.object:add_velocity(vector_new(0,velocity,0))
end end
--make mobs fall slowly
mobs.mob_fall_slow = function(self)
local current_velocity = self.object:get_velocity()
local goal_velocity = {
x = 0,
y = -2,
z = 0,
}
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
new_velocity_addition.x = 0
new_velocity_addition.z = 0
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then
vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition)))
end
new_velocity_addition.x = 0
new_velocity_addition.z = 0
--smooths out mobs a bit
if vector_length(new_velocity_addition) >= 0.0001 then
self.object:add_velocity(new_velocity_addition)
end
end
--[[ --[[

View File

@ -18,6 +18,7 @@ mobs:register_mob("mobs_mc:chicken", {
xp_max = 3, xp_max = 3,
collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.69, 0.2}, collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.69, 0.2},
runaway = true, runaway = true,
fall_slow = true,
floats = 1, floats = 1,
visual = "mesh", visual = "mesh",
mesh = "mobs_mc_chicken.b3d", mesh = "mobs_mc_chicken.b3d",

View File

@ -7,14 +7,22 @@ local S = minetest.get_translator("mobs_mc")
mobs:register_mob("mobs_mc:enderdragon", { mobs:register_mob("mobs_mc:enderdragon", {
type = "monster", type = "monster",
spawn_class = "hostile", spawn_class = "hostile",
pathfinding = 1,
attacks_animals = true, attacks_animals = true,
walk_chance = 100, walk_chance = 100,
rotate = 270,
tilt_fly = true,
hostile = true,
shoot_arrow = function(self, pos, dir)
-- 2-4 damage per arrow
local dmg = math.random(2,4)
mcl_bows.shoot_arrow("mobs_mc:dragon_fireball", pos, dir, self.object:get_yaw(), self.object, nil, dmg)
end,
hp_max = 200, hp_max = 200,
hp_min = 200, hp_min = 200,
xp_min = 500, xp_min = 500,
xp_max = 500, xp_max = 500,
collisionbox = {-2, 3, -2, 2, 5, 2}, collisionbox = {-2, 0, -2, 2, 2, 2},
eye_height = 1,
physical = false, physical = false,
visual = "mesh", visual = "mesh",
mesh = "mobs_mc_dragon.b3d", mesh = "mobs_mc_dragon.b3d",
@ -23,6 +31,7 @@ mobs:register_mob("mobs_mc:enderdragon", {
}, },
visual_size = {x=3, y=3}, visual_size = {x=3, y=3},
view_range = 35, view_range = 35,
reach = 20,
walk_velocity = 6, walk_velocity = 6,
run_velocity = 6, run_velocity = 6,
can_despawn = false, can_despawn = false,
@ -132,10 +141,11 @@ mobs:register_arrow("mobs_mc:dragon_fireball", {
-- node hit, explode -- node hit, explode
hit_node = function(self, pos, node) hit_node = function(self, pos, node)
mobs:boom(self, pos, 2) --mobs:boom(self, pos, 2)
mcl_explosions.explode(self.object:get_pos(), 2,{ drop_chance = 1.0 })
end end
}) })
mobs:register_egg("mobs_mc:enderdragon", S("Ender Dragon"), "mobs_mc_spawn_icon_dragon.png", 0, true) mobs:register_egg("mobs_mc:enderdragon", S("Ender Dragon"), "mobs_mc_spawn_icon_dragon.png", 0, true)
mcl_wip.register_wip_item("mobs_mc:enderdragon") --mcl_wip.register_wip_item("mobs_mc:enderdragon")

View File

@ -114,7 +114,7 @@ mobs:register_arrow("mobs_mc:fireball", {
}, nil) }, nil)
]]-- ]]--
--mobs:boom(self, self.object:get_pos(), 1, true) --mobs:boom(self, self.object:get_pos(), 1, true)
mcl_explosions.explode(self.object:get_pos(), 3,{ drop_chance = 1.0 }) mcl_explosions.explode(self.object:get_pos(), 1,{ drop_chance = 1.0 })
end, end,
hit_mob = function(self, mob) hit_mob = function(self, mob)
@ -123,12 +123,12 @@ mobs:register_arrow("mobs_mc:fireball", {
damage_groups = {fleshy = 6}, damage_groups = {fleshy = 6},
}, nil) }, nil)
--mobs:boom(self, self.object:get_pos(), 1, true) --mobs:boom(self, self.object:get_pos(), 1, true)
mcl_explosions.explode(self.object:get_pos(), 3,{ drop_chance = 1.0 }) mcl_explosions.explode(self.object:get_pos(), 1,{ drop_chance = 1.0 })
end, end,
hit_node = function(self, pos, node) hit_node = function(self, pos, node)
--mobs:boom(self, pos, 1, true) --mobs:boom(self, pos, 1, true)
mcl_explosions.explode(self.object:get_pos(), 3,{ drop_chance = 1.0 }) mcl_explosions.explode(self.object:get_pos(), 1,{ drop_chance = 1.0 })
end end
}) })

View File

@ -22,13 +22,15 @@ local wolf = {
type = "animal", type = "animal",
spawn_class = "passive", spawn_class = "passive",
can_despawn = true, can_despawn = true,
neutral = true,
hp_min = 8, hp_min = 8,
hp_max = 8, hp_max = 8,
xp_min = 1, xp_min = 1,
xp_max = 3, xp_max = 3,
rotate = 270,
passive = false, passive = false,
group_attack = true, group_attack = true,
collisionbox = {-0.3, -0.01, -0.3, 0.3, 0.84, 0.3}, collisionbox = {-0.3, -0.00, -0.3, 0.3, 0.85, 0.3},
visual = "mesh", visual = "mesh",
mesh = "mobs_mc_wolf.b3d", mesh = "mobs_mc_wolf.b3d",
textures = { textures = {
@ -52,7 +54,7 @@ local wolf = {
run_velocity = 3, run_velocity = 3,
damage = 4, damage = 4,
reach = 2, reach = 2,
attack_type = "dogfight", attack_type = "punch",
fear_height = 4, fear_height = 4,
follow = mobs_mc.follow.wolf, follow = mobs_mc.follow.wolf,
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)