Kryzeth Standard Library

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

Parameters
surfacestring | LuaSurface

the surface to look up

positionMapPosition

the position to check

Returns
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.

Parameters
surfaceLuaSurface

the surface to look up

positionMapPosition

the position to check

Returns
any

({@{nil}} or {[@{string} &lt;resource-type&gt;] = {@{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.

Parameters
surfaceLuaSurface

the surface to look up

positionMapPosition

the position to check

typestring

the resource type (example: "iron-ore")

Returns
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.

Parameters
resourcesLuaEntity[]

an array of resource entities

Returns
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.

Parameters
resourcesLuaEntity[]

an array of resource entities

resource_namesstring[]

the names of the resource entities

Returns
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.

Parameters
resource_patchLuaEntity[]

the resource patch

Returns
BoundingBox

the area of the resource patch

See:

Resource.getresourcepatch_at

Fields2

Resource.__class: string = "Resource"
Resource.__index : unknown