DigitalMadness

mineBoxTall

Aug 1st, 2021 (edited)
913
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Local
  2. local distance = 0 -- How Far Did User Pick
  3. local torchDist = 12 -- When to Place Torch
  4. local onlight = 0
  5. local width = distance
  6. local Fuel = 0 -- if 2 then it is unlimited no fuel needed
  7. local NeedFuel = 0 -- If Fuel Need Then 1 if not Then 0
  8. local Error = 0 -- 0 = No Error and 1 = Error
  9. local Way = 0 -- 0 = Left and 1 = Right
  10.  
  11. --Place torch
  12. local function PlaceTorch()
  13.     if useTorch == "y" then
  14.         if onlight <= 0 then
  15.             repeat
  16.                 if turtle.getItemCount(3) > 0 then
  17.                     turtle.select(3)
  18.                     turtle.placeDown()
  19.                     turtle.select(4)
  20.                     onlight = torchDist
  21.                 else
  22.                     print("turtle run out of torchs")
  23.                     sleep(10)
  24.                 end
  25.             until onlight > 0
  26.         else
  27.             onlight = onlight - 1
  28.         end
  29.     end
  30. end
  31.  
  32. --Empty slot 4 to 16 will go to chest
  33. local function EmptyInventory()
  34.     repeat
  35.         if turtle.getItemCount(1) > 0 then
  36.             turtle.select(1)
  37.             turtle.digDown()
  38.             turtle.placeDown()
  39.             for slot = 4, 16 do
  40.                 turtle.select(slot)
  41.                 turtle.dropDown()
  42.                 sleep(0.5)
  43.             end
  44.             turtle.select(4)
  45.         else
  46.             print("turtle run out of chest")
  47.             sleep(10)
  48.         end
  49.     until turtle.getItemCount(16) == 0
  50. end
  51.  
  52. --Refueling
  53. local function RefuelTurtle()
  54.     if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 10 then
  55.         repeat
  56.             Needfuel = 1
  57.             ItemFuel = turtle.getItemCount(2)
  58.             if ItemFuel > 0 then
  59.                 turtle.select(2)
  60.                 turtle.refuel(1)
  61.                 turtle.select(4)
  62.             else
  63.                 print("turtle run out of fuel")
  64.                 sleep(10)
  65.             end
  66.         until NeedFuel == 0
  67.     end
  68. end
  69.  
  70. --Turn around
  71. local function turnAround()
  72.     if Way == 0 then
  73.         Way = 1
  74.         turtle.turnLeft()
  75.         turtle.dig()
  76.         turtle.forward()
  77.         width = width - 1
  78.         turtle.digUp()
  79.         turtle.digDown()
  80.         turtle.turnLeft()
  81.     elseif Way == 1 then
  82.         Way = 0
  83.         turtle.turnRight()
  84.         turtle.dig()
  85.         turtle.forward()
  86.         width = width - 1
  87.         turtle.digUp()
  88.         turtle.digDown()
  89.         turtle.turnRight()
  90.     end
  91. end
  92.  
  93. --Move forward
  94. local function Forward()
  95.     repeat
  96.         if turtle.getItemCount(16) > 0 then
  97.             EmptyInventory()
  98.         end
  99.         if turtle.detect() then
  100.             turtle.dig()
  101.         end
  102.         if turtle.forward() then -- sometimes sand and gravel and block and mix-up distance
  103.             moves = moves - 1
  104.         end
  105.         if turtle.detectUp() then
  106.             turtle.digUp()
  107.         end
  108.         if turtle.detectDown() then
  109.             turtle.digDown()
  110.         end
  111.         PlaceTorch()
  112.         RefuelTurtle()
  113.     until moves == 0
  114. end
  115.  
  116. --Get to start position
  117. function toStart()
  118.     turtle.turnRight()
  119.     PlaceTorch()
  120.     moves = distance / 2
  121.     Forward()
  122.     turtle.turnLeft()
  123.     onlight = 0
  124. end
  125.  
  126. --Full mining cycle
  127. function Mining()
  128.     turtle.select(4)
  129.     turtle.digDown()
  130.     PlaceTorch()
  131.     width = distance
  132.     repeat
  133.         moves = distance
  134.         Forward()
  135.         turnAround()
  136.     until width == 0
  137.     Forward()
  138. end
  139.  
  140. --Start
  141. print("Hi There Welcome to Mining Turtle Program")
  142. print("Chest in slot 1")
  143. print("Fuel in slot 2")
  144. print("Torch in slot 3")
  145. print("Use torches y/n")
  146. useTorch = read()
  147.  
  148. print("How Far Will Turtle Go")
  149. distance = tonumber(read()) - 1
  150.  
  151. toStart()
  152. Mining()
  153. EmptyInventory()
  154.  
  155. print("Done")
RAW Paste Data