entity.resource
Methods6
function Resource.get_resources_at(surface: string | LuaSurface, position: MapPosition) -> LuaEntity[]
Gets all resource entities at the specified position and surface. Adapted from YARM/resmon.lua → find_resource_at
surfacestring | LuaSurfacethe surface to look up
positionMapPositionthe position to check
- LuaEntity[]
an array of resource entities
function Resource.get_resource_patches_at(surface: LuaSurface, position: MapPosition) -> any
From the resources at the given surface and position, return all connected (horizontally, vertically and diagonally) resource entities. <p>When the resource patches are found, the returned object will be an associative array where the key is the resource-type string and the value is an array of entities that correspond to the resource-type. <p>For now, this function gets just the ore patches, since problems arise when a single resource entity spans multiple tiles.
This implementation is unstable; if a resource entity reference changes during the search,
both the old and the new version of the entity might be included.
surfaceLuaSurfacethe surface to look up
positionMapPositionthe position to check
- any
({@{nil}} or {[@{string} <resource-type>] = {@{LuaEntity},...},...}) a map of resource types to resource entities or empty array if they don't exist
function Resource.get_resource_patch_at(surface: LuaSurface, position: MapPosition, type: string) -> LuaEntity[] | nil
From the resources at the given surface and position, return all connected (horizontally, vertically and diagonally) resource entities of specified type. <p>For now, this function gets just the ore patches, since problems arise when a single resource entity spans multiple tiles.
This implementation is unstable; if a resource entity reference changes during the search,
both the old and the new version of the entity might be included.
surfaceLuaSurfacethe surface to look up
positionMapPositionthe position to check
typestringthe resource type (example: "iron-ore")
- LuaEntity[] | nil
an array containing all resources in the resource patch, or an empty array if there are no resources there
function Resource.get_resource_types(resources: LuaEntity[]) -> string[]
Given an array of resource entities, get an array containing their names. Every element within the new array is unique and is the name of a resource entity.
resourcesLuaEntity[]an array of resource entities
- string[]
a new array with the names of the resources
function Resource.filter_resources(resources: LuaEntity[], resource_names: string[]) -> LuaEntity[]
Given an array of resource entities, return the ones that have the given resource names.
resourcesLuaEntity[]an array of resource entities
resource_namesstring[]the names of the resource entities
- LuaEntity[]
a new array containing the entities matching the given resource names
function Resource.get_resource_patch_bounds(resource_patch: LuaEntity[]) -> BoundingBox
Given a resource patch, return its area.
resource_patchLuaEntity[]the resource patch
- BoundingBox
the area of the resource patch
Resource.getresourcepatch_at
Fields2
Resource.__class: string = "Resource"
Resource.__index : unknown