ComputerCraft, OpenPeripheral and Applied Energistics

Discussion in 'Mod Discussion' started by Platinawolf, Mar 22, 2014.

  1. Platinawolf

    Platinawolf Active Member

    I'm running the Direwolf20(1.64) pack and I'm trying to figure out how to retrieve a list of all items in the AE network. Preferably like the now defunct MiscPeripheral's ME-bridge with its getList().

    The end result is going to be used to display on a monitor down the line ^^* But at the moment I'd be happy with just the line to get the amount of cobble-stone stored in the network so I can start poking around...
     
  2. casilleroatr

    casilleroatr Popular Member

    I'm not sure of the exact method name although you can probably find it by using the computercraft peripheral documentation program in my signature. I think you have to use the straight id and damage values instead of running them through a formula back in in the miscperipherals days

    edit: I made a demo report for the ME controller using my program on the thread I made for the program.

    The pertinent methods include:

    containsItemType
    countOfItemType

    and possibly, getAvailableItems

    Check the report out to get parameters and return types etc. It might be a good idea to get the program anyway and rerun it on the AE peripherals to make sure the reports are up to date.
     
  3. Arkandos

    Arkandos Popular Member Mod Developer

    If there are no good methods for directly interfacing with AE, I do know LP has native CC support.
     
  4. Platinawolf

    Platinawolf Active Member

    Checked the list of AE's methods, none of them looks promising,,, But that MethodMan program looks usefull :) I'l have to set up an LP network next then I suppose ^^*
     
  5. Platinawolf

    Platinawolf Active Member

    Ditched AE, went for a LP based solution. Following one assumes that you have a 6 wide and 4 high screen above the computer and the LP request pipe below


    Code:
    function sortByAmount(x, y)
      return x.amount > y.amount
    end
    
    function generateList()
        print("import started")
        itemList={}
        n=1
        myList = lp.getAvailableItems()
        print(#myList)
        for key,value in pairs( myList ) do
            z = myList[key]
            id = z[1]
            itemList[n] = {}
            itemList[n].id = id
            itemList[n].name = string.sub(lp.getUnlocalizedName(itemList[key].id),1,20)
            itemList[n].amount = lp.getItemAmount(itemList[key].id)
            if (key%10 == 0) then
                sleep(0.00000000000000000000000000000001)
            end
            n= n+1
        end   
        table.sort(itemList, sortByAmount)
        updateDisplay()
        return itemList
    end
    
    function checkAmount(itemList)
        for i = 1, totalItemsToDisplay ,1 do
            itemList[i].amount = lp.getItemAmount(itemList[i].id)
            if (i%10 == 0) then
                sleep(0.00000000000000000000000000000001)
            end
        end   
        table.sort(itemList, sortByAmount)
        updateDisplay()
    end   
    
    function updateDisplay()
        monX = 1
        monY = 2
        mon.clear()
        for i = 1, totalItemsToDisplay,1 do
            name = itemList[i].name
            amount = itemList[i].amount
            mon.setCursorPos(monY, monX)
            mon.write(name)
            mon.setCursorPos(monY+21,monX)
            mon.write(":        ")
            amountString = tostring(amount).." |"
            mon.setCursorPos(monY+30-string.len(amountString),monX)
            mon.write(amountString)
            if monX == itemsToDisplayPerRow then
                monX = 0
                monY = monY+30
            end   
            monX = monX+1
        end   
    end   
    
    function boot()
        iteration = 1
        lp = peripheral.wrap(lpDirection)
        mon=peripheral.wrap(monitorDirection)
        mon.setTextScale(0.5)
        mon.clear()
        mon.setTextScale(0.5)
        mon.setCursorPos(34,26)
        mon.write("Platinawolf  display  system  booting  up,  stand by...")
        mon.setCursorPos(36,32)
        sleep(1)
        mon.write("Generating  list")
        itemList = generateList()
       
        sleep(10)
    end
    
    function mainLoop()
        while true do
            if (iteration % 30==0) then
                print("generating list")
                itemList = generateList()
                print("updateDisplay")   
                iteration = 1
            else   
                print("Updating list")
                checkAmount(itemList)
                print("updateDisplay")   
                iteration = iteration +1
            end
            sleep(10)
        end
    end
    
    
    --variables
    totalItemsToDisplay = 208
    itemsToDisplayPerRow = 52
    lpDirection = "bottom"
    monitorDirection = "top"
    -- end variables
    
    
    boot()
    mainLoop()
    
     
  6. casilleroatr

    casilleroatr Popular Member

    I haven't read the program yet (although thanks for posting it I will take a look soon), but I thought I would mention that you can only sleep for a minimum of 1 tick (0.05s). Any smaller value will just round up to a tick
     
  7. Platinawolf

    Platinawolf Active Member

    Ooh, so minimum of 1 tick sleep. Good to know :) But considering that I have more important stuff around I thought it best to eer on the side of caution with sleeping ^^* Especially as I had problems with the program not yeilding when I batched 100 of the getItemAmount's...
     
  8. casilleroatr

    casilleroatr Popular Member

    Its a good idea to sleep, if only for a tick. I wasn't picking faults or anything, I just thought if anything it will save you key presses.
     
  9. Platinawolf

    Platinawolf Active Member

    And one thing I noticed is that if run at startup it will collapse due to lp not having loaded yet. Delaying for about 10 secs should be enough...


    Sent from my iPad using Tapatalk
     

Share This Page