How to place saplings on chunk generation?
I am trying to get saplings to place randomly on dirt with grass blocks when the chunk is generated in the world. No exception is being thrown, but no saplings are being placed. Here is my code:
Please don't scold me if it's really simple. I'm a total noob at Lua. The reason why I'm using a while loop instead of a for loop is because it would freeze up minetest and make it close without any error. All help is much appreciated!
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_on_generated(
function(minp, maxp)
local dirtPositions = minetest.env:find_nodes_in_area(minp, maxp, {"default:dirt_with_grass"})
local i = 0
while (dirtPositions[i] ~= nil) do
local willDirtHaveSapling = math.random(1,2)
if (willDirtHaveSapling == 1) then
local saplingPos = dirtPositions[i]
saplingPos.y = saplingPos.y + 1
minetest.env:add_node(saplingPos, "industry:rubbersapling")
end
i = i + 1
end
end
)
Please don't scold me if it's really simple. I'm a total noob at Lua. The reason why I'm using a while loop instead of a for loop is because it would freeze up minetest and make it close without any error. All help is much appreciated!