Compatibility between Gregtech 6 and OpenComputer?

Hi. Sorry I’m late to the party. and I probably wont be back to be perfectly honest. Just stumbling my way around the internet to see if this world accelerator on my server rack is actually doing anything. It seems to be… part of the time… but i digress.

In opencomputers, blocks that can be directly interfaced with will show up on component.list() when adjacent to an adapter.
Something cool about Lua is the fact that basically everything is either a table or its on a table. (Just kidding… But theres a rediculous amount of tables for real)
functions are no different. math is a table. redstone is a table. etc. These tables are typically provided by files or components (funny story, in unix… everything is actually a file… including devices.). Blocks that act as components automatically get added to the component table (and become a table within a table). (although duplicates lose primary status… eg: arent callable by component.nameOfComponent … for example component.redstone)

So… there are multiple ways we can leverage this…

  1. get the connected components with component.list()
    Then connect an adapter to the block you want to interface with, and get the list again.
    Is there anything new? If so go into the lua interpreter (by entering the command ‘lua’ from the command line) and type compo then press tab (to autocomplete component) a period should also appear with the rest of the word component.
    So now we have component.
    (Side panel, and actually method 2 of checking for components, you can now just start pressing tab to cycle through available entries on the components table.) Im going to use an example that might be helpful, and might not (IDK whats up with gregtech 6, im on GTNH which runs gregtech 5… and quite possibly a modified version of it at that.)
    we should now have something like component.gt_machine.
    Just like above… we can cycle through everything on the gt_machine table with tab.
    Just to be clear. Any functions it exposes (commands provided by it that we can use through it only) are table values. Sometimes they leave off the () at the end of the autocomplete. Somethings its just an internal variable… like component.gt_machine.address. Sometimes its another table. Play around with it and see what functions you can reveal and what you can do with them.
    some provided functions have documentation. theres a bunch of ways of getting it. but typically entering the command without the parentheses in the lua interpreter returns information if available.

You can also just iterate over all the tables programmatically. functions aren’t ever (okay I guess typically) addressed to numbers on table. so component.gt_machine[1] will almost certainly return nil. That means we need to use pairs instead of ipairs (ipairs being usable on ordered tables… table[1] table[2] you get it)

TLDR;
connect adapter block to device you want to interface with. connect adapter to computer.
and run the file getMethods.lua

Maybe ill make an installer or something eventually… but for now instructions are in the readme

Happy coding! Oh, and technically, since you can use redstone, you can do all of those things with opencomputers using its redstone capabilities.

4 Likes