This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
RandomBlue's profile picture

AE2 Stocker - Autocraft minimum inventory levels.

Started by RandomBlue, 11 September 2015 - 09:04 PM
RandomBlue #1
Posted 11 September 2015 - 11:04 PM
Got tired of running out of items in my AE2 system and didn't like the options for maintaining a minimum stock level for certain items. The approach I had been using required a level emitter, ME export bus, crafting card to auto-craft the item and a way to import the item back into the system. This requires a minimum of 2 channels (3 if you count the import bus to get items back into the system, but I had been sharing one import bus connected via tesseract or ender chest) per item you want to keep stocked. This program replaces all of that with a single computer and a full-size ME Interface, using a single channel.

Stocker description:


-- **   Minecraft AE2 Auto-Stocker by RandomBlue (E.J. Wilburn)
-- **   ----------------------------------------------------
-- **
-- **   This program automatically crafts items necessary to maintain a minimum
-- **   stock level of specific items.  The items are configured in a file on
-- **   a computercraft computer named stock_list.txt in the stocker directory.
-- **   Examine that file for example formatting and details.
-- **
-- **   Minimum stock levels and crafting batch sizes are configurable per item.
-- **
-- **   The computer must be placed adjacent to a full block ME Interface attached
-- **   to an ME Network where both the items are stored and the crafting CPUs are
-- **   located.  Each item you wish to maintain a stock level for must have
-- **   autocrafting enabled for it.
-- **
-- **   Arguments
-- **   ----------------------------------------------------
-- **   checkFrequency (optional)  - How often inventory levels are checked in seconds.
-- **   attachSide (optional)	   - Side the computer is attached to the ME Interface (full block version).
-- **   stockFileName (optional)   - Full path to the file containing stocking requirements.

Pastebin links:
Stocker program - http://pastebin.com/yac8keDW
Config file - http://pastebin.com/5eZABmj6

I suppose it's possible to use this to continually craft any item you want by setting the minQuantity value to something very high, then every time stock is checked it will attempt to craft it. If there aren't enough mats it just fails silently. Might be a good way to auto-craft your basics like converting ore to ingots continually.

Currently the app does require you use string identifiers instead of numeric IDs, but you can get those by hitting F3+h to turn on display of those IDs. You might have to open F3 first and play around with hitting that key combo until it's enabled.
Kalmon #2
Posted 22 September 2015 - 04:27 PM
I would like to work with you on this program. I've updated it to include:
-monitor support
-auto finding of the ME interface with no need to specify a location
-modem and networking support so the computer does not need to be touching the interface
-Reserved CPUs –allows you to specify how many CPUs to reserve for manual crafting. This way it doesn't tie up all the CPUs with keep stock.

If you'd like I can get you a pastebin link to my update. I wanted to ask you first as you were kind enough to post this.

on another note:
I've also got a complete list of all the APIs in AE2 as well as a detailed spreadsheed of args and returns for each function.
Base AE2 API:
http://pastebin.com/4EUT1QEf
Detailed API decoded:
http://pastebin.com/FPmpgDpx
Fousicek #3
Posted 14 October 2015 - 05:05 PM
Hi, i am quite new to programing in lua.

so if i may ask.

if i want to print a name of a items using getAvailableItems("all") how do i do that exactly ?

i have this. local myTable = {peripheral.wrap("top").getAvailableItems("all")}

i tryed print(tostring(myTable.args.1[name]))

and such combinations but i think that i still not get how that table is made from that interface.

Can i get some simple command which will show it ?

Thank you
Kalmon #4
Posted 19 October 2015 - 01:11 PM
Hi, i am quite new to programing in lua.

so if i may ask.

if i want to print a name of a items using getAvailableItems("all") how do i do that exactly ?

i have this. local myTable = {peripheral.wrap("top").getAvailableItems("all")}

i tryed print(tostring(myTable.args.1[name]))

and such combinations but i think that i still not get how that table is made from that interface.

Can i get some simple command which will show it ?

Thank you

If you look at the original posted file and find these sections:

note that ae2 is the wraped AE2 interface


function getAllItems(ae2)
        local outputAllItems = ae2.getAvailableItems()
        assert(outputAllItems ~= nil, "No craftable items found in this AE2 network.")
        assert(#outputAllItems > 0, "No craftable items found in this AE2 network.")
        return outputAllItems
end

local allItems = getAllItems(ae2)
        for i=1, #allItems do
            if (allItems[i].is_craftable == true) then
                stockItem(allItems[i], stocks, ae2)
            end
        end
so from that if all you want is a print of available items you would do something like:


local MEInterface = peripheral.wrap("top")  --assuming the computer is under the interface
local ItemList = MEInterface.getAvailableItems()

for x=1, #ItemList do
  print(ItemList[x].name)  --I'm not sure of the .name it might be .description I haven't tested it yet
end
Bocephus666 #5
Posted 07 November 2015 - 02:36 PM
Kalmon, I'd love to see your updates to the script.