Advertisement
ScoutMaester

SkizMiner

Sep 6th, 2023 (edited)
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.13 KB | Gaming | 0 0
  1. MaxZ = 1
  2. CurrentZ = 0
  3. MaxX = 1
  4. CurrentX = 1
  5. MaxY = 1
  6. CurrentY = 1
  7.  
  8. Heading = "n"
  9. PreviousUTurnDirection = "left"
  10. SkipAirSpacesAbove = false
  11. DigOutWidthFirst = false
  12. DebugLevel = 3 -- 0-3
  13.  
  14. function GetFuelLevel()
  15.     local coal = 0
  16.     local details = turtle.getItemDetail()
  17.     while coal == 0 do
  18.         print ("I have " ..turtle.getFuelLevel().. " fuel")
  19.         print ("Would you like to add more fuel? y/n")
  20.         input = read()
  21.         if input("y") then
  22.             print "Confirmed"
  23.         else
  24.             print "Please add coal to slot 1"
  25.             turtle.select(1)
  26.             print "Please confirm when done <Enter>"
  27.             input = read()
  28.             if details.name ~= "minecraft.coal" then
  29.                 print "I do not see coal in slot 1"
  30.             else
  31.                 print "Refueling"
  32.                 turtle.refuel()
  33.                 coal = 1
  34.             end
  35.         end
  36.     end
  37. end
  38.  
  39. function Init()
  40.     local input = ""
  41.  
  42.     print("How far should I dig?")
  43.     MaxZ = tonumber(read())
  44.     if (MaxZ < 1) then MaxZ = 0 end
  45.  
  46.     print("How thic?")
  47.     MaxX = tonumber(read())
  48.     if (MaxX < 1) then MaxX = 1 end
  49.  
  50.     print("aaaand one more question. How tall? ^.^")
  51.     MaxY = tonumber(read())
  52.     if (MaxY < 1) then MaxY = 1 end
  53.  
  54.     print("Oh also should I stop digging up if there's an empty space above? (y/n)")
  55.     input = read()
  56.     if (input == "y" or input == "Y") then
  57.         SkipAirSpacesAbove = true
  58.     end
  59.  
  60.     print("Wait. D-do you want me to dig out the Length first? ^///^ Or Width first? uwu (l/w)")
  61.     input = read()
  62.     if (input == "w" or input == "W") then
  63.         DigOutWidthFirst = true
  64.     end
  65.  
  66.     print("Yes, master :3")
  67.     print("I'll try my best for you hehe")
  68. end
  69.  
  70. function TryPoke()
  71.     if (Heading == "n" and CurrentZ < MaxZ) then
  72.         if (DebugLevel >= 3) then print("- - (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Poking North") end
  73.         turtle.dig()
  74.         return true
  75.     elseif (Heading == "s" and CurrentZ > 1) then
  76.         if (DebugLevel >= 3) then print("- - (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Poking South") end
  77.         turtle.dig()
  78.         return true
  79.     elseif (Heading == "e" and CurrentX < MaxX) then
  80.         if (DebugLevel >= 3) then print("- - (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Poking East") end
  81.         turtle.dig()
  82.         return true
  83.     elseif (Heading == "w" and CurrentX > 1) then
  84.         if (DebugLevel >= 3) then print("- - (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Poking West") end
  85.         turtle.dig()
  86.         return true
  87.     end
  88.  
  89.     return false
  90. end
  91. function TryAdvance()
  92.     if (TryPoke() == false) then return false end
  93.  
  94.     if (Heading == "n" and CurrentZ < MaxZ) then
  95.         if (DebugLevel >= 2) then print("- (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Advancing North") end
  96.         turtle.forward()
  97.         CurrentZ = CurrentZ + 1
  98.         return true
  99.     elseif (Heading == "s" and CurrentZ > 1) then
  100.         if (DebugLevel >= 2) then print("- (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Advancing South") end
  101.         turtle.forward()
  102.         CurrentZ = CurrentZ - 1
  103.         return true
  104.     elseif (Heading == "e" and CurrentX < MaxX) then
  105.         if (DebugLevel >= 2) then print("- (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Advancing East") end
  106.         turtle.forward()
  107.         CurrentX = CurrentX + 1
  108.         return true
  109.     elseif (Heading == "w" and CurrentX > 1) then
  110.         if (DebugLevel >= 2) then print("- (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Advancing West") end
  111.         turtle.forward()
  112.         CurrentX = CurrentX - 1
  113.         return true
  114.     end
  115.  
  116.     return false
  117. end
  118.  
  119. function AdvanceUpward()
  120.     if (DebugLevel >= 3) then print("- - (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Advancing Upward") end
  121.     turtle.digUp()
  122.     turtle.up()
  123.     CurrentY = CurrentY + 1
  124. end
  125. function AdvanceDownward()
  126.     if (DebugLevel >= 3) then print("- - (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Advancing Downward") end
  127.     turtle.digDown()
  128.     turtle.down()
  129.     CurrentY = CurrentY - 1
  130. end
  131. function DigUpToTop()
  132.     if (CurrentY >= MaxY) then return end
  133.  
  134.     if (DebugLevel >= 2) then print("- (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Digging Up To Top") end
  135.  
  136.     while (CurrentY < MaxY) do
  137.         if (SkipAirSpacesAbove and turtle.detectUp() == false) then
  138.             if (DebugLevel >= 3) then print("- - (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Detected Empty Space Above") end
  139.             break
  140.         end
  141.         TryPoke()
  142.         AdvanceUpward()
  143.     end
  144. end
  145. function DigDownToOne()
  146.     if (DebugLevel >= 2) then print("- (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Digging Down To Zero") end
  147.  
  148.     while (CurrentY > 1) do
  149.         TryPoke()
  150.         AdvanceDownward()
  151.     end
  152. end
  153.  
  154. function TryAdvanceTilEndOfLine()
  155.     if (DebugLevel >= 1) then print("(" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Beginning Line") end
  156.     local atDestination = (not TryPoke())
  157.     if (atDestination) then return false end
  158.     while (not atDestination) do
  159.         DigUpToTop()
  160.         TryAdvance()
  161.         DigUpToTop()
  162.         DigDownToOne()
  163.         if (SkipAirSpacesAbove == false) then
  164.             TryAdvance()
  165.         end
  166.         atDestination = (not TryAdvance())
  167.     end
  168.     return true
  169. end
  170.  
  171. function TurnRight()
  172.     if (Heading == "n") then Heading = "e" end
  173.     if (Heading == "e") then Heading = "s" end
  174.     if (Heading == "s") then Heading = "w" end
  175.     if (Heading == "w") then Heading = "n" end
  176.     if (DebugLevel >= 2) then print("- (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Turning Right. Heading = " ..Heading) end
  177.     turtle.turnRight()
  178. end
  179. function TurnLeft()
  180.     if (Heading == "n") then Heading = "w" end
  181.     if (Heading == "w") then Heading = "s" end
  182.     if (Heading == "s") then Heading = "e" end
  183.     if (Heading == "e") then Heading = "n" end
  184.     if (DebugLevel >= 2) then print("- (" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") Turning Left. Heading = " ..Heading) end
  185.     turtle.turnLeft()
  186. end
  187. function Turn()
  188.     if (PreviousUTurnDirection == "left") then
  189.         TurnRight()
  190.         return
  191.     end
  192.     TurnLeft()
  193. end
  194. function TryUTurn()    
  195.     Turn()
  196.     if (not TryAdvance()) then return false end
  197.     Turn()
  198.  
  199.     if (DebugLevel >= 1) then print("(" ..CurrentZ.. "," ..CurrentX.. "," ..CurrentY.. ") UTurning. Heading = " ..Heading) end
  200.     if (PreviousUTurnDirection == "right") then PreviousUTurnDirection = "left"
  201.     elseif (PreviousUTurnDirection == "left") then PreviousUTurnDirection = "right" end
  202.  
  203.     return true
  204. end
  205.  
  206.  
  207.  
  208.  
  209.  
  210. function Main()
  211.     Init()
  212.     if (TryAdvance() == false) then
  213.         print("aw hec you teased me :'(")
  214.         return
  215.     end
  216.     if (DigOutWidthFirst) then
  217.         TurnRight()
  218.         PreviousUTurnDirection = "right"
  219.     end
  220.  
  221.     local done = false
  222.     while (not done) do
  223.         done = (not TryAdvanceTilEndOfLine())
  224.         if (done) then break end
  225.         done = (not TryUTurn())
  226.     end
  227.  
  228.     print("I'm all done! :D")
  229. end
  230.  
  231.  
  232.  
  233. Main()
Tags: Minealone
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement