CaptainSpaceCat

AutoSiever

Dec 28th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. local p = peripheral.wrap("right")
  2. local tArgs = {...}
  3.  
  4. if tArgs[1] ~= "gravel" and tArgs[1] ~= "sand" and tArgs[1] ~= "dust" then
  5.     error("Usage: " .. shell.getRunningProgram() .. " <material type>")
  6. end
  7.  
  8. local itemRef = {}
  9. if tArgs[1] == "gravel" then
  10.     itemRef = {
  11.     "exnihilo:exnihilo.iron_broken",
  12.     "exnihilo:exnihilo.copper_broken",
  13.     "exnihilo:exnihilo.tin_broken",
  14.     "exnihilo:exnihilo.aluminum_broken",
  15.     "exnihilo:exnihilo.gold_broken",
  16.     "exnihilo:exnihilo.silver_broken",
  17.     "exnihilo:exnihilo.lead_broken",
  18.     "exnihilo:exnihilo.nickel_broken",
  19.     "exnihilo:exnihilo.platinum_broken"
  20.     }
  21. elseif tArgs[1] == "sand" then
  22.     itemRef = {
  23.     "exnihilo:exnihilo.iron_crushed",
  24.     "exnihilo:exnihilo.copper_crushed",
  25.     "exnihilo:exnihilo.tin_crushed",
  26.     "exnihilo:exnihilo.aluminum_crushed",
  27.     "exnihilo:exnihilo.gold_crushed",
  28.     "exnihilo:exnihilo.silver_crushed",
  29.     "exnihilo:exnihilo.lead_crushed",
  30.     "exnihilo:exnihilo.nickel_crushed",
  31.     "exnihilo:exnihilo.platinum_crushed"
  32.     }
  33. elseif tArgs[1] == "dust" then
  34.     itemRef = {
  35.     "exnihilo:exnihilo.iron_powdered",
  36.     "exnihilo:exnihilo.copper_powdered",
  37.     "exnihilo:exnihilo.tin_powdered",
  38.     "exnihilo:exnihilo.aluminum_powdered",
  39.     "exnihilo:exnihilo.gold_powdered",
  40.     "exnihilo:exnihilo.silver_powdered",
  41.     "exnihilo:exnihilo.lead_powdered",
  42.     "exnihilo:exnihilo.nickel_powdered",
  43.     "exnihilo:exnihilo.platinum_powdered"
  44.     }
  45. end
  46.  
  47. local itemCount = {}
  48.  
  49. function initializeItemCount()
  50.     if fs.exists("_itemCount_") and pcall(getSavedCount) then
  51.     else
  52.         for i = 1, #itemRef do
  53.             itemCount[#itemCount+1] = 0
  54.         end
  55.         saveItemCount()
  56.     end
  57. end
  58.  
  59. function getSavedCount()
  60.     local rFile = fs.open("_itemCount_", "r")
  61.     for i = 1, #itemRef do
  62.         itemCount[#itemCount+1] = tonumber(rFile.readLine())
  63.     end
  64.     rFile.close()
  65. end
  66.  
  67. function saveItemCount()
  68.     local oFile = fs.open("_itemCount_", "w")
  69.     for _, v in pairs(itemCount) do
  70.         oFile.writeLine(v)
  71.     end
  72.     oFile.close()
  73. end
  74.  
  75. function printItemCount()
  76.     term.clear()
  77.     term.setCursorPos(1, 1)
  78.     for _, v in pairs(itemRef) do
  79.         write(v:sub(19, 19) .. " ")
  80.     end
  81.     term.setCursorPos(1, 2)
  82.     for _, v in pairs(itemCount) do
  83.         write(v .. " ")
  84.     end
  85. end
  86.  
  87. function checkItem(i)
  88.     for n = 1, #itemRef do
  89.         if i.name == itemRef[n] then
  90.             return true, n
  91.         end
  92.     end
  93.     return false
  94. end
  95.  
  96. initializeItemCount()
  97. while true do
  98.     printItemCount()
  99.     while not turtle.suck() do
  100.     end
  101.     turtle.select(1)
  102.     info = turtle.getItemDetail()
  103.     ok, num = checkItem(info)
  104.     if ok then
  105.         itemCount[num] = itemCount[num] + 1
  106.         if itemCount[num] == 4 then
  107.             itemCount[num] = 0
  108.             p.pullItem("down", num)
  109.             turtle.transferTo(2, 1)
  110.             turtle.transferTo(5, 1)
  111.             turtle.transferTo(6, 1)
  112.             turtle.craft()
  113.             turtle.dropUp()
  114.         else
  115.             p.pushItem("down", 1, 1, num)
  116.         end
  117.         saveItemCount()
  118.     else
  119.         turtle.dropUp()
  120.     end
  121. end
Add Comment
Please, Sign In to add comment