From 87d4640ca18ce3af15b894b6d9f340582ce56829 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 13 Sep 2022 13:53:17 +0200 Subject: [PATCH] mcl_mobs: actually use the localized functions not that it actually gains *a lot* --- mods/ENTITIES/mcl_mobs/api.lua | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index d899a02ac..23bcbf37f 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -29,6 +29,7 @@ local max = math.max local atann = math.atan local random = math.random local floor = math.floor +local ceil = math.ceil local atan = function(x) if not x or x ~= x then @@ -38,7 +39,6 @@ local atan = function(x) end end - -- Load settings local damage_enabled = minetest.settings:get_bool("enable_damage") 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 end -- randomize the pitch a bit - pitch = pitch + math.random(-10, 10) * 0.005 + pitch = pitch + random(-10, 10) * 0.005 end minetest.sound_play(sound, { object = self.object, @@ -280,7 +280,7 @@ local function update_roll(self) local cbox = table.copy(self.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 end @@ -315,7 +315,7 @@ local set_yaw = function(self, yaw, delay, dtime) if delay == 0 then if self.shaking and dtime then - yaw = yaw + (math.random() * 2 - 1) * 5 * dtime + yaw = yaw + (random() * 2 - 1) * 5 * dtime end self.object:set_yaw(yaw) update_roll(self) @@ -584,7 +584,7 @@ local damage_effect = function(self, damage) -- damage particles 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 pos = self.object:get_pos() @@ -710,7 +710,7 @@ local item_drop = function(self, cooked, looting_level) end 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 if num > 0 then @@ -819,7 +819,7 @@ local check_for_death = function(self, cause, cmi_cause) item_drop(self, cooked, looting) 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 @@ -1200,7 +1200,7 @@ local do_env_damage = function(self) end 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) if self.breath <= 0 then @@ -1218,7 +1218,7 @@ local do_env_damage = function(self) return true end else - self.breath = math.min(self.breath_max, self.breath + 1) + self.breath = min(self.breath_max, self.breath + 1) end end @@ -1544,7 +1544,7 @@ local breed = function(self) return end - mcl_experience.throw_xp(pos, math.random(1, 7)) + mcl_experience.throw_xp(pos, random(1, 7)) -- custom breed function if parent1.on_breed then @@ -1560,7 +1560,7 @@ local breed = function(self) -- Use texture of one of the parents - local p = math.random(1, 2) + local p = random(1, 2) if p == 1 then ent_c.base_texture = parent1.base_texture else @@ -1722,7 +1722,7 @@ local smart_mobs = function(self, s, p, dist, dtime) end, self) 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 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 local jumpheight = 0 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 jumpheight = 1 end @@ -1794,7 +1794,7 @@ local smart_mobs = function(self, s, p, dist, dtime) 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 s.y = s.y + sheight @@ -2232,9 +2232,9 @@ local follow_flop = function(self) if sdef and sdef.walkable then mob_sound(self, "flop") self.object:set_velocity({ - x = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), + x = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), y = FLOP_HEIGHT, - z = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), + z = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), }) end @@ -2289,8 +2289,8 @@ local function go_to_pos(entity,b) return true end 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 - if b.x > s.x then yaw = yaw + math.pi end + local yaw = (atann(v.z / v.x) + pi / 2) - entity.rotate + if b.x > s.x then yaw = yaw + pi end entity.object:set_yaw(yaw) set_velocity(entity,entity.follow_velocity) mcl_mobs:set_animation(entity, "walk") @@ -3474,7 +3474,7 @@ local mob_activate = function(self, staticdata, def, dtime) local c = 1 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_size = self.visual_size self.base_colbox = self.collisionbox @@ -3688,7 +3688,7 @@ local mob_step = function(self, dtime) self.delay = self.delay - 1 if self.shaking then - yaw = yaw + (math.random() * 2 - 1) * 5 * dtime + yaw = yaw + (random() * 2 - 1) * 5 * dtime end self.object:set_yaw(yaw) update_roll(self) @@ -3843,7 +3843,7 @@ local mob_step = function(self, dtime) self.object:remove() return elseif self.lifetimer <= 10 then - if math.random(10) < 4 then + if random(10) < 4 then self.despawn_immediately = true else self.lifetimer = 20 @@ -4516,7 +4516,7 @@ minetest.register_globalstep(function(dtime) for _, obj in pairs(minetest.get_objects_inside_radius(pos, 47)) do local lua = obj:get_luaentity() if lua and lua.is_mob then - lua.lifetimer = math.max(20, lua.lifetimer) + lua.lifetimer = max(20, lua.lifetimer) lua.despawn_immediately = false end end