Advertisement
peptide

Charger

Feb 3rd, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. -- Redstone Energy Cell Charger
  2. -- Top ender chest is for Empty cells
  3. -- Bottom chest is for Full cells
  4.  
  5. p = peripheral.wrap("front") -- Cell management
  6.  
  7. function checkCell()
  8.   -- See if a cell is in front of the turtle, and if it is charged.
  9.   print("Checking for cell")
  10.   cellPresent = turtle.detect()
  11.   if cellPresent == true then
  12.         print("Cell present")
  13.     if p.getEnergyStored("front") == p.getMaxEnergyStored("front") then
  14.         print("Cell fully charged - swapping")
  15.         swapCell()
  16.     else print("Cell not fully charged")
  17.     end
  18.   end
  19.   if cellPresent == false then
  20.         print("No cell detected, placing new cell")
  21.         swapCell()
  22.   end
  23. end
  24.  
  25. function getEmptyCell()
  26.   -- check if there's a cell in inventory, if not, grab one
  27.   if turtle.getItemCount(1) == 0 then turtle.suckUp() end -- pull cell from depleted chest
  28.   return true
  29. end
  30.  
  31. function swapCell()
  32.   print("Swapping cell")
  33.   turtle.dig()
  34.   turtle.dropDown()
  35.   turtle.suckUp()
  36.   turtle.place()
  37.   return true
  38. end
  39.  
  40. while true do
  41.   --check for cell
  42.   -- if present, check charge level - if full, cycle, if not, wait
  43.   checkCell()
  44.   print("Round complete, sleeping for 30 seconds.")
  45.   sleep(30) -- wait 30 seconds for next check.
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement