Advertisement
Gioves

QuarryV1.0Alpha

Oct 19th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.68 KB | None | 0 0
  1. --XsgZ1itp
  2. -- pastebin get XsgZ1itp startup
  3. local firstSlotBlackList = 1 --Slots for compare dirt/stone/...
  4. local lastSlotBlackList = 4
  5.  
  6. local firstSlot = 5 --Slots for store ore
  7. local lastSlot = 12
  8.  
  9. local cobleChestSlot = 13 -- Slots for send/recive items
  10. local useSlot = 14
  11. local coalChestSlot = 15
  12. local enderChestSlot = 16
  13.  
  14. function emptyIfFull() --check if the turtle is full and empty it
  15.     if (turtle.getItemCount(lastSlot-1) > 0) then
  16.         print("Vidange des items...")
  17.         turtle.select(enderChestSlot)
  18.         turtle.placeUp()
  19.         sleep(0.15)
  20.         for slot=firstSlot,lastSlot do
  21.             turtle.select(slot)
  22.             while turtle.getItemCount(slot) > 0 do
  23.                 turtle.dropUp(turtle.getItemCount(slot))
  24.                 if turtle.getItemCount(slot) > 0 then
  25.                     sleep(5)
  26.                 end
  27.             end
  28.         end
  29.         print("Fin")
  30.         turtle.select(enderChestSlot)
  31.         turtle.digUp()
  32.     end
  33. end
  34.  
  35. function refuelIfEmpty() --fill the fuel of the turtle
  36.     if turtle.getFuelLevel()<500 then
  37.         print("Remplissage de Coal...")
  38.         turtle.select(coalChestSlot)
  39.         turtle.placeUp()
  40.         turtle.select(useSlot)
  41.         turtle.suckUp(32)
  42.         turtle.refuel(32)
  43.         print("Fin")
  44.         turtle.select(coalChestSlot)
  45.         turtle.digUp()
  46.     end
  47. end
  48.  
  49. function checkDig() --check if is not blacklisted and dig it if it's true
  50.     local dig = true
  51.     for slot=firstSlotBlackList,lastSlotBlackList do
  52.         turtle.select(slot)
  53.         if turtle.compare() then
  54.             dig = false
  55.         end
  56.     end
  57.     if dig then
  58.         turtle.dig()
  59.     end
  60. end
  61.  
  62. function well() -- dig the well and ores
  63.     local depth = 1
  64.     turtle.digDown()
  65.     turtle.down()
  66.     turtle.digDown()
  67.     while turtle.down() do
  68.         for i=0,3 do
  69.             turtle.turnRight()
  70.             checkDig()
  71.         end
  72.         emptyIfFull()
  73.         depth = depth+1
  74.         turtle.digDown()
  75.     end
  76.     return depth
  77. end
  78.  
  79. function up(depth)
  80.     for i=1,depth do
  81.         turtle.up()
  82.         if turtle.getItemCount(useSlot) <=1 then
  83.             turtle.select(cobleChestSlot)
  84.             turtle.placeUp()
  85.             turtle.select(useSlot)
  86.             turtle.suckUp(64)
  87.             turtle.select(cobleChestSlot)
  88.             turtle.digUp()
  89.             turtle.select(useSlot)
  90.             turtle.placeDown()
  91.         else
  92.             turtle.select(useSlot)
  93.             turtle.placeDown()
  94.         end
  95.     end
  96.     turtle.select(enderChestSlot)
  97.     turtle.placeUp()
  98.     turtle.select(useSlot)
  99.     turtle.dropUp(turtle.getItemCount(slot))
  100.     turtle.select(enderChestSlot)
  101.     turtle.digUp()
  102. end
  103.  
  104. function nextwell() -- move to the next well
  105.     for j=0,4 do
  106.         turtle.forward()
  107.     end
  108. end
  109.  
  110. function firstWell(nb) -- move to the next well
  111.     for i=1,nb do
  112.         turtle.forward()
  113.     end
  114. end
  115.  
  116. function start(nbrPuits, turtleType)
  117.     if(turtleType == 1) then
  118.         print("En cours...")
  119.     elseif(turtleType == 2) then
  120.         firstWell(3)
  121.         print("En cours...")
  122.     elseif(turtleType == 3) then
  123.         firstWell(1)
  124.         print("En cours...")
  125.     elseif(turtleType == 4) then
  126.         firstWell(4)
  127.         print("En cours...")
  128.     else
  129.         firstWell(2)
  130.         print("En cours...")
  131.     end
  132.     for i=1,nbrPuits do
  133.         print("boucle main")
  134.         refuelIfEmpty()
  135.         depth = well()
  136.         print("profondeur :")
  137.         print(depth)
  138.         up(depth)
  139.         nextwell() 
  140.     end
  141.     print("Terminee")
  142. end
  143.    
  144. -------------
  145. --Main Prog
  146. -------------
  147.  
  148. local depth = 0
  149. local nbrPuits
  150. local turtleType
  151.  
  152. print("Quarry v0.1 Alpha")
  153. print("Type de la turtle : 1 a 5. (Syncro)")
  154. turtleType = tonumber(read())
  155. if (turtleType < 1) or (turtleType>5) then
  156.     print("Erreur : Reboot")
  157.     sleep(5)
  158.     os.reboot()
  159. end
  160. term.clear()
  161. term.setCursorPos(1,1)
  162. print("Quarry v0.1 Alpha")
  163. print("Ready...")
  164.  
  165. rednet.open("left")
  166.  
  167. while true do
  168.     local senderId, firstmessage, distance = rednet.receive()
  169.     local senderId, secondmessage, distance = rednet.receive()
  170.     if (tonumber(firstmessage)>0) and (tonumber(firstmessage)<64) and (secondmessage == "start") then
  171.         nbrPuits = tonumber(firstmessage)/4
  172.         start(nbrPuits, turtleType)
  173.     end
  174.     sleep(15)
  175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement