Resource module

Resource utilities.

Usage

local Resource = require('stdlib/entity/resource')

Functions

filter_resources (resources, resource_names) Given an array of resource entities, return the ones that have the given resource names.
get_resource_patch_at (surface, position, type) From the resources at the given surface and position, return all connected (horizontally, vertically and diagonally) resource entities of specified type.
get_resource_patch_bounds (resource_patch) Given a resource patch, return its area.
get_resource_patches_at (surface, position) From the resources at the given surface and position, return all connected (horizontally, vertically and diagonally) resource entities.
get_resource_types (resources) Given an array of resource entities, get an array containing their names.
get_resources_at (surface, position) Gets all resource entities at the specified position and surface.

Functions

# filter_resources (resources, resource_names)

Given an array of resource entities, return the ones that have the given resource names.

Parameters: Returns:
  • ({nil or LuaEntity,...}) a new array containing the entities matching the given resource names or nil if no matches were found
# get_resource_patch_at (surface, position, type)

From the resources at the given surface and position, return all connected (horizontally, vertically and diagonally) resource entities of specified type.

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:
  • surface : (LuaSurface) the surface to look up
  • position : (Position) the position to check
  • type : (string) the resource type (example: "iron-ore")
Returns:
  • ({nil or LuaEntity,...}) an array containing all resources in the resource patch, or an empty array if there are no resources there
# get_resource_patch_bounds (resource_patch)

Given a resource patch, return its area.

Parameters: Returns: See also:
# get_resource_patches_at (surface, position)

From the resources at the given surface and position, return all connected (horizontally, vertically and diagonally) resource entities.

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.

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:
  • surface : (LuaSurface) the surface to look up
  • position : (Position) the position to check
Returns:
  • ({nil} or {[string <resource-type>] = {LuaEntity,...},...}) a map of resource types to resource entities or empty array if they don't exist
# get_resource_types (resources)

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: Returns:
  • ({nil or string,...}) a new array with the names of the resources or nil if no resource entities are given
# get_resources_at (surface, position)

Gets all resource entities at the specified position and surface.

Adapted from YARM/resmon.lua → find_resource_at

Parameters: Returns: