[RESOLVED] Determine if a belt is a corner/turn belt

Place to get help with not working mods / modding interface.
Picks
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sun Sep 10, 2023 11:57 pm
Contact:

[RESOLVED] Determine if a belt is a corner/turn belt

Post by Picks »

First:
Is there a function in the API or a characteristic of the belt entities that I can exploit to determine if a belt is a corner belt?
For example, a West facing belt is, as far as I can find, programatically identical to a West facing belt with a South facing belt adjacent to its North side.
Currently I'm brute forcing it by checking adjacent positions to the belt in question, but that feels hamhanded and wrong. I assume there's a better way to determine this and I just can't find it.

Second:
Is there a way to allow the belt to 'connect' to the building I'm creating in my mod? (same funcitonality as the nose of one belt connecting to the tail of another)
How would one go about adding 'belt connection points' to a building.
The building I'm making is larger than 1x1, so if the process is different for larger dimension buildings, what's that process?

Thanks for any help.
Last edited by Picks on Fri Dec 01, 2023 12:00 pm, edited 1 time in total.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2982
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Determine if a belt is a corner/turn belt

Post by boskid »

For 1.1.100 i added LuaEntity::belt_shape read that will return "left", "straight" or "right" depending on what is the current shape of a transport belt. There are ways to determine the shape from existing fields but it is annoying operation as you need to get all neighbours of a transport belt and check if left neighbour (relative to belts direction), right neighbour (relative to belts direction) and back neighbour (relative to belts direction) are facing into the current belt and if yes you have 3 bool (left conencted, straight connected, right connected) which has to be then translated into expected shape: if there is straight connection, or there are both left and right or there are neither left nor right connection, then it is straight. Left is when there is only left connection and right is only when there is right connection. Quite annoying so LuaEntity::belt_shape will be added.

As for the second. The only way for belts to change shape is by having other belts nearby. If you want to have your building appear as it is connecting with belts, you may want to spawn additional invisible belts under your entity so they will influence shape of belts nearby.
Picks
Burner Inserter
Burner Inserter
Posts: 6
Joined: Sun Sep 10, 2023 11:57 pm
Contact:

Re: Determine if a belt is a corner/turn belt

Post by Picks »

Excellet, thanks for the responses. I look forward to LuaEntity::belt_shape for sure. I'm basically doing what you described currently. I can confirm that it is indeed quite annoying.

For the second point, that's what I had presumed would be the way to do it. I'll work towards that solution.

Thanks for your time.
User avatar
_CodeGreen
Long Handed Inserter
Long Handed Inserter
Posts: 72
Joined: Sat Mar 05, 2022 11:30 am
Contact:

Re: [RESOLVED] Determine if a belt is a corner/turn belt

Post by _CodeGreen »

It's actually pretty simple to tell if a belt is curved and which direction (clockwise/counterclockwise) it's turning, due to the belt_neighbours field. If belt_neighbours.inputs has only one entry, then it's (edit: potentially) a curved belt (only if the input belt direction is different). Then, (belt.direction - input.direction) % 8 == 2 can tell you if it's clockwise. It's nice to have the built in api though, because previously anyone who wanted that information would have to figure out how to do all that themselves, so I'm glad nobody else has to now.
My Mods | If you can't make it perfect, make it adjustable
Post Reply

Return to “Modding help”