Advertisement
Doskyft

Mineur3000

Jan 18th, 2022 (edited)
564
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function forwardAndDigTopAndDown()
  2.   forwardAndDig()
  3.  
  4.   if turtle.inspectDown() then
  5.     turtle.digDown()
  6.   end
  7.   if turtle.inspectUp() then
  8.     turtle.digUp()
  9.   end
  10. end
  11.  
  12. function halfTurnAndDigAround(direction)
  13.   if direction == 'left' then
  14.     turtle.turnLeft()
  15.   elseif direction == 'right' then
  16.     turtle.turnRight()
  17.   end
  18.  
  19.   forwardAndDigTopAndDown()
  20.  
  21.   if direction == 'left' then
  22.     turtle.turnLeft()
  23.   elseif direction == 'right' then
  24.     turtle.turnRight()
  25.   end
  26. end
  27.  
  28. function forwardAndDig()
  29.   if turtle.inspect() then
  30.     turtle.dig()
  31.   end
  32.  
  33.   turtle.forward()
  34. end
  35.  
  36. function exitWithMessage(msg)
  37.   print(msg)
  38.  
  39.   exit()
  40. end
  41.  
  42. function checkSpaceFree()
  43.   local i = 16
  44.   local free = false
  45.  
  46.   while i > 0 do
  47.     turtle.select(i)
  48.  
  49.     if turtle.getItemCount() == 0 then
  50.       free = true
  51.     end
  52.  
  53.     i = i - 1
  54.   end
  55.  
  56.   return free
  57. end
  58.  
  59. function cleanTurtle()
  60.   if turtle.inspectDown() then
  61.     turtle.digDown()
  62.   end
  63.  
  64.   turtle.select(1)
  65.  
  66.   if not checkIsChestInSlot() then
  67.     exitWithMessage('Plus de coffres dans le slot 1 !')
  68.   end
  69.  
  70.   inspectFrontStatus, inspectFrontData = turtle.inspect()
  71.   inspectDownStatus, inspectDownData = turtle.inspectDown()
  72.   inspectUpStatus, inspectUpData = turtle.inspectUp()
  73.  
  74.   if
  75.     (inspectFrontStatus and inspectFrontData['name'] == 'minecraft:lava') or
  76.     (inspectDownStatus and inspectDownData['name'] == 'minecraft:lava') or
  77.     (inspectUpStatus and inspectUpData['name'] == 'minecraft:lava')
  78.   then
  79.     return
  80.   end
  81.  
  82.   if not turtle.placeDown() then
  83.     exitWithMessage('Impossible de placer un coffre sous la turtle')
  84.   end
  85.  
  86.   local slot = 16
  87.  
  88.   while slot > 1 do
  89.     if not checkIsTorchInSlot() then
  90.       turtle.select(slot)
  91.       turtle.dropDown()
  92.     end
  93.  
  94.     slot = slot - 1
  95.   end
  96. end
  97.  
  98. function dropUselessItem()
  99.   local slot = 16
  100.  
  101.   while slot > 0 do
  102.     turtle.select(slot)
  103.  
  104.     item = turtle.getItemDetail()
  105.  
  106.     uselessItem = {
  107.       'minecraft:cobblestone',
  108.       'minecraft:stone',
  109.       'minecraft:dirt'
  110.     }
  111.  
  112.     for i = 0, 3 do
  113.       if item and item['name'] == uselessItem[i] then
  114.         turtle.drop()
  115.       end
  116.     end
  117.  
  118.     slot = slot - 1
  119.   end
  120. end
  121.  
  122. function checkIsChestInSlot()
  123.   local item = turtle.getItemDetail()
  124.  
  125.   return item and string.match(item['name'], ".*chest")
  126. end
  127.  
  128. function checkIsTorchInSlot()
  129.   local item = turtle.getItemDetail()
  130.  
  131.   return item and string.match(item['name'], ".*torch")
  132. end
  133.  
  134. function placeTorch()
  135.   if turtle.inspectDown() then
  136.     turtle.digDown()
  137.   end
  138.  
  139.   turtle.select(2)
  140.  
  141.   if checkIsTorchInSlot() then
  142.     turtle.placeDown()
  143.   end
  144. end
  145.  
  146. function start()
  147.   print("Bienvenue dans le mineur 3000 !")
  148.  
  149.   turtle.select(1)
  150.  
  151.   if not checkIsChestInSlot() then
  152.     exitWithMessage("la turtle doit avoir des coffres dans sont premier slot !")
  153.   end
  154. end
  155.  
  156. local lengthLine = 25
  157. local lengthMax = 1000
  158. local move = 0
  159. local torchInterval = 16
  160. local direction = 'left'
  161.  
  162. start()
  163.  
  164. while true do
  165.   forwardAndDigTopAndDown()
  166.  
  167.   if move ~= 0 and move % lengthLine == 0 then
  168.     halfTurnAndDigAround(direction)
  169.     dropUselessItem()
  170.  
  171.     if direction == 'left' then
  172.       direction = 'right'
  173.     elseif direction == 'right' then
  174.       direction = 'left'
  175.     else
  176.       exitWithMessage('Direction incorrect')
  177.     end
  178.   end
  179.  
  180.   if move ~= 0 and move % torchInterval == 0 then
  181.     placeTorch()
  182.   end
  183.  
  184.   if not checkSpaceFree() then
  185.     cleanTurtle()
  186.   end
  187.  
  188.   if move > lengthMax then
  189.     exitWithMessage('Travail terminé')
  190.   end
  191.  
  192.   move = move + 1
  193.  
  194.   term.clear()
  195.   term.setCursorPos(1, 1)
  196.  
  197.   print(move .. '/' .. lengthMax)
  198. end
  199.  
  200. exitWithMessage("end")
  201.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement