Advertisement
djst3rios

Dj's mining turtle script

Oct 17th, 2023 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 KB | Gaming | 0 0
  1. -- Function to check if an item is in the discard list
  2. local function isItemToDiscard(itemName)
  3.     local discardList = {"minecraft:cobblestone", "minecraft:andesite", "minecraft:granite", "minecraft:stone", "minecraft:diorite", "minecraft:redstone", "minecraft:dirt"}
  4.     local lowercaseItemName = itemName:lower()  -- Convert to lowercase for case-insensitive comparison
  5.     for _, item in ipairs(discardList) do
  6.         if lowercaseItemName == item then
  7.             return true
  8.         end
  9.     end
  10.     return false
  11. end
  12.  
  13. -- Function to refuel the turtle
  14. local function refuelTurtle()
  15.     -- Check if the turtle has fuel
  16.     if turtle.getFuelLevel() < 10 then
  17.         local slot = 1
  18.         while slot <= 16 do
  19.             -- Find the first slot with fuel
  20.             local item = turtle.getItemDetail(slot)
  21.             if item and turtle.select(slot) and turtle.refuel(1) then
  22.                 print("Refueled from slot", slot)
  23.                 turtle.select(1)
  24.                 return
  25.             end
  26.             slot = slot + 1
  27.         end
  28.         print("No fuel found. Please refuel the turtle.")
  29.         os.shutdown()
  30.     end
  31. end
  32.  
  33. local function dropUselessItems()
  34.     for slot = 1, 16 do
  35.         local item = turtle.getItemDetail(slot)
  36.         if item and isItemToDiscard(item.name) then
  37.             turtle.select(slot)
  38.             turtle.drop()
  39.         end
  40.     end
  41.     turtle.select(1)
  42. end
  43.  
  44. -- Parse the command line argument for the length of the mining area
  45. local args = {...}
  46. local length = tonumber(args[1]) or 0
  47.  
  48. print("Length of Mining Area:", length)  -- Print the parsed length
  49.  
  50. if length <= 0 then
  51.     print("Usage: myprogram <length>")
  52.     return
  53. end
  54.  
  55.  
  56. -- Main mining loop
  57. local blocksMined = 0
  58. while blocksMined < length do
  59.     refuelTurtle()  -- Check and refuel the turtle if necessary
  60.     -- Perform the sequence of actions with error handling and adjusted order
  61.     turtle.dig()
  62.  
  63.     turtle.up()
  64.     turtle.dig()
  65.  
  66.     turtle.forward()
  67.     turtle.dig()
  68.  
  69.     turtle.turnLeft()
  70.     turtle.dig()
  71.  
  72.     turtle.turnRight()
  73.     turtle.dig()
  74.  
  75.     turtle.turnRight()
  76.     turtle.dig()
  77.  
  78.     turtle.down()
  79.     turtle.dig()
  80.  
  81.     turtle.turnLeft()
  82.         turtle.dig()
  83.     turtle.turnLeft()
  84.         turtle.dig()
  85.     turtle.turnRight()
  86.  
  87.     blocksMined = blocksMined + 8
  88.     dropUselessItems()
  89.  
  90.     -- Check if we've reached the specified length
  91.     if blocksMined >= length then
  92.         break
  93.     end
  94. end
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement