Advertisement
naej

mining turtle

Sep 22nd, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.92 KB | None | 0 0
  1. -- variables
  2. local junkBlock = {"minecraft:stone","minecraft:sand","minecraft:dirt"}
  3. local isJunk = false
  4. local rawLenth = 1
  5. local rawNumber = 1
  6.  
  7.  
  8. -------------------------------------------
  9. --         Fonctions pour miner
  10. -------------------------------------------
  11.  
  12. -- Fonction comparaison de block en face
  13. function compareBlockFront()
  14.     if turtle.detect() == true then
  15.         local isDetect, inspectedBlock = turtle.inspect()
  16.         if isDetect == true then
  17.             for i=1, table.getn(junkBlock) do
  18.                 if junkBlock[i] == inspectedBlock.name then
  19.                     isJunk = true
  20.                     return isJunk
  21.                 end
  22.             end
  23.             isJunk = false
  24.             return isJunk
  25.         end
  26.     end
  27. end
  28. -- Fonction comparaison de block en haut
  29. function compareBlockUp()
  30.     if turtle.detectUp() == true then
  31.         local isDetect, inspectedBlock = turtle.inspectUp()
  32.         if isDetect == true then
  33.             for i=1, table.getn(junkBlock) do
  34.                 if junkBlock[i] == inspectedBlock.name then
  35.                     isJunk = true
  36.                     return isJunk
  37.                 end
  38.             end
  39.             isJunk = false
  40.             return isJunk
  41.         end
  42.     end
  43. end
  44. -- Fonction comparaison de block en bas
  45. function compareBlockDown()
  46.     if turtle.detectDown() == true then
  47.         local isDetect, inspectedBlock = turtle.inspectDown()
  48.         if isDetect == true then
  49.             for i=1, table.getn(junkBlock) do
  50.                 if junkBlock[i] == inspectedBlock.name then
  51.                     isJunk = true
  52.                     return isJunk
  53.                 end
  54.             end
  55.             isJunk = false
  56.             return isJunk
  57.         end
  58.     end
  59. end
  60.  
  61. -- Fonction pour boucher les fuites en face
  62. function leakPluggingFront()
  63.     if turtle.detect() == false then
  64.         turtle.select(1)
  65.         turtle.place()
  66.         return true
  67.     else
  68.         return false
  69.     end
  70. end
  71. -- Fonction pour boucher les fuites en haut
  72. function leakPluggingUp()
  73.     if turtle.detectUp() == false then
  74.         turtle.select(1)
  75.         turtle.placeUp()
  76.         return true
  77.     else
  78.         return false
  79.     end
  80. end
  81. -- Fonction pour boucher les fuites en bas
  82. function leakPluggingDown()
  83.     if turtle.detectDown() == false then
  84.         turtle.select(1)
  85.         turtle.placeDown()
  86.         return true
  87.     else
  88.         return false
  89.     end
  90. end
  91.  
  92. -- Fonction pour miner en face
  93. function digFront()
  94.     turtle.dig()
  95.     turtle.select(2)
  96.     turtle.place()
  97. end
  98. -- Fonction pour miner en haut
  99. function digUp()
  100.     turtle.digUp()
  101.     turtle.select(2)
  102.     turtle.placeUp()
  103. end
  104. -- Fonction pour miner en bas
  105. function digDown()
  106.     turtle.digDown()
  107.     turtle.select(2)
  108.     turtle.placeDown()
  109. end
  110.  
  111. -- Changement de ligne de minage
  112. function newRaw()
  113.     moveDown(1)
  114.     turnLeft(1)
  115.     moveForward(3)
  116.     turnLeft(1)
  117. end
  118. -- Ligne de minage
  119. function digRaw(lenth)
  120.     for i=1, lenth do
  121.         moveForward(1)
  122.         turnLeft(1)
  123.         if compareBlockFront() == false then
  124.             digFront()
  125.         end
  126.         turnRight(2)
  127.         if compareBlockFront() == false then
  128.             digFront()
  129.         end
  130.         turnLeft(1)
  131.         if compareBlockDown() == false then
  132.             digDown()
  133.         end
  134.         i=i+1
  135.     end
  136.     leakPluggingFront()
  137.     moveUp(1)
  138.     leakPluggingFront()
  139.     turnRight(1)
  140.     leakPluggingFront()
  141.     turnLeft(2)
  142.     leakPluggingFront()
  143.     turnLeft(1)
  144.     for i=1, lenth do
  145.         moveForward(1)
  146.         turnLeft(1)
  147.         if compareBlockFront() == false then
  148.             digFront()
  149.         end
  150.         turnRight(2)
  151.         if compareBlockFront() == false then
  152.             digFront()
  153.         end
  154.         turnLeft(1)
  155.         if compareBlockUp() == false then
  156.             digUp()
  157.         end
  158.         i=i+1
  159.     end
  160. end
  161.  
  162. -------------------------------------------
  163. --     Fonctions pour le deplacement
  164. -------------------------------------------
  165.  
  166. -- Fonction pour se deplacer en avant
  167. function moveForward(lenth,floor,way,endBlock)
  168.     floor = floor or false
  169.     way = way or false
  170.     endBlock = endBlock or false
  171.     for i=1, lenth do
  172.         if turtle.detect() == false then
  173.             while turtle.forward() == false do
  174.                 turtle.attack()
  175.                 os.sleep(0.5)
  176.             end
  177.         else
  178.             while turtle.forward() == false do
  179.                 turtle.dig()
  180.                 os.sleep(0.5)
  181.             end
  182.         end
  183.         if floor == "b" then
  184.             leakPluggingDown()
  185.         elseif floor == "t" then
  186.             leakPluggingUp()
  187.         end
  188.         if way == "l" then
  189.             turnLeft(1)
  190.             leakPluggingFront()
  191.             turnRight(1)
  192.         elseif way == "r" then
  193.             turnRight(1)
  194.             leakPluggingFront()
  195.             turnLeft(1)
  196.         end
  197.         if i == lenth and endBlock == true then
  198.             leakPluggingFront()
  199.         end
  200.         i=i+1
  201.     end
  202. end
  203. -- Fonction pour se deplacer en haut
  204. function moveUp(lenth)
  205.     for i=1, lenth do
  206.         if turtle.detectUp() == false then
  207.             while turtle.up() == false do
  208.                 turtle.attack()
  209.                 os.sleep(0.5)
  210.             end
  211.         else
  212.             while turtle.up() == false do
  213.                 turtle.digUp()
  214.                 os.sleep(0.5)
  215.             end
  216.         end
  217.         i=i+1
  218.     end
  219. end
  220. -- Fonction pour se deplacer en bas
  221. function moveDown(lenth)
  222.     for i=1, lenth do
  223.         if turtle.detectDown() == false then
  224.             while turtle.down() == false do
  225.                 turtle.attackDown()
  226.                 os.sleep(0.5)
  227.             end
  228.         else
  229.             while turtle.forward() == false do
  230.                 turtle.dig()
  231.                 os.sleep(0.5)
  232.             end
  233.         end
  234.         i=i+1
  235.     end
  236. end
  237. -- Fonction pour tourner a droite
  238. function turnRight(nb)
  239.     for i=1, nb do
  240.         turtle.turnRight()
  241.         i=i+1
  242.     end
  243. end
  244. -- Fonction pour tourner a gauche
  245. function turnLeft(nb)
  246.     for i=1, nb do
  247.         turtle.turnLeft()
  248.         i=i+1
  249.     end
  250. end
  251.  
  252. -------------------------------------------
  253. --            Inventaire
  254. -------------------------------------------
  255.  
  256. -- placer un block en face
  257. function place(slot)
  258.     slot = slot or turtle.getSelectedSlot()
  259.     turtle.select(slot)
  260.     turtle.place()
  261. end
  262. -- placer un block en haut
  263. function placeUp(slot)
  264.     slot = slot or turtle.getSelectedSlot()
  265.     turtle.select(slot)
  266.     turtle.placeUp()
  267. end
  268. -- placer un block en bas
  269. function placeDown(slot)
  270.     slot = slot or turtle.getSelectedSlot()
  271.     turtle.select(slot)
  272.     turtle.placeDown()
  273. end
  274.  
  275. -- gestion des slots rΓ©servΓ©s
  276.  
  277. -------------------------------------------
  278. --         Gestion du carburant
  279. -------------------------------------------
  280.  
  281. -- Controle du niveau de carburant
  282.  
  283. -- Recharger en carburant
  284.  
  285.  
  286.  
  287. -------------------------------------------
  288. --            Mise en route
  289. -------------------------------------------
  290.  
  291. -- Creation de la salle de depart
  292. --[[
  293. moveForward(2,"b","l",true)
  294. turnRight(1)
  295. moveForward(1,"b","l")
  296. turnRight(1)
  297. moveForward(2,"b","m",true)
  298. turnLeft(1)
  299. moveForward(1,"b","r")
  300. turnLeft(1)
  301. moveForward(2,"b","r",true)
  302. moveUp(1)
  303. turnLeft(2)
  304. moveForward(2,"t","l",true)
  305. turnRight(1)
  306. moveForward(1,"t","l")
  307. turnRight(1)
  308. moveForward(2,"t","m",true)
  309. turnLeft(1)
  310. moveForward(1,"t","r")
  311. turnLeft(1)
  312. moveForward(2,"t","r")
  313. turnLeft(2)
  314. moveDown(1)
  315. moveForward(1)
  316. turnRight(1)
  317. moveForward(1)
  318. turnRight(1)
  319. place(5)
  320. turnLeft(1)
  321. moveForward(1)
  322. turnRight(1)
  323. place(5)
  324. moveUp(1)
  325. place(5)
  326. turnRight(1)
  327. moveForward(1)
  328. turnLeft(1)
  329. place(5)
  330. turnRight(1)
  331. moveForward(1)
  332. turtle.dig()
  333. place(1)
  334. moveDown(1)
  335. turnLeft(2)
  336. moveForward(1)
  337. turnLeft(1)
  338. moveForward(1)
  339. print('Ready to start ? press "enter"')
  340. ok = read()
  341. --]]
  342. -- saisie des dimentions de minage
  343. print("Lenth of eatch raw ?")
  344. rawLenth = read()
  345. print("Number of raw ?")
  346. rawNumber = read()
  347.  
  348. for i=1, rawNumber do
  349.     digRaw(rawLenth)
  350.     newRaw()
  351. end
  352. turnLeft(1)
  353. moveUp(1)
  354. moveForward(rawNumber*3)
  355. turnLeft(1)
  356. moveDown(1)
  357. moveForward(1)
  358. -- vider l'inventaire
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement