mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
Add voxelarea.lua helper to builtin
This commit is contained in:
parent
280946ba83
commit
3f13dc790c
@ -25,4 +25,4 @@ dofile(minetest.get_modpath("__builtin").."/static_spawn.lua")
|
||||
dofile(minetest.get_modpath("__builtin").."/detached_inventory.lua")
|
||||
dofile(minetest.get_modpath("__builtin").."/falling.lua")
|
||||
dofile(minetest.get_modpath("__builtin").."/features.lua")
|
||||
|
||||
dofile(minetest.get_modpath("__builtin").."/voxelarea.lua")
|
||||
|
46
builtin/voxelarea.lua
Normal file
46
builtin/voxelarea.lua
Normal file
@ -0,0 +1,46 @@
|
||||
VoxelArea = {
|
||||
MinEdge = {x=1, y=1, z=1},
|
||||
MaxEdge = {x=0, y=0, z=0},
|
||||
ystride = 0,
|
||||
zstride = 0,
|
||||
}
|
||||
|
||||
function VoxelArea:new(o)
|
||||
o = o or {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
local e = o:getExtent()
|
||||
o.ystride = e.x
|
||||
o.zstride = e.x * e.y
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
function VoxelArea:getExtent()
|
||||
return {
|
||||
x = self.MaxEdge.x - self.MinEdge.x + 1,
|
||||
y = self.MaxEdge.y - self.MinEdge.y + 1,
|
||||
z = self.MaxEdge.z - self.MinEdge.z + 1,
|
||||
}
|
||||
end
|
||||
|
||||
function VoxelArea:getVolume()
|
||||
local e = self:getExtent()
|
||||
return e.x * e.y * e.z
|
||||
end
|
||||
|
||||
function VoxelArea:index(x, y, z)
|
||||
local i = (z - self.MinEdge.z) * self.zstride +
|
||||
(y - self.MinEdge.y) * self.ystride +
|
||||
(x - self.MinEdge.x) + 1
|
||||
return math.floor(i)
|
||||
end
|
||||
|
||||
function VoxelArea:indexp(p)
|
||||
local i = (p.z - self.MinEdge.z) * self.zstride +
|
||||
(p.y - self.MinEdge.y) * self.ystride +
|
||||
(p.x - self.MinEdge.x) + 1
|
||||
return math.floor(i)
|
||||
end
|
||||
|
@ -1572,6 +1572,16 @@ methods:
|
||||
^ will be ignored
|
||||
- update_liquids(): Update liquid flow
|
||||
|
||||
VoxelArea: A helper class for voxel areas
|
||||
- Can be created via VoxelArea:new{MinEdge=pmin, MaxEdge=pmax}
|
||||
- Coordinates are *inclusive*, like most other things in Minetest
|
||||
methods:
|
||||
- getExtent(): returns a 3d vector containing the size of the area formed by MinEdge and MaxEdge
|
||||
- getVolume(): returns the volume of the area formed by MinEdge and MaxEdge
|
||||
- index(x, y, z): returns the index of an absolute position in a flat array starting at 1
|
||||
^ useful for things like VoxelManip, raw Schematic specifiers, PerlinNoiseMap:get2d/3dMap, and so on
|
||||
- indexp(p): same as above, except takes a vector
|
||||
|
||||
Mapgen objects
|
||||
---------------
|
||||
A mapgen object is a construct used in map generation. Mapgen objects can be used by an on_generate
|
||||
|
Loading…
Reference in New Issue
Block a user