Advertisement
naej

mining turtle 2

Sep 24th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.67 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. local turtleOrientation = "n"
  7. local turtleXPos = 0
  8. local turtleYPos = 0
  9. local turtleZPos = 0
  10.  
  11. -------------------------------------------
  12. --         Fonctions pour miner
  13. -------------------------------------------
  14.  
  15. -- Fonction comparaison de block en face
  16. function compareBlockFront()
  17.     if turtle.detect() == true then
  18.         local isDetect, inspectedBlock = turtle.inspect()
  19.         if isDetect == true then
  20.             for i=1, table.getn(junkBlock) do
  21.                 if junkBlock[i] == inspectedBlock.name then
  22.                     isJunk = true
  23.                     return isJunk
  24.                 end
  25.             end
  26.             isJunk = false
  27.             return isJunk
  28.         end
  29.     end
  30. end
  31. -- Fonction comparaison de block en haut
  32. function compareBlockUp()
  33.     if turtle.detectUp() == true then
  34.         local isDetect, inspectedBlock = turtle.inspectUp()
  35.         if isDetect == true then
  36.             for i=1, table.getn(junkBlock) do
  37.                 if junkBlock[i] == inspectedBlock.name then
  38.                     isJunk = true
  39.                     return isJunk
  40.                 end
  41.             end
  42.             isJunk = false
  43.             return isJunk
  44.         end
  45.     end
  46. end
  47. -- Fonction comparaison de block en bas
  48. function compareBlockDown()
  49.     if turtle.detectDown() == true then
  50.         local isDetect, inspectedBlock = turtle.inspectDown()
  51.         if isDetect == true then
  52.             for i=1, table.getn(junkBlock) do
  53.                 if junkBlock[i] == inspectedBlock.name then
  54.                     isJunk = true
  55.                     return isJunk
  56.                 end
  57.             end
  58.             isJunk = false
  59.             return isJunk
  60.         end
  61.     end
  62. end
  63.  
  64. -- Fonction pour boucher les fuites en face
  65. function leakPluggingFront()
  66.     if turtle.detect() == false then
  67.         turtle.select(1)
  68.         turtle.place()
  69.         return true
  70.     else
  71.         return false
  72.     end
  73. end
  74. -- Fonction pour boucher les fuites en haut
  75. function leakPluggingUp()
  76.     if turtle.detectUp() == false then
  77.         turtle.select(1)
  78.         turtle.placeUp()
  79.         return true
  80.     else
  81.         return false
  82.     end
  83. end
  84. -- Fonction pour boucher les fuites en bas
  85. function leakPluggingDown()
  86.     if turtle.detectDown() == false then
  87.         turtle.select(1)
  88.         turtle.placeDown()
  89.         return true
  90.     else
  91.         return false
  92.     end
  93. end
  94.  
  95. -- Fonction pour miner en face
  96. function digFront()
  97.     turtle.dig()
  98.     turtle.select(2)
  99.     turtle.place()
  100. end
  101. -- Fonction pour miner en haut
  102. function digUp()
  103.     turtle.digUp()
  104.     turtle.select(2)
  105.     turtle.placeUp()
  106. end
  107. -- Fonction pour miner en bas
  108. function digDown()
  109.     turtle.digDown()
  110.     turtle.select(2)
  111.     turtle.placeDown()
  112. end
  113.  
  114. -- Changement de ligne de minage
  115. function newRaw()
  116.     moveDown(1)
  117.     turnLeft(1)
  118.     moveForward(3)
  119.     turnLeft(1)
  120. end
  121. -- Ligne de minage
  122. function digRaw(lenth)
  123.     for i=1, lenth do
  124.         moveForward(1)
  125.         turnLeft(1)
  126.         if compareBlockFront() == false then
  127.             digFront()
  128.         end
  129.         turnRight(2)
  130.         if compareBlockFront() == false then
  131.             digFront()
  132.         end
  133.         turnLeft(1)
  134.         if compareBlockDown() == false then
  135.             digDown()
  136.         end
  137.         i=i+1
  138.     end
  139.     leakPluggingFront()
  140.     moveUp(1)
  141.     leakPluggingFront()
  142.     turnRight(1)
  143.     leakPluggingFront()
  144.     turnLeft(2)
  145.     leakPluggingFront()
  146.     turnLeft(1)
  147.     for i=1, lenth do
  148.         moveForward(1)
  149.         turnLeft(1)
  150.         if compareBlockFront() == false then
  151.             digFront()
  152.         end
  153.         turnRight(2)
  154.         if compareBlockFront() == false then
  155.             digFront()
  156.         end
  157.         turnLeft(1)
  158.         if compareBlockUp() == false then
  159.             digUp()
  160.         end
  161.         i=i+1
  162.     end
  163. end
  164.  
  165. -------------------------------------------
  166. --      Fonctions de positionnement
  167. -------------------------------------------
  168.  
  169. -- Fonction de maj de l'orientation
  170. function setOrientTurtle(c)
  171.     if c == "l" then
  172.         if turtleOrientation == "n" then
  173.             turtleOrientation = "w"
  174.         elseif turtleOrientation == "e" then
  175.             turtleOrientation = "n"
  176.         elseif turtleOrientation == "s" then
  177.             turtleOrientation = "e"
  178.         elseif turtleOrientation == "w" then
  179.             turtleOrientation = "s"
  180.         end
  181.     elseif c == "r" then
  182.         if turtleOrientation == "n" then
  183.             turtleOrientation = "e"
  184.         elseif turtleOrientation == "e" then
  185.             turtleOrientation = "s"
  186.         elseif turtleOrientation == "s" then
  187.             turtleOrientation = "w"
  188.         elseif turtleOrientation == "w" then
  189.             turtleOrientation = "n"
  190.         end
  191.     end
  192.     print("new orientation : " .. turtleOrientation)
  193. end
  194.  
  195. -- Fonction position courante
  196. function setCurrentPosition(d)
  197.     if d == "f" and turtleOrientation == "n" then
  198.         -- code moving north
  199.         -- z-
  200.         turtleZPos = turtleZPos - 1
  201.     elseif d == "f" and turtleOrientation == "e" then
  202.         -- code moving east
  203.         -- x+
  204.         turtleXPos = turtleXPos + 1
  205.     elseif d == "f" and turtleOrientation == "s" then
  206.         -- code moving south
  207.         -- z+
  208.         turtleZPos = turtleZPos + 1
  209.     elseif d == "f" and turtleOrientation == "w" then
  210.         -- code moving west
  211.         -- x-
  212.         turtleXPos = turtleXPos - 1
  213.     elseif d == "u" then
  214.         -- code moving up
  215.         --y+
  216.         turtleYPos = turtleYPos + 1
  217.     elseif d == "d" then
  218.         -- code moving down
  219.         -- y-
  220.         turtleYPos = turtleYPos - 1
  221.     end
  222.     print("new position : x=" .. turtleXPos .. ", y=" .. turtleYPos .. ", z=" .. turtleZPos)
  223. end
  224.  
  225. -------------------------------------------
  226. --     Fonctions pour le deplacement
  227. -------------------------------------------
  228.  
  229. -- Fonction pour se deplacer en avant
  230. function moveForward(lenth)
  231.     floor = floor or false
  232.     for i=1, lenth do
  233.         if turtle.detect() == false then
  234.             while turtle.forward() == false do
  235.                 turtle.attack()
  236.                 os.sleep(0.5)
  237.             end
  238.         else
  239.             while turtle.forward() == false do
  240.                 turtle.dig()
  241.                 os.sleep(0.5)
  242.             end
  243.         end
  244.         setCurrentPosition("f")
  245.         i=i+1
  246.     end
  247. end
  248. -- Fonction pour se deplacer en haut
  249. function moveUp(lenth)
  250.     for i=1, lenth do
  251.         if turtle.detectUp() == false then
  252.             while turtle.up() == false do
  253.                 turtle.attack()
  254.                 os.sleep(0.5)
  255.             end
  256.         else
  257.             while turtle.up() == false do
  258.                 turtle.digUp()
  259.                 os.sleep(0.5)
  260.             end
  261.         end
  262.         setCurrentPosition("u")
  263.         i=i+1
  264.     end
  265. end
  266. -- Fonction pour se deplacer en bas
  267. function moveDown(lenth)
  268.     for i=1, lenth do
  269.         if turtle.detectDown() == false then
  270.             while turtle.down() == false do
  271.                 turtle.attackDown()
  272.                 os.sleep(0.5)
  273.             end
  274.         else
  275.             while turtle.down() == false do
  276.                 turtle.dig()
  277.                 os.sleep(0.5)
  278.             end
  279.         end
  280.         setCurrentPosition("d")
  281.         i=i+1
  282.     end
  283. end
  284. -- Fonction pour tourner a droite
  285. function turnRight(nb)
  286.     for i=1, nb do
  287.         turtle.turnRight()
  288.         setOrientTurtle("r")
  289.         i=i+1
  290.     end
  291. end
  292. -- Fonction pour tourner a gauche
  293. function turnLeft(nb)
  294.     for i=1, nb do
  295.         turtle.turnLeft()
  296.         setOrientTurtle("l")
  297.         i=i+1
  298.     end
  299. end
  300.  
  301. -------------------------------------------
  302. --            Inventaire
  303. -------------------------------------------
  304.  
  305. -- placer un block en face
  306. function place(slot)
  307.     slot = slot or turtle.getSelectedSlot()
  308.     turtle.select(slot)
  309.     turtle.place()
  310. end
  311. -- placer un block en haut
  312. function placeUp(slot)
  313.     slot = slot or turtle.getSelectedSlot()
  314.     turtle.select(slot)
  315.     turtle.placeUp()
  316. end
  317. -- placer un block en bas
  318. function placeDown(slot)
  319.     slot = slot or turtle.getSelectedSlot()
  320.     turtle.select(slot)
  321.     turtle.placeDown()
  322. end
  323.  
  324. -- gestion des slots rΓ©servΓ©s
  325.  
  326. -------------------------------------------
  327. --         Gestion du carburant
  328. -------------------------------------------
  329.  
  330. -- Controle du niveau de carburant
  331. function fuelLevel(lenth)
  332.     fuelLevel = turtle.getFuelLevel()
  333.     if fuelLevel <= lenth + 5 then
  334.         goRefuel()
  335.     end
  336. end
  337. -- Retour pour faire le plein de carburant
  338. function goRefuel()
  339.     oldPosX = turtleXPos
  340.     oldPosY = turtleYPos
  341.     oldPosZ = turtleZPos
  342.     moveXgo = turtleXPos * -1
  343.     moveYgo = turtleYPos * -1
  344.     moveZgo = turtleZPos * -1
  345.     if moveXgo < 0 then
  346.         while turtleOrientation ~= "w" do
  347.             turnRight(1)
  348.         end
  349.         moveForward(math.abs(moveXgo))
  350.     elseif 0 < moveXgo then
  351.         while turtleOrientation ~= "e" do
  352.             turnLeft(1)
  353.         end
  354.         moveForward(moveXgo)
  355.     elseif moveZgo < 0 then
  356.         while turtleOrientation ~= "s" do
  357.             turnRight(1)
  358.         end
  359.         moveForward(math.abs(moveZgo))
  360.     elseif 0 < moveZgo then
  361.         while turtleOrientation ~= "n" do
  362.             turnLeft(1)
  363.         end
  364.         moveForward(moveZgo)
  365.     elseif moveYgo < 0 then
  366.         moveUp(1)
  367.     elseif 0 < moveYgo
  368.         moveDown(1)
  369.     end
  370.     -- orienter la turtle vers le coffre de carburant
  371.     -- vider l'inventaire au passage
  372.     -- renvoyer la turtle au point de minage
  373. end
  374.  
  375.  
  376. -- Recharger en carburant
  377.  
  378.  
  379.  
  380. -------------------------------------------
  381. --            Mise en route
  382. -------------------------------------------
  383.  
  384. -- Initialisation du minage
  385. print("I am in what direction ?")
  386. print("n = north")
  387. print("e = east")
  388. print("s = south")
  389. print("w = west")
  390. turtleOrientation = read()
  391.  
  392.  
  393. -- saisie des dimentions de minage
  394. print("Lenth of eatch raw ?")
  395. rawLenth = read()
  396. print("Number of raw ?")
  397. rawNumber = read()
  398.  
  399. for i=1, rawNumber do
  400.     digRaw(rawLenth)
  401.     newRaw()
  402. end
  403. turnLeft(1)
  404. moveUp(1)
  405. moveForward(rawNumber*3)
  406. turnLeft(1)
  407. moveDown(1)
  408. moveForward(1)
  409. -- vider l'inventaire
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement