How to get item positions on a transport-belt?

Place to get help with not working mods / modding interface.
uukgoblin
Inserter
Inserter
Posts: 28
Joined: Mon Apr 02, 2018 4:43 pm
Contact:

How to get item positions on a transport-belt?

Post by uukgoblin »

I would like to know the precise positions of items held by a transport belt's lane.

I couldn't find any appropriate method in LuaTransportLine, except can_insert_at(), which is a very indirect way of finding where the items might be placed. It also doesn't say what items there are.

Using the LuaTransportLine's operator[] does tell me what items there are on the lane, but I can't figure out a way to get the LuaItemStacks' positions.

I also tried find_entities() on the nauvis LuaSurface, but that only seems to find the transport belt itself, not items lying on it.

Are items lying on the belt also LuaEntities? Can I find them somehow?
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to get item positions on a transport-belt?

Post by eradicator »

uukgoblin wrote: Sun Aug 23, 2020 9:53 pm Are items lying on the belt also LuaEntities?
No. Historically they once were, but belts have been heavily performance-optimized.
I don't think there's a way to get the pixel-perfect stack position. The index of a stack in a LuaTransportLine - as you already know - covers a range of positions on the belt.
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.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3716
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: How to get item positions on a transport-belt?

Post by DaveMcW »

I also needed to find the items on a single transport-belt, and I found a workaround.

If you mark a transport-belt for deconstruction, this breaks its connections. Then get_transport_line() returns a LuaTransportLine containing exactly the items on that belt.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to get item positions on a transport-belt?

Post by eradicator »

DaveMcW wrote: Fri Nov 06, 2020 5:18 am I also needed to find the items on a single transport-belt, and I found a workaround.

If you mark a transport-belt for deconstruction, this breaks its connections. Then get_transport_line() returns a LuaTransportLine containing exactly the items on that belt.
LuaEntity.get_transport_line() always returns a transport line for just that one belt.
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.
Post Reply

Return to “Modding help”