Browse Source

[bushes_classic] Optimize math.random call function

master
sys4 2 weeks ago
parent
commit
c2681261e0
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      bushes_classic/nodes.lua

+ 5
- 3
bushes_classic/nodes.lua View File

@@ -4,6 +4,8 @@ local S = minetest.get_translator("bushes_classic")
plantlife_bushes = {}

-- TODO: add support for nodebreakers? those dig like mese picks
local random = math.random

plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger)
if not (digger and pos and oldnode) then
return
@@ -63,7 +65,7 @@ plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger)

-- with a chance of 1/3, return 2 bushes
local amount
if math.random(1,3) == 1 then
if random(1,3) == 1 then
amount = "2"
else
amount = "1"
@@ -75,7 +77,7 @@ plantlife_bushes.after_dig_node = function(pos, oldnode, oldmetadata, digger)
elseif groupcaps.choppy then

-- the amount of sticks may vary
local amount = math.random(4, 20)
local amount = random(4, 20)
-- return some sticks
harvested = "default:stick " .. amount

@@ -136,7 +138,7 @@ minetest.register_abm({
local dirt = minetest.get_node(dirtpos)
local is_soil = minetest.get_item_group(dirt.name, "soil") or minetest.get_item_group(dirt.name, "potting_soil")

if is_soil and (dirt.name == "farming:soil_wet" or math.random(1,3) == 1) then
if is_soil and (dirt.name == "farming:soil_wet" or random(1,3) == 1) then
minetest.swap_node( pos, {name = "bushes:" .. bush_name .. "_bush"})
end
end


Loading…
Cancel
Save