mcl_mobs: actually use the localized functions
not that it actually gains *a lot*
This commit is contained in:
parent
51e244fe35
commit
87d4640ca1
|
@ -29,6 +29,7 @@ local max = math.max
|
||||||
local atann = math.atan
|
local atann = math.atan
|
||||||
local random = math.random
|
local random = math.random
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
|
local ceil = math.ceil
|
||||||
|
|
||||||
local atan = function(x)
|
local atan = function(x)
|
||||||
if not x or x ~= x then
|
if not x or x ~= x then
|
||||||
|
@ -38,7 +39,6 @@ local atan = function(x)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Load settings
|
-- Load settings
|
||||||
local damage_enabled = minetest.settings:get_bool("enable_damage")
|
local damage_enabled = minetest.settings:get_bool("enable_damage")
|
||||||
local disable_blood = minetest.settings:get_bool("mobs_disable_blood")
|
local disable_blood = minetest.settings:get_bool("mobs_disable_blood")
|
||||||
|
@ -147,7 +147,7 @@ local mob_sound = function(self, soundname, is_opinion, fixed_pitch)
|
||||||
pitch = base_pitch
|
pitch = base_pitch
|
||||||
end
|
end
|
||||||
-- randomize the pitch a bit
|
-- randomize the pitch a bit
|
||||||
pitch = pitch + math.random(-10, 10) * 0.005
|
pitch = pitch + random(-10, 10) * 0.005
|
||||||
end
|
end
|
||||||
minetest.sound_play(sound, {
|
minetest.sound_play(sound, {
|
||||||
object = self.object,
|
object = self.object,
|
||||||
|
@ -280,7 +280,7 @@ local function update_roll(self)
|
||||||
local cbox = table.copy(self.collisionbox)
|
local cbox = table.copy(self.collisionbox)
|
||||||
local acbox = self.object:get_properties().collisionbox
|
local acbox = self.object:get_properties().collisionbox
|
||||||
|
|
||||||
if math.abs(cbox[2] - acbox[2]) > 0.1 then
|
if abs(cbox[2] - acbox[2]) > 0.1 then
|
||||||
was_Fleckenstein = true
|
was_Fleckenstein = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ local set_yaw = function(self, yaw, delay, dtime)
|
||||||
|
|
||||||
if delay == 0 then
|
if delay == 0 then
|
||||||
if self.shaking and dtime then
|
if self.shaking and dtime then
|
||||||
yaw = yaw + (math.random() * 2 - 1) * 5 * dtime
|
yaw = yaw + (random() * 2 - 1) * 5 * dtime
|
||||||
end
|
end
|
||||||
self.object:set_yaw(yaw)
|
self.object:set_yaw(yaw)
|
||||||
update_roll(self)
|
update_roll(self)
|
||||||
|
@ -584,7 +584,7 @@ local damage_effect = function(self, damage)
|
||||||
-- damage particles
|
-- damage particles
|
||||||
if (not disable_blood) and damage > 0 then
|
if (not disable_blood) and damage > 0 then
|
||||||
|
|
||||||
local amount_large = math.floor(damage / 2)
|
local amount_large = floor(damage / 2)
|
||||||
local amount_small = damage % 2
|
local amount_small = damage % 2
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
@ -710,7 +710,7 @@ local item_drop = function(self, cooked, looting_level)
|
||||||
end
|
end
|
||||||
|
|
||||||
if do_common_looting then
|
if do_common_looting then
|
||||||
num = num + math.floor(math.random(0, looting_level) + 0.5)
|
num = num + floor(random(0, looting_level) + 0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
if num > 0 then
|
if num > 0 then
|
||||||
|
@ -819,7 +819,7 @@ local check_for_death = function(self, cause, cmi_cause)
|
||||||
item_drop(self, cooked, looting)
|
item_drop(self, cooked, looting)
|
||||||
|
|
||||||
if ((not self.child) or self.type ~= "animal") and (minetest.get_us_time() - self.xp_timestamp <= 5000000) then
|
if ((not self.child) or self.type ~= "animal") and (minetest.get_us_time() - self.xp_timestamp <= 5000000) then
|
||||||
mcl_experience.throw_xp(self.object:get_pos(), math.random(self.xp_min, self.xp_max))
|
mcl_experience.throw_xp(self.object:get_pos(), random(self.xp_min, self.xp_max))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1200,7 +1200,7 @@ local do_env_damage = function(self)
|
||||||
end
|
end
|
||||||
if drowning then
|
if drowning then
|
||||||
|
|
||||||
self.breath = math.max(0, self.breath - 1)
|
self.breath = max(0, self.breath - 1)
|
||||||
|
|
||||||
effect(pos, 2, "bubble.png", nil, nil, 1, nil)
|
effect(pos, 2, "bubble.png", nil, nil, 1, nil)
|
||||||
if self.breath <= 0 then
|
if self.breath <= 0 then
|
||||||
|
@ -1218,7 +1218,7 @@ local do_env_damage = function(self)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self.breath = math.min(self.breath_max, self.breath + 1)
|
self.breath = min(self.breath_max, self.breath + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1544,7 +1544,7 @@ local breed = function(self)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
mcl_experience.throw_xp(pos, math.random(1, 7))
|
mcl_experience.throw_xp(pos, random(1, 7))
|
||||||
|
|
||||||
-- custom breed function
|
-- custom breed function
|
||||||
if parent1.on_breed then
|
if parent1.on_breed then
|
||||||
|
@ -1560,7 +1560,7 @@ local breed = function(self)
|
||||||
|
|
||||||
|
|
||||||
-- Use texture of one of the parents
|
-- Use texture of one of the parents
|
||||||
local p = math.random(1, 2)
|
local p = random(1, 2)
|
||||||
if p == 1 then
|
if p == 1 then
|
||||||
ent_c.base_texture = parent1.base_texture
|
ent_c.base_texture = parent1.base_texture
|
||||||
else
|
else
|
||||||
|
@ -1722,7 +1722,7 @@ local smart_mobs = function(self, s, p, dist, dtime)
|
||||||
end, self)
|
end, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
if math.abs(vector.subtract(s,target_pos).y) > self.stepheight then
|
if abs(vector.subtract(s,target_pos).y) > self.stepheight then
|
||||||
|
|
||||||
if height_switcher then
|
if height_switcher then
|
||||||
use_pathfind = true
|
use_pathfind = true
|
||||||
|
@ -1763,7 +1763,7 @@ local smart_mobs = function(self, s, p, dist, dtime)
|
||||||
if self.fear_height ~= 0 then dropheight = self.fear_height end
|
if self.fear_height ~= 0 then dropheight = self.fear_height end
|
||||||
local jumpheight = 0
|
local jumpheight = 0
|
||||||
if self.jump and self.jump_height >= 4 then
|
if self.jump and self.jump_height >= 4 then
|
||||||
jumpheight = math.min(math.ceil(self.jump_height / 4), 4)
|
jumpheight = min(ceil(self.jump_height / 4), 4)
|
||||||
elseif self.stepheight > 0.5 then
|
elseif self.stepheight > 0.5 then
|
||||||
jumpheight = 1
|
jumpheight = 1
|
||||||
end
|
end
|
||||||
|
@ -1794,7 +1794,7 @@ local smart_mobs = function(self, s, p, dist, dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local sheight = math.ceil(self.collisionbox[5]) + 1
|
local sheight = ceil(self.collisionbox[5]) + 1
|
||||||
|
|
||||||
-- assume mob is 2 blocks high so it digs above its head
|
-- assume mob is 2 blocks high so it digs above its head
|
||||||
s.y = s.y + sheight
|
s.y = s.y + sheight
|
||||||
|
@ -2232,9 +2232,9 @@ local follow_flop = function(self)
|
||||||
if sdef and sdef.walkable then
|
if sdef and sdef.walkable then
|
||||||
mob_sound(self, "flop")
|
mob_sound(self, "flop")
|
||||||
self.object:set_velocity({
|
self.object:set_velocity({
|
||||||
x = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
|
x = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
|
||||||
y = FLOP_HEIGHT,
|
y = FLOP_HEIGHT,
|
||||||
z = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
|
z = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2289,8 +2289,8 @@ local function go_to_pos(entity,b)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local v = { x = b.x - s.x, z = b.z - s.z }
|
local v = { x = b.x - s.x, z = b.z - s.z }
|
||||||
local yaw = (math.atan(v.z / v.x) + math.pi / 2) - entity.rotate
|
local yaw = (atann(v.z / v.x) + pi / 2) - entity.rotate
|
||||||
if b.x > s.x then yaw = yaw + math.pi end
|
if b.x > s.x then yaw = yaw + pi end
|
||||||
entity.object:set_yaw(yaw)
|
entity.object:set_yaw(yaw)
|
||||||
set_velocity(entity,entity.follow_velocity)
|
set_velocity(entity,entity.follow_velocity)
|
||||||
mcl_mobs:set_animation(entity, "walk")
|
mcl_mobs:set_animation(entity, "walk")
|
||||||
|
@ -3474,7 +3474,7 @@ local mob_activate = function(self, staticdata, def, dtime)
|
||||||
local c = 1
|
local c = 1
|
||||||
if #def.textures > c then c = #def.textures end
|
if #def.textures > c then c = #def.textures end
|
||||||
|
|
||||||
self.base_texture = def.textures[math.random(c)]
|
self.base_texture = def.textures[random(c)]
|
||||||
self.base_mesh = def.mesh
|
self.base_mesh = def.mesh
|
||||||
self.base_size = self.visual_size
|
self.base_size = self.visual_size
|
||||||
self.base_colbox = self.collisionbox
|
self.base_colbox = self.collisionbox
|
||||||
|
@ -3688,7 +3688,7 @@ local mob_step = function(self, dtime)
|
||||||
|
|
||||||
self.delay = self.delay - 1
|
self.delay = self.delay - 1
|
||||||
if self.shaking then
|
if self.shaking then
|
||||||
yaw = yaw + (math.random() * 2 - 1) * 5 * dtime
|
yaw = yaw + (random() * 2 - 1) * 5 * dtime
|
||||||
end
|
end
|
||||||
self.object:set_yaw(yaw)
|
self.object:set_yaw(yaw)
|
||||||
update_roll(self)
|
update_roll(self)
|
||||||
|
@ -3843,7 +3843,7 @@ local mob_step = function(self, dtime)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
elseif self.lifetimer <= 10 then
|
elseif self.lifetimer <= 10 then
|
||||||
if math.random(10) < 4 then
|
if random(10) < 4 then
|
||||||
self.despawn_immediately = true
|
self.despawn_immediately = true
|
||||||
else
|
else
|
||||||
self.lifetimer = 20
|
self.lifetimer = 20
|
||||||
|
@ -4516,7 +4516,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 47)) do
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 47)) do
|
||||||
local lua = obj:get_luaentity()
|
local lua = obj:get_luaentity()
|
||||||
if lua and lua.is_mob then
|
if lua and lua.is_mob then
|
||||||
lua.lifetimer = math.max(20, lua.lifetimer)
|
lua.lifetimer = max(20, lua.lifetimer)
|
||||||
lua.despawn_immediately = false
|
lua.despawn_immediately = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue