Advertisement
Te-ki

CCTTurbineRotorAutoRepair

Feb 25th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | None | 0 0
  1. -- CCT Turbine Rotor Auto Repair by Teki
  2.  
  3. local freeSlot = 0
  4. local blockDetected, blockDetails = turtle.inspect()
  5. local details = turtle.getItemDetail()
  6. local bladesReady = false
  7. local bladesSlot = 0
  8.  
  9. -- Processing Functions
  10. local function clearInventory()
  11.     for i =1,16 do
  12.         turtle.dropDown(i)
  13.     end
  14. end
  15.  
  16. local function getFirstFreeSlot()
  17.     for i =1,16 do
  18.         if turtle.getItemCount(i) == 0 then
  19.             return i
  20.         end
  21.     end
  22.     return 0
  23. end
  24.  
  25. local function getRotorSlot()
  26.     for i =1,16 do
  27.         details = turtle.getItemDetail(i)
  28.         if details ~= nil and details.name == "Railcraft:part.turbine.rotor" then
  29.             print("Rotor Found in slot " .. i)
  30.             return i
  31.         end
  32.     end
  33.     print("No Rotor Found")
  34.     return 0
  35. end
  36.  
  37. local function getBladesSlot()
  38.     for i =1,16 do
  39.         details = turtle.getItemDetail(i)
  40.         if details ~= nil and details.name == "Railcraft:part.turbine.blade" then
  41.             print("Blades Found in slot " .. i)
  42.             return i
  43.         end
  44.     end
  45.     print("No Blades Found")
  46.     return 0
  47. end
  48.  
  49. -- Main Functions
  50. local function craftBlades()
  51.     clearInventory()
  52.     turtle.select(1)
  53.     turtle.suckDown(8)
  54.     turtle.select(5)
  55.     turtle.suckDown(8)
  56.     turtle.select(9)
  57.     turtle.suckDown(8)
  58.     turtle.craft()
  59. end
  60.  
  61. local function prepareBlades()
  62.     bladesSlot = getBladesSlot()
  63.     if bladesSlot ~= 0 then
  64.         turtle.select(bladesSlot)
  65.         turtle.transferTo(1,1)
  66.         turtle.transferTo(2,1)
  67.         turtle.transferTo(3,1)
  68.         turtle.transferTo(5,1)
  69.         turtle.transferTo(7,1)
  70.         turtle.transferTo(9,1)
  71.         turtle.transferTo(10,1)
  72.         turtle.transferTo(11,1)
  73.         bladesReady = true
  74.         return true
  75.     else
  76.         craftBlades()
  77.     end
  78. end
  79.  
  80. local function checkTurbine()
  81.     blockDetected, blockDetails = turtle.inspect()
  82.     if blockDetected and blockDetails.name == "Railcraft:machine.alpha" and blockDetails.metadata == 1 then
  83.         turtle.select(6)
  84.         if turtle.suck(1) then
  85.             details = turtle.getItemDetail(6)
  86.             if details.count == 1 and details.metadata >= 28000 then
  87.                 print("Turbine Rotor needs to be repaired !")
  88.                 print("Repairing ...")
  89.                 turtle.craft()
  90.                 print("Done !")
  91.             else
  92.                 print("Turbine Rotor is in good enough state")
  93.             end
  94.             turtle.drop(getRotorSlot())
  95.             return true
  96.         else
  97.             print("Can't catch Turbine Rotor")
  98.         end
  99.     else
  100.         print("Not in front of a Steam Turbine Housing ! " .. blockDetails.name .. " " .. blockDetails.metadata)
  101.         return false
  102.     end
  103. end
  104.  
  105. while true do
  106.     if bladesReady then
  107.         checkTurbine()
  108.     else
  109.         if prepareBlades() then
  110.             checkTurbine()
  111.         else
  112.             print("Can't prepare Blades !")
  113.         end
  114.     end
  115.     sleep(10)
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement