[Solved] Finding entities

Place to get help with not working mods / modding interface.
Post Reply
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

[Solved] Finding entities

Post by FuryoftheStars »

EDIT: I'm having a hard time finding any info on surface.find_entities_filtered. Anyone got a link to it on the wiki?

Hi,

So I'm working on updating a mod created by someone else (Diesel Locomotive) where the mod checks for the existence of pumps adjacent to the locomotive by using the find_entities_filtered method. The problem I'm finding with this is that the locomotive can sit "off grid", and with the pumps collision box not encompassing the entire tile it sits on, it's possible for this method to check a point on the tile that is outside of the pump's collision box and thus misses seeing it.

My question is, is there another method of detecting entities that would be better/can check the entire tile of a given position?

EDIT: Ok, as I'm digging more into this, it seems like there are several different ways that it can do searches. This is the current variation of it that's being used in this mod:

Code: Select all

local found_pumps = loco.surface.find_entities_filtered{
	name = "pump",
	position = moveposition(
		loco.position,
		ori_to_dir(loco.orientation),
		{x = connection_array[j][1], y = connection_array[j][2]}
	)
}
Where connection_array is a table of {x,y} coordinates that we care about finding a pump at relative to the locomotive's current position.
Last edited by FuryoftheStars on Tue Jul 02, 2019 2:03 am, edited 1 time in total.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles


FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Finding entities

Post by FuryoftheStars »

darkfrei wrote:
Mon Jul 01, 2019 9:36 pm
LuaSurface.find_entities_filtered
Ah, thank you! I'll look this over and see if it helps me understand it better. :)
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Finding entities

Post by FuryoftheStars »

Thanks for the link. As I was considering on using the radius argument to allow it to span the gaps, it occurred to me that if I also rounded the locomotive's position values that were being fed in, it would help make sure that the function was always scanning the middle of the tiles.

Anyways, this issue seems to be solved. Time to tackle the next one.... :)
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Post Reply

Return to “Modding help”