mirror of
https://codeberg.org/tenplus1/farming.git
synced 2024-11-10 20:30:31 +01:00
revert to old cocoa register_on_generate function, new one had memory leak
This commit is contained in:
parent
663cf0b86c
commit
e3bf5f92a7
|
@ -143,10 +143,44 @@ farming.registered_plants["farming:cocoa_beans"] = {
|
|||
steps = 4
|
||||
}
|
||||
|
||||
-- register async mapgen script
|
||||
-- add random cocoa pods to jungle tree's
|
||||
|
||||
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
|
||||
local random = math.random -- localise for speed
|
||||
|
||||
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.set_node(pos, {
|
||||
name = "farming:cocoa_" .. tostring(random(4))
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
|
||||
-- Localize things for speed
|
||||
|
||||
local random = math.random
|
||||
local jungletree_nodes = {"default:jungletree", "mcl_core:jungletree"}
|
||||
local jungletree_leaves = {
|
||||
"default:jungleleaves", "moretrees:jungletree_leaves_green", "mcl_core:jungleleaves"}
|
||||
|
||||
-- check area to place cocoa pods near jungle trees
|
||||
|
||||
local function generate(vmanip, minp, maxp)
|
||||
|
||||
if maxp.y < 0 then return end
|
||||
|
||||
local min, max = vmanip:get_emerged_area()
|
||||
local area = VoxelArea:new({MinEdge = min, MaxEdge = max})
|
||||
local data = vmanip:get_light_data()
|
||||
local cocoa = minetest.find_nodes_in_area(minp, maxp, jungletree_nodes)
|
||||
|
||||
for n = 1, #cocoa do
|
||||
|
||||
local pos = cocoa[n]
|
||||
|
||||
if minetest.find_node_near(pos, 1, jungletree_leaves) then
|
||||
|
||||
local 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" then
|
||||
|
||||
local index = area:index(pos.x, pos.y, pos.z)
|
||||
|
||||
if data[index] > 12 then -- light at pos > 12
|
||||
|
||||
minetest.set_node(pos, {name = "farming:cocoa_" .. random(4)})
|
||||
--print("Cocoa Pod added at " .. minetest.pos_to_string(pos))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- mapgen
|
||||
|
||||
if minetest.save_gen_notify then -- async env (5.9+)
|
||||
minetest.register_on_generated(function(vmanip, minp, maxp, blockseed)
|
||||
generate(vmanip, minp, maxp)
|
||||
end)
|
||||
else -- main thread (5.8 and earlier)
|
||||
minetest.register_on_generated(function(minp, maxp, blockseed)
|
||||
generate(minetest.get_mapgen_object("voxelmanip"), minp, maxp)
|
||||
end)
|
||||
end
|
Loading…
Reference in New Issue
Block a user