1
0
mirror of https://codeberg.org/tenplus1/farming.git synced 2025-06-29 23:01:00 +02:00

use async env support when generating cocoa pods (thx Niklp)

This commit is contained in:
tenplus1
2024-06-09 07:33:19 +01:00
parent e33dd0e275
commit 433d485292
3 changed files with 62 additions and 44 deletions

View File

@ -210,46 +210,9 @@ farming.registered_plants["farming:cocoa_beans"] = {
steps = 4
}
-- localize math.random for speed
local random = math.random
-- add random cocoa pods to jungle tree's
minetest.register_on_generated(function(minp, maxp)
if maxp.y < 0 then
return
end
local pos, dir
local cocoa = minetest.find_nodes_in_area(minp, maxp,
{"default:jungletree", "mcl_core:jungletree"})
for n = 1, #cocoa do
pos = cocoa[n]
if minetest.find_node_near(pos, 1,
{"default:jungleleaves", "moretrees:jungletree_leaves_green",
"mcl_core:jungleleaves"}) then
dir = random(80)
if dir == 1 then pos.x = pos.x + 1
elseif dir == 2 then pos.x = pos.x - 1
elseif dir == 3 then pos.z = pos.z + 1
elseif dir == 4 then pos.z = pos.z -1
end
if dir < 5
and minetest.get_node(pos).name == "air"
and minetest.get_node_light(pos) > 12 then
--print ("Cocoa Pod added at " .. minetest.pos_to_string(pos))
minetest.swap_node(pos, {
name = "farming:cocoa_" .. tostring(random(4))
})
end
end
end
end)
-- register async mapgen script
if minetest.register_mapgen_script then
minetest.register_mapgen_script(farming.path .. "/crops/cocoa_mapgen.lua")
else
dofile(farming.path .. "/crops/cocoa_mapgen.lua")
end