I think more generally, the question is, can multiple blocks occupy the same coordinate?
If "yes" then you probably don't want to reference them using coordinates.
If the answer is "no" then you need to research how hashing works.
This way you can access objects directly:
Code: Select all
function removeBlock(x, y, z)
local index = hash3(x, y, z)
blocks[index] = nil
end
To illustrate how hashing works you could use strings:
Code: Select all
function hash3(x, y, z)
return x..','..y..','..z
end
It's usually more efficient to use math though.
One basic approach is to use shifting to pack the index into a single hex.
x,y,z must be integers within the range 0-255.
Code: Select all
function hash3(x, y, z)
assert(x >= 0 and y >= 0 and z >= 0, "out of bounds")
assert(x <= 255 and y <= 255 and z <= 255, "out of bounds")
return x*0x10000 + y*0x100 + z
end
This is basically the code for packing a 3-component color (RGB) into a hex.
Of course there are more sophisticated algorithms out there that can (depending on your needs) pack coords better.