Page 1 of 1

[0.12.35] area of event.on_chunk_generated is to big

Posted: Tue May 31, 2016 8:51 pm
by MrDoomah
The area returned by the on_chunk_generated event is to big. It returns an area as follows:

Code: Select all

area = {left_top = {x = n*32, y = m*32}, bottom_right = {x = (n+1)*32, y = (m+1)*32}}
where n and m are chunk coordinates. So for chunk position {0,0} it returns {{0,0},{32,32}}.
This is too big, as seen here:
Image

Returned area should be:

Code: Select all

area = {left_top = {x = n*32, y = m*32}, bottom_right = {x = n*32 + 31, y = m*32 + 31}}

Re: [0.12.35] area of event.on_chunk_generated is to big

Posted: Tue May 31, 2016 8:57 pm
by Rseding91
Your command is wrong. You're iterating from 0 to 32 inclusive which is 33 tiles total: 1 too many on both the x and y direction.

for x = 0,31 do is what you're looking for: the tiles in that chunk because they're 0 based indexing.

The "area" given during the chunk generated event is that - the *area* - not the tile size. The top left point is 0,0 and the bottom right point is 32,32: these are the chunks area and not tile sizes which is correct.

Re: [0.12.35] area of event.on_chunk_generated is to big

Posted: Tue May 31, 2016 9:00 pm
by MrDoomah
Rseding91 wrote:Your command is wrong. You're iterating from 0 to 32 inclusive which is 33 tiles total: 1 too many on both the x and y direction.

for x = 1,32 do is what you're looking for.
yah, fair point. It was a bad example.

To be more precise:
The area of a chunk is bounded by (in math notation)

Code: Select all

x = [n*32, (n+1)*32[
y = [m*32, (m+1)*32[

Re: [0.12.35] area of event.on_chunk_generated is to big

Posted: Wed Jun 01, 2016 5:08 am
by silverkitty23
you're missing a little on the math notation: it's
x: n*32 (inclusive) => (n+1)*32 (exclusive)

I think the fn returns 0 and 32 because in C the loop wouldn't be : "for x = 0,32", it would be "for ( x = 0; x < 32; x++ )"
in other words, the function is correct for the internal API, and inconvenient for the Lua API :/