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.
[RESOLVED] Determine if a belt is a corner/turn belt
[RESOLVED] Determine if a belt is a corner/turn belt
Last edited by Picks on Fri Dec 01, 2023 12:00 pm, edited 1 time in total.
Re: Determine if a belt is a corner/turn belt
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.
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.
Re: Determine if a belt is a corner/turn belt
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.
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.
- _CodeGreen
- 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
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