1
0
mirror of https://codeberg.org/tenplus1/farming.git synced 2024-12-26 02:30:20 +01:00

using on_generate to place cocoa pods instead of abm

This commit is contained in:
TenPlus1 2016-06-22 20:49:11 +01:00
parent 38b4111878
commit 01e2f37467

View File

@ -137,38 +137,46 @@ crop_def.drop = {
} }
minetest.register_node("farming:cocoa_3", table.copy(crop_def)) minetest.register_node("farming:cocoa_3", table.copy(crop_def))
-- add random cocoa pods to jungle tree trunks -- add random cocoa pods to jungle tree's
minetest.register_abm({ minetest.register_on_generated(function(minp, maxp)
nodenames = {"default:jungletree"},
neighbors = {"default:jungleleaves", "moretrees:jungletree_leaves_green"},
interval = 8,
chance = 80,
catch_up = false,
action = function(pos, node)
local dir = math.random(1, 50) if maxp.y < 0 then
return
end
local pos, dir
local cocoa = minetest.find_nodes_in_area(minp, maxp, "default:jungletree")
for n = 1, #cocoa do
pos = cocoa[n]
if minetest.find_node_near(pos, 1,
{"default:jungleleaves", "moretrees:jungletree_leaves_green"}) then
dir = math.random(1, 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(math.random(1, 3))
})
end
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
else return
end end
end
local nodename = minetest.get_node(pos).name end)
if nodename == "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(math.random(1, 3))
})
end
end,
})