Fix incorrect usages of math.random (#4621)

random() does not support float arguments

Reviewed-on: VoxeLibre/VoxeLibre#4621
Reviewed-by: Mikita Wiśniewski <rudzik8@protonmail.com>
Co-authored-by: kno10 <erich.schubert@gmail.com>
Co-committed-by: kno10 <erich.schubert@gmail.com>
This commit is contained in:
kno10 2024-09-07 14:58:12 +02:00 committed by the-real-herowl
parent 593a095a5f
commit ebee85db7e
9 changed files with 26 additions and 27 deletions

View File

@ -362,7 +362,7 @@ function mob_class:env_danger_movement_checks(player_in_active_range)
self.state = "stand"
self:set_animation( "stand")
end
yaw = yaw + math.random(-0.5, 0.5)
yaw = yaw + math.random() - 0.5
yaw = self:set_yaw( yaw, 8)
return
end
@ -788,9 +788,9 @@ function mob_class:flop()
if self.object:get_velocity().y < 0.1 then
self:mob_sound("flop")
self.object:set_velocity({
x = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
x = (math.random()-0.5) * 2 * FLOP_HOR_SPEED,
y = FLOP_HEIGHT,
z = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
z = (math.random()-0.5) * 2 * FLOP_HOR_SPEED,
})
end
end
@ -920,7 +920,7 @@ function mob_class:do_states_walk()
-- Randomly turn
if math.random(1, 100) <= 30 then
yaw = yaw + math.random(-0.5, 0.5)
yaw = yaw + math.random() - 0.5
yaw = self:set_yaw( yaw, 8)
end
end
@ -929,7 +929,7 @@ function mob_class:do_states_walk()
-- otherwise randomly turn
elseif math.random(1, 100) <= 30 then
yaw = yaw + math.random(-0.5, 0.5)
yaw = yaw + math.random() - 0.5
yaw = self:set_yaw( yaw, 8)
end
@ -989,7 +989,7 @@ function mob_class:do_states_stand(player_in_active_range)
if lp.x > s.x then yaw = yaw +math.pi end
else
yaw = yaw + math.random(-0.5, 0.5)
yaw = yaw + math.random() - 0.5
end
yaw = self:set_yaw( yaw, 8)

View File

@ -95,8 +95,8 @@ mcl_mobs.register_mob("mobs_mc:blaze", {
end
local pos = self.object:get_pos()
minetest.add_particle({
pos = {x=pos.x+math.random(-0.7,0.7)*math.random()/2,y=pos.y+math.random(0.7,1.2),z=pos.z+math.random(-0.7,0.7)*math.random()/2},
velocity = {x=0, y=math.random(1,1), z=0},
pos = {x=pos.x+(math.random()*0.7-0.35)*math.random(),y=pos.y+0.7+math.random()*0.5,z=pos.z+(math.random()*0.7-0.35)*math.random()},
velocity = {x=0, y=1, z=0},
expirationtime = math.random(),
size = math.random(1, 4),
collisiondetection = true,
@ -110,8 +110,8 @@ mcl_mobs.register_mob("mobs_mc:blaze", {
},
})
minetest.add_particle({
pos = {x=pos.x+math.random(-0.7,0.7)*math.random()/2,y=pos.y+math.random(0.7,1.2),z=pos.z+math.random(-0.7,0.7)*math.random()/2},
velocity = {x=0, y=math.random(1,1), z=0},
pos = {x=pos.x+(math.random()*0.7-0.35)*math.random(),y=pos.y+0.7+math.random()*0.5,z=pos.z+(math.random()*0.7-0.35)*math.random()},
velocity = {x=0, y=1, z=0},
expirationtime = math.random(),
size = math.random(1, 4),
collisiondetection = true,
@ -125,8 +125,8 @@ mcl_mobs.register_mob("mobs_mc:blaze", {
},
})
minetest.add_particle({
pos = {x=pos.x+math.random(-0.7,0.7)*math.random()/2,y=pos.y+math.random(0.7,1.2),z=pos.z+math.random(-0.7,0.7)*math.random()/2},
velocity = {x=0, y=math.random(1,1), z=0},
pos = {x=pos.x+(math.random()*0.7-0.35)*math.random(),y=pos.y+0.7+math.random()*0.5,z=pos.z+(math.random()*0.7-0.35)*math.random()},
velocity = {x=0, y=1, z=0},
expirationtime = math.random(),
size = math.random(1, 4),
collisiondetection = true,

View File

@ -84,7 +84,7 @@ local cod = {
self.object:set_bone_position("body", vector.new(0,1,0), vector.new(degrees(dir_to_pitch(self.object:get_velocity())) * -1 + 90,0,0))
if minetest.get_item_group(self.standing_in, "water") ~= 0 then
if self.object:get_velocity().y < 5 then
self.object:add_velocity({ x = 0 , y = math.random(-.007, .007), z = 0 })
self.object:add_velocity({ x = 0 , y = math.random()*.014-.007, z = 0 })
end
end
--]]

View File

@ -81,16 +81,16 @@ local dolphin = {
reach = 2,
damage = 2.5,
attack_type = "dogfight",
--[[ this is supposed to make them jump out the water but doesn't appear to work very well
do_custom = function(self,dtime)
--[[ this is supposed to make them jump out the water but doesn't appear to work very well
self.object:set_bone_position("body", vector.new(0,1,0), vector.new(degrees(dir_to_pitch(self.object:get_velocity())) * -1 + 90,0,0))
if minetest.get_item_group(self.standing_in, "water") ~= 0 then
if self.object:get_velocity().y < 5 then
self.object:add_velocity({ x = 0 , y = math.random(-.007, .007), z = 0 })
self.object:add_velocity({ x = 0 , y = math.random()*.014-.007, z = 0 })
end
end
--]]
end,
--]]
}
mcl_mobs.register_mob("mobs_mc:dolphin", dolphin)

View File

@ -122,7 +122,7 @@ local spawn_children_on_die = function(child_mob, spawn_distance, eject_speed)
end
local mndef = minetest.registered_nodes[minetest.get_node(pos).name]
local mother_stuck = mndef and mndef.walkable
local angle = math.random(0, math.pi*2)
local angle = math.random() * math.pi * 2
local children = {}
local spawn_count = math.random(2, 4)
for i = 1, spawn_count do

View File

@ -177,7 +177,7 @@ function lightning.strike_func(pos, pos2, objects)
add_entity(pos2, "mobs_mc:skeleton_horse")
local angle, posadd
angle = math.random(0, math.pi*2)
angle = math.random() * math.pi * 2
for i=1,3 do
posadd = { x=math.cos(angle),y=0,z=math.sin(angle) }
posadd = vector.normalize(posadd)

View File

@ -30,7 +30,7 @@ minetest.register_abm({
local cherry_particle = {
velocity = vector.zero(),
acceleration = vector.new(0,-1,0),
size = math.random(1.3,2.5),
size = 1.3 + math.random() * 1.2,
texture = "mcl_cherry_blossom_particle_" .. math.random(1, 12) .. ".png",
animation = {
type = "vertical_frames",
@ -45,8 +45,8 @@ local cherry_particle = {
local wind_direction -- vector
local time_changed -- 0 - afternoon; 1 - evening; 2 - morning
local function change_wind_direction()
local east_west = math.random(-0.5,0.5)
local north_south = math.random(-0.5,0.5)
local east_west = math.random() - 0.5
local north_south = math.random() - 0.5
wind_direction = vector.new(east_west, 0, north_south)
end
change_wind_direction()
@ -57,10 +57,10 @@ minetest.register_abm({
interval = 5,
chance = 10,
action = function(pos, node)
minetest.after(math.random(0.1,1.5),function()
minetest.after(0.1 + math.random() * 1.4,function()
local pt = table.copy(cherry_particle)
pt.pos = vector.offset(pos,math.random(-0.5,0.5),-0.51,math.random(-0.5,0.5))
pt.expirationtime = math.random(1.2,4.5)
pt.pos = vector.offset(pos,math.random()-0.5,-0.51,math.random()-0.5)
pt.expirationtime = 1.2 + math.random() * 3.3
pt.texture = "mcl_cherry_blossom_particle_" .. math.random(1, 12) .. ".png"
local time = minetest.get_timeofday()
if time_changed ~= 0 and time > 0.6 and time < 0.605 then

View File

@ -259,8 +259,7 @@ local function spawn_mobs(pos, elapsed)
end
-- Spawn attempt done. Next spawn attempt much later
timer:start(math.random(10, 39.95))
timer:start(math.random() * 29.95 + 10)
end
-- The mob spawner node.

View File

@ -280,7 +280,7 @@ minetest.register_globalstep(function(dtime)
pos = fly_pos,
velocity = vector.zero(),
acceleration = vector.zero(),
expirationtime = math.random(0.3, 0.5),
expirationtime = 0.3 + math.random() * 0.2,
size = math.random(1, 2),
collisiondetection = false,
vertical = false,