Firnagzen

Untitled

Oct 29th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. -- Initalise
  2. rs.setBundledOutput("left", 0)
  3. rs.setBundledOutput("left", colors.red)
  4. drawers = peripheral.wrap("front")
  5. screen = peripheral.wrap("bottom")
  6.  
  7. -- Function to help pull to full
  8. function pullHelper(turtle_slot, drawer_slot, number)
  9. local to_pull = number - turtle.getItemCount(turtle_slot)
  10. while to_pull > 0 do
  11. drawers.pushItem("south", drawer_slot, to_pull, turtle_slot)
  12. to_pull = number - turtle.getItemCount(turtle_slot)
  13. sleep(0.1)
  14. end
  15. end
  16.  
  17. -- Make distal name:slot_ID table
  18. drawer_slots = {}
  19. for ID, slot in pairs(drawers.getAllStacks()) do
  20. drawer_slots[slot.all().id] = ID
  21. print(ID, " ", slot.all().id)
  22. end
  23.  
  24. while true do
  25. if rs.getAnalogOutput("top") < 15 then
  26. local total = 0
  27. -- local inventory = {
  28. -- "minecraft:wheat" = 0,
  29. -- "minecraft:soul_sand" = 0,
  30. -- "minecraft:nether_star" = 0
  31. -- }
  32.  
  33. -- Switch off pull before counting
  34. rs.setBundledOutput("left", colors.red)
  35.  
  36. -- Tabulate items in inventory
  37. screen.setText("screen", "Counting items!", 0xffffff)
  38. for i = 1, 16 do
  39. item = turtle.getItemDetail(i)
  40. if item then
  41. -- inventory[item.name] += item.count
  42. total = total + item.count
  43. end
  44. end
  45.  
  46. -- If inventory is empty, refill
  47. if total == 0 then
  48. local drawer_slot = 0
  49.  
  50. -- One nether star
  51. screen.setText("screen", "Refilling star!", 0xFF0000)
  52. drawer_slot = drawer_slots["minecraft:nether_star"]
  53. drawers.pushItem("south", drawer_slot, 1, 1)
  54.  
  55. -- Forty wheat
  56. screen.setText("screen", "Refilling wheat!", 0xFF0000)
  57. drawer_slot = drawer_slots["minecraft:wheat"]
  58. pullHelper(2, drawer_slot, 40)
  59.  
  60. -- Four hundred soul sand
  61. screen.setText("screen", "Refilling soul sand!", 0xFF0000)
  62. drawer_slot = drawer_slots["minecraft:soul_sand"]
  63. for i = 3, 8 do
  64. pullHelper(i, drawer_slot, 60)
  65. end
  66.  
  67. -- And a partridge in a pear tree
  68. pullHelper(9, drawer_slot, 40)
  69. end
  70.  
  71. -- Reenable pull
  72. screen.setText("screen", "Active!", 0xffffff)
  73. rs.setBundledOutput("left", colors.red + colors.green)
  74.  
  75. else
  76. rs.setBundledOutput("left", colors.red)
  77. screen.setText("screen", "Nether stars full!", 0xffffff)
  78. end
  79.  
  80. -- Yield
  81. sleep(1)
  82. end
Advertisement
Add Comment
Please, Sign In to add comment