Advertisement
lucifersamfr

EssentiaJarFiller

May 21st, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local chest = peripheral.wrap("bottom")
  2. local chestToTurtle = "up"
  3. local jarSide = "top"
  4. local tSlot = 1
  5. local aspect = "herba"
  6.  
  7. function printItemSlot(slot)
  8.   if slot.display_name ~= nil then  print("display_name : "..slot.display_name) end
  9.   if slot.qty ~= nil then           print("qty          : "..slot.qty) end
  10.   if slot.max_size ~= nil then      print("max_size     : "..slot.max_size) end
  11.   if slot.max_dmg ~= nil then       print("max_dmg      : "..slot.max_dmg) end
  12.   if slot.raw_name ~= nil then      print("raw_name     : "..slot.raw_name) end
  13.   if slot.dmg ~= nil then           print("dmg          : "..slot.dmg) end
  14.   if slot.id ~= nil then            print("id           : "..slot.id) end
  15.   if slot.name ~= nil then          print("name         : "..slot.name) end
  16.   --if slot.mod_id ~= nil then        print("mod_id       : "..slot.mod_id) end
  17. end
  18.  
  19. function emptyJarSlot()
  20.   local as = chest.getAllStacks(false)
  21.   for slot,content in pairs(as) do
  22.     if content.name == "blockJar" then
  23.       return slot
  24.     end
  25.   end
  26.   return 0
  27. end
  28.  
  29. function init()
  30.   print("Emptying turtle inventory")
  31.   for i=1,16 do
  32.     if turtle.getItemCount(i) > 0 then
  33.       chest.pullItem(chestToTurtle,i)
  34.     end
  35.   end
  36.  
  37.   while not turtle.detectUp() do
  38.     print("No Jar refilling!")
  39.    
  40.     while turtle.getItemCount(tSlot) < 1 do
  41.       print("Retrieving an empty jar from the chest")
  42.       local ejs =emptyJarSlot()
  43.       if ejs > 0 then
  44.         chest.pushItemIntoSlot(chestToTurtle,ejs,tSlot,1)
  45.       end
  46.       sleep(1)
  47.     end
  48.     print("The empty Jar has been retrieved from the chest")
  49.  
  50.     turtle.select(tSlot)
  51.     print("Place the empty jar for refilling")
  52.     while not turtle.placeUp() do
  53.       print("Cannot place the jar. Retry in a few seconds...")
  54.       sleep(1)
  55.     end
  56.     sleep(1)
  57.   end
  58. end
  59.  
  60. function getHerbaLevel(side)
  61.   return peripheral.call(side,"getAspectCount",aspect)
  62. end
  63.  
  64. function getFullJar()
  65.   if not turtle.detectUp() then
  66.     print("No jar refilling")
  67.     return false
  68.   end
  69.  
  70.   while getHerbaLevel(jarSide) < 64 do
  71.     print("Jar not filled yet. Waiting...")
  72.     sleep(2)
  73.   end
  74.  
  75.   turtle.select(tSlot)
  76.   while not turtle.digUp() do
  77.     print("Cannot dig the jar. Retry in a few seconds...")
  78.     sleep(1)
  79.   end
  80.   if turtle.getItemCount(tSlot) < 1 then
  81.     print("Jar digged but not found in turtle inventory.")
  82.     return false
  83.   end
  84.   while turtle.getItemCount(tSlot) > 0 do
  85.     chest.pullItem(chestToTurtle,tSlot)
  86.     sleep(1)
  87.   end
  88.   print("Jar sent to cheest")
  89.   return true  
  90. end
  91.  
  92. while true do
  93.   init()
  94.   getFullJar()
  95.   sleep(1)
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement