DigitalMadness

mineSides

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