Page 1 of 1

convert Position to LuaTransportLine and position

Posted: Mon Mar 26, 2018 5:02 pm
by sparr
I have x/y coordinates in the world. The tile they point at is a belt or splitter. I want to get the number of the transport line my coordinates point at, and the "position" on that transport line. Possibly only if there's an exact match, possibly the nearest match.

Also the reverse, from transportline+position to Position

I would use this functionality in Belt Overflow and other items-on-belts manipulating mods.

Re: convert Position to LuaTransportLine and position

Posted: Wed Apr 10, 2019 10:14 pm
by sparr
Now that we have info on which transportlines connect to which others, this would be even more useful to figure out where items leaving one will appear on the other.

Re: convert Position to LuaTransportLine and position

Posted: Wed May 01, 2019 2:45 pm
by LeonSkills
Support on this.

I'd like a

Code: Select all

LuaEntity.get_transport_line_index(position)
that returns the index of the transport line, or nil if position is outside the TransportBeltConnectable (the index so we can easily call get_transport_line(index) and do some math with the index). Would be nice if it would return that position as well as a second return value.
Or have LuaEntity.drop_target also store the LuaTransportLine or its index as a second value if the target is a TransportBeltConnectable.
But if we have the .get_transport_line_index(position) then we get that behaviour with

Code: Select all

local belt = inserter.drop_target
local transport_line = belt.get_transport_line(belt.get_transport_line_index(inserter.drop_position)

I wrote my own function for this to try to figure out at which transportline an inserter is inserting items to.
Which works fine. All vanilla inserters insert at the top right corner of a belt.
Except for that one exception where you're inserting on a corner piece
Image

Which is literally the only exception. A south facing inserter inserting to a north facing belt that has only a east facing belt feeding into it from the west. (And similarly for all its 90 degree rotation variations)

Accounting for that exception is the majority of the code of that method (can probably be optimized a bit) and it probably breaks when using modded inserters.