1
0
Fork 0

Generate cocoas at jungle trees

This commit is contained in:
Wuzzy 2017-02-18 19:15:58 +01:00
parent 4488944838
commit f0e5a9707a
1 changed files with 17 additions and 11 deletions

View File

@ -62,6 +62,7 @@ local crop_def = {
"[combine:32x32:-10,0=mcl_cocoas_cocoa_stage_0.png", "[combine:32x32:-10,0=mcl_cocoas_cocoa_stage_0.png", "[combine:32x32:-10,0=mcl_cocoas_cocoa_stage_0.png", "[combine:32x32:-10,0=mcl_cocoas_cocoa_stage_0.png",
}, },
paramtype = "light", paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
walkable = true, walkable = true,
drop = "mcl_dye:brown", drop = "mcl_dye:brown",
@ -154,39 +155,44 @@ crop_def.drop = "mcl_dye:brown 3",
minetest.register_node("mcl_cocoas:cocoa_3", table.copy(crop_def)) minetest.register_node("mcl_cocoas:cocoa_3", table.copy(crop_def))
-- Add random cocoa pods to jungle trees -- Add random cocoa pods to jungle trees
-- TODO: Do this more efficiently, with LuaVoxelManip
minetest.register_on_generated(function(minp, maxp) minetest.register_on_generated(function(minp, maxp)
if maxp.y < 0 then if maxp.y < 0 then
return return
end end
local pos, dir local pos, treepos, dir
local cocoa = minetest.find_nodes_in_area(minp, maxp, "mcl_core:jungletree") local cocoa = minetest.find_nodes_in_area(minp, maxp, "mcl_core:jungletree")
for n = 1, #cocoa do for n = 1, #cocoa do
pos = cocoa[n] pos = cocoa[n]
treepos = table.copy(pos)
if minetest.find_node_near(pos, 1, {"mcl_core:jungleleaves"}) then if minetest.find_node_near(pos, 1, {"mcl_core:jungleleaves"}) then
dir = math.random(1, 80) dir = math.random(1, 40)
if dir == 1 then 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 pos.z = pos.z + 1
elseif dir == 4 then elseif dir == 2 then
pos.z = pos.z - 1 pos.z = pos.z - 1
elseif dir == 3 then
pos.x = pos.x + 1
elseif dir == 4 then
pos.x = pos.x -1
end end
if dir < 5 local nn = minetest.get_node(pos).name
and minetest.get_node(pos).name == "air"
and minetest.get_node_light(pos) > 12 then
if dir < 5
and nn == "air"
and minetest.get_node_light(pos) > 12 then
minetest.swap_node(pos, { minetest.swap_node(pos, {
name = "mcl_cocoas:cocoa_" .. tostring(math.random(1, 3)) name = "mcl_cocoas:cocoa_" .. tostring(math.random(1, 3)),
param2 = minetest.dir_to_facedir(vector.subtract(treepos, pos))
}) })
end end