Damaged

Extractor optimize

Sep 8th, 2014
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. local extractor = peripheral.wrap("back")
  2. local storageChest = peripheral.wrap("container_chest_0")
  3.  
  4. local function tableCount(inputTable)
  5.    local count = 0
  6.    for _ in pairs(inputTable) do count = count + 1 end
  7.    return count
  8. end
  9.  
  10. while true do
  11.    print("sleeping")
  12.    sleep(1)
  13.    print("processing redstone")  --   This takes a comparitor input (from an industrial coil) from the right,
  14.                                  --   lets the extractor run if the value is 2+, forces it to run if it is
  15.                                  --   4+ (to prevent explosions) and will stop the extractor if it drops below 1
  16.                                  --   It also checks to see if any actual work needs doing
  17.    --if redstone.getAnalogInput("right") == 0 then
  18.    --   redstone.setOutput("left",false)
  19.    --else
  20.    if redstone.getAnalogInput("right") > 4 then
  21.       redstone.setOutput("left",true)
  22.    elseif tableCount(extractor.getAllStacks()) ~= 0 --[[ and redstone.getAnalogInput("right") > 2 ]] then
  23.       redstone.setOutput("left",true)
  24.    else
  25.       redstone.setOutput("left",false)
  26.    end
  27.    print("exporting stuffed items to chest") -- Grab items from the bottom left 3 slots of the extractor
  28.    for i = 2,4,1 do
  29.       print("slot "..i)
  30.       storageChest.pullItem("west", i)
  31.    end
  32.    print("compressing chest")
  33.    storageChest.condenseItems()
  34.    print("trying to import back") -- Push items back, where they will fit
  35.    for i,data in pairs(storageChest.getAllStacks()) do
  36.       print("chest slot "..i)
  37.       for j = 2,4,1 do
  38.          print("extractor slot "..j)
  39.          if storageChest.pushItemIntoSlot("west",i,j) > 0 then
  40.             print("success!")
  41.          else
  42.             print("didn't fit")
  43.          end
  44.       end
  45.    end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment