Objects - Triborda/opencomputers-wiki GitHub Wiki

Objects in OC Lua

most Objects in this page are hash tables, all are at the time of writing this.

Item

An item is a hash table consisting of the key, values:

  • damage: integer - describes how much durability an item has lost, think of this value as max_durability - current_durability
  • isCraftable: boolean - (Specific to AE2 ME systems) if the item is a crafting result from an encoded pattern in any ME autocrafting multiblocks this is true
  • size: integer - number of items found in that item stack, this value may be higher than 64 if the item stack is in an ME system
  • maxSize: integer - maximum number of items in a stack of this item, this value may not change depending on what the item is contained in
  • label: String - the item label, e.g "Gold Ingot"
  • maxDamage: integer - the maximum durability of an item (or the maximum amount of damage an item may take before breaking)
  • hasTag: boolean - if the item has an NBT tag this value is true
  • name: String - the item name, e.g minecraft:gold_ingot

Further entries are only applicable if config file has been edited to enable them

  • id: integer - the item id e.g for gold: 266. Vanilla ids will remain constant for a given version of the game, however mod items may fluctuate depending on modpack. Use at your own risk. requires insertIdsInConverters=true
  • oreNames: Table - the item group(/s) that this item belongs to e.g for white glass:"blockGlass", "blockGlassWhite" requires insertIdsInConverters=true

Code block below shows the Item table of stone

item = {
  label = "Stone",
  damage = 0,
  oreNames = {"stone"},
  id = 1,
  size = 1,
  hasTag = false,
  maxDamage = 0,
  maxSize = 1,
  isCraftable = false,
  name = "minecraft:stone"
}

Filter tables

A filter table is a user defined hash table of keys with values. A filter table may be used to whitelist results when a function returns a table of hash tables or objects. in the case of getItemsInNetwork() from the me system functions a filter table will tell the function to only return the items with key values that match the filter table key values.

Example usage

-- imports
local component = require("component")
local me = component.proxy(component.me_interface.address)
local ser = require("serialization")
-- main
-- filter for size equal to 32
filter = {
    size = 32
}
-- output all items in ME system with stack size equal to 32
io.write(ser.serialize(me.getItemsInNetwork(filter)))

ME_CPU

An ME_CPU object is a hash table that has values describing the status of an ME CPU multiblock

An ME_CPU has key, values of:

  • busy: boolean - If the CPU is currently crafting this will return true, false otherwise
  • coprocessors: integer - The number of coprocessor blocks in this multiblock
  • name: string - The name of this CPU as the ME system reads it. This may be changed by renaming one of the blocks in the multiblock on an anvil
  • storage: integer - The total amount of crafting storage availible in the CPU. a single 1k crafting storage block equates to 1024 storage

Code block below shows ME_CPU table of a multiblock with a 1k crafting storage block, two coprocessors and a crafting monitor

me_cpu = {
    busy = false,
    coprocessors = 2,
    name = "",
    storage = 1024
}