Advertisement
CaptainSpaceCat

Auto Ex Nihilo Crafter

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