Canonical way to convert ChunkPosition -> BoundingBox?

Place to get help with not working mods / modding interface.
Post Reply
AngledLuffa
Fast Inserter
Fast Inserter
Posts: 187
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

Canonical way to convert ChunkPosition -> BoundingBox?

Post by AngledLuffa »

I assume that if I'm given a Position chunk_position, I can convert that to a bounding box by doing x * 32, y * 32, x * 32 + 31, y * 32 + 31. However, it seems kind of hacky to hardcode those numbers, even if the size of a chunk is not likely to ever change.

Ultimately, what I want is a way to get the BoundingBox for on_chunk_charted

https://lua-api.factorio.com/latest/eve ... nk_charted

It's a little unfortunate that on_chunk_charted and on_chunk_generated have different attributes. Is it possible to unify that somehow? Preferably by having the bounding box in both, or at perhaps by adding the bounding box to on_chunk_charted without removing any of its existing attributes.

kingarthur
Smart Inserter
Smart Inserter
Posts: 1459
Joined: Sun Jun 15, 2014 11:39 am
Contact:

Re: Canonical way to convert ChunkPosition -> BoundingBox?

Post by kingarthur »

seems to be the current way to handle it. for that last part it would need to be a modding interface request and unless there is some particular reason for it the devs should add it.

i would suggest going to viewforum.php?f=28 and clearly explain exactly what your requesting they add and why. at that point they should take a look at it soonish compared to here where its buried under a sort of question even though its more a feature request

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Canonical way to convert ChunkPosition -> BoundingBox?

Post by eradicator »

Code: Select all

for chunk in surface.get_chunks() do
  local area = {
    left_top     = {x = chunk.x*32   , y = chunk.y*32   },
    right_bottom = {x = chunk.x*32+32, y = chunk.y*32+32}
    }
  --dostuff
  end
The chunk iterator has the same "problem". Funny enough there's already an interface request to include the area there too.

Btw, why are you using +31? When i tested with rendering.draw_rectangle the above code seemed to perfectly match the tile grid.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

AngledLuffa
Fast Inserter
Fast Inserter
Posts: 187
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

Re: Canonical way to convert ChunkPosition -> BoundingBox?

Post by AngledLuffa »

eradicator wrote:
Fri Aug 02, 2019 1:33 pm
Btw, why are you using +31? When i tested with rendering.draw_rectangle the above code seemed to perfectly match the tile grid.
Wasn't sure if it would use < or <= at the end of the range. 32 makes more sense now that you mention it. Thanks!

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Canonical way to convert ChunkPosition -> BoundingBox?

Post by Bilka »

AngledLuffa wrote:
Mon Jul 29, 2019 3:13 am
Ultimately, what I want is a way to get the BoundingBox for on_chunk_charted
I have added the area to the event for the next version.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

AngledLuffa
Fast Inserter
Fast Inserter
Posts: 187
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

Re: Canonical way to convert ChunkPosition -> BoundingBox?

Post by AngledLuffa »

Thank you, that's perfect!

Post Reply

Return to “Modding help”