LVM and mapgen help request
I am looking for some help with map generation and the lua voxel manipulator.
Hopefully you can get the idea of what I am trying to do from the code.
Basically replacing each grass node with one of 4 random variants.
This code does do what I want but is incredibly slow.
Is there a better way to achieve the same effect?
Edit: Note this is not minetest_game, the grass node here is a solid (drawtype normal) node.
Hopefully you can get the idea of what I am trying to do from the code.
Basically replacing each grass node with one of 4 random variants.
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, seed)
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local data = vm:get_data()
for i in area:iterp(emin, emax) do
if data[i] == minetest.get_content_id("default:grass") then
local n = tostring(math.random(1, 4))
data[i] = minetest.get_content_id("default:grass_"..n)
end
end
vm:set_data(data)
vm:set_lighting({day=0, night=0})
vm:calc_lighting()
vm:write_to_map(data)
end)
This code does do what I want but is incredibly slow.
Is there a better way to achieve the same effect?
Edit: Note this is not minetest_game, the grass node here is a solid (drawtype normal) node.