Advertisement
jig487

stripMiner

Mar 15th, 2024 (edited)
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.25 KB | None | 0 0
  1. --goes through the turtles inventory and drops anything not included in the list.
  2. local function purgeInventory( list )
  3.     local goodItem = false
  4.     for i = 1, 16 do
  5.         goodItem = false
  6.         local itemTbl = turtle.getItemDetail(i)
  7.         for j = 1, #list do
  8.             if itemTbl then
  9.                 if itemTbl.name then
  10.                     if itemTbl.name == list[j] then
  11.                         goodItem = true
  12.                         break
  13.                     end
  14.                 end
  15.             end
  16.         end
  17.         if goodItem == false then
  18.             turtle.select(i)
  19.             turtle.drop()
  20.         end
  21.     end
  22.     turtle.select(1)
  23. end
  24.  
  25. --attempts to move forward. If fails, mines the block/s in front of and above the turtle until it can
  26. local function mineForward(blocks)
  27.     blocks = blocks or 1
  28.     for i = 1, blocks do
  29.         while not turtle.forward() do
  30.             turtle.dig()
  31.         end
  32.         turtle.digUp()
  33.     end
  34. end
  35.  
  36. local function drawDisplay(rowNumber,length,depth)
  37.     term.clear()
  38.     term.setCursorPos(1,1)
  39.     term.setTextColor(colors.yellow)
  40.     term.write("Running: ")
  41.     term.setTextColor(colors.lime)
  42.     term.write("simpleStripMiner")
  43.     term.setTextColor(colors.yellow)
  44.     term.write(" !")
  45.  
  46.     term.setCursorPos(1,3)
  47.     term.setTextColor(colors.orange)
  48.     term.write("Current row: ")
  49.     term.setTextColor(colors.cyan)
  50.     term.write(rowNumber)
  51.     term.setTextColor(colors.orange)
  52.     term.write("/")
  53.     term.setTextColor(colors.blue)
  54.     term.write(length)
  55.  
  56.     local estimatedMined = (rowNumber)*depth*2 + (rowNumber)*6
  57.     local maxBlocks = length*depth*2 + length*6
  58.  
  59.     term.setCursorPos(1,4)
  60.     term.setTextColor(colors.orange)
  61.     term.write("Estimated mined blocks:")
  62.     term.setTextColor(colors.pink)
  63.     term.write(estimatedMined)
  64.     term.setTextColor(colors.orange)
  65.     term.write("/")
  66.     term.setTextColor(colors.magenta)
  67.     term.write(maxBlocks)
  68.     term.setTextColor(colors.orange)
  69.     term.write("!")
  70.  
  71.     term.setCursorPos(1,5)
  72.     term.setTextColor(colors.red)
  73.     term.write("Fuel ")
  74.     term.setTextColor(colors.orange)
  75.     term.write("remaining: ")
  76.     term.setTextColor(colors.gray)
  77.     print(turtle.getFuelLevel())
  78.     term.setTextColor(colors.brown)
  79.     term.write("Blocks ")
  80.     term.setTextColor(colors.orange)
  81.     term.write("remaining: ")
  82.     term.setTextColor(colors.gray)
  83.     term.write(maxBlocks-estimatedMined)
  84.  
  85.     term.setCursorPos(1,8)
  86.     term.setTextColor(colors.orange)
  87.     term.write("* Hold 'ctr + t' to stop!")
  88.     term.setTextColor(colors.red)
  89.     term.setCursorPos(9,8)
  90.     term.write("ctr + t")
  91.     term.setTextColor(colors.orange)
  92.     term.setCursorPos(13,8)
  93.     term.write("+")
  94.  
  95.     term.setCursorPos(1,9)
  96.     print("* Use the 'refuel' command after stopping the program to refuel the turtle!")
  97.     term.setTextColor(colors.red)
  98.     term.setCursorPos(12,9)
  99.     term.write("refuel")
  100.     term.setTextColor(colors.yellow)
  101.     term.setCursorPos(28,9)
  102.     term.write("after")
  103.  
  104.     term.setTextColor(colors.white)
  105. end
  106.  
  107. local function run(length,depth,dir)
  108.     local whitelist = {
  109.         "minecraft:diamond",
  110.         "minecraft:emerald",
  111.         "minecraft:raw_gold",
  112.         "minecraft:raw_iron",
  113.         "minecraft:raw_copper",
  114.         "minecraft:coal",
  115.         "minecraft:lapis_lazuli",
  116.         "minecraft:quartz",
  117.         "minecraft:ancient_debris"
  118.     }
  119.  
  120.     local turn1 = turtle.turnLeft
  121.     local turn2 = turtle.turnRight
  122.  
  123.     if dir == 0 then
  124.         dir = "right"
  125.     else
  126.         dir = "left"
  127.     end
  128.  
  129.     if dir == "right" then
  130.         turn1 = turtle.turnRight
  131.         turn2 = turtle.turnLeft
  132.     end
  133.  
  134.     local blocksSinceLastPurge = 0
  135.  
  136.     drawDisplay(0,length,depth)
  137.  
  138.     for x = 1, length do
  139.         mineForward(depth)
  140.  
  141.         if x%2 ~= 0 then
  142.             turn1()
  143.             mineForward(3)
  144.             turn1()
  145.         else
  146.             turn2()
  147.             mineForward(3)
  148.             turn2()
  149.         end
  150.  
  151.         drawDisplay(x,length,depth)
  152.         blocksSinceLastPurge = blocksSinceLastPurge + depth*2
  153.  
  154.         if blocksSinceLastPurge > 500 then
  155.             purgeInventory(whitelist)
  156.             blocksSinceLastPurge = 0
  157.         end
  158.     end
  159. end
  160.  
  161. return {
  162.     run = run
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement