Firnagzen

Untitled

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