Advertisement
Guest User

mana

a guest
May 22nd, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. local idleStep = 8
  2. local rechargeStep = 4
  3. --mana
  4. local target = 14 --/15
  5. --comparator
  6. local compSide = "front"
  7. ---cakeChest
  8. local chestSide = "bottom"
  9. local reverse = "up"
  10. --turtle
  11. local buffer = 16
  12. local cakeSlot = 1
  13.  
  14. local chest = peripheral.wrap(chestSide)
  15. print(chest.getInventoryName().." found.")
  16.  
  17. function lowCake()
  18.   return turtle.getItemCount(cakeSlot) < (buffer/2)
  19. end
  20.  
  21. function round(n)
  22.   return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
  23. end  
  24.  
  25. function refillCake()
  26.   if lowCake() then
  27.     print("Cake level is low(inf. "..(buffer/2)..")")
  28.     local as = chest.getAllStacks(false)
  29.     for i,slot in pairs(as) do
  30.       if slot ~= nil and slot.name == "cake" and lowCake() then
  31.         print(chest.pushItem(reverse,i,(buffer-turtle.getItemCount(cakeSlot)),cakeSlot).." cakes retrieved from slot "..i..".")
  32.       end
  33.     end
  34.   end  
  35. end
  36.  
  37. function getLevel()
  38.   local lvl = rs.getAnalogInput(compSide)
  39.   print("Mana level is "..round(lvl*100/15).."%")
  40.   return lvl
  41. end
  42.  
  43. while true do
  44.  
  45.   while getLevel() < target do
  46.     print("RECHARGING!")
  47.     if not turtle.detectUp() then
  48.       turtle.select(cakeSlot)
  49.       refillCake()
  50.       if not turtle.placeUp() then
  51.         print("Error placing cake!")
  52.       end
  53.     else
  54.       print("Previous cake still present!")
  55.     end
  56.     sleep(rechargeStep)
  57.   end
  58.  
  59.   print("IDLE")
  60.   sleep(idleStep)
  61.  
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement