Advertisement
mathiaas

stripMine

Apr 7th, 2024 (edited)
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. -- be careful of fuel lvl
  2. local args = {...}
  3.  
  4. if #args < 2 then
  5.     print("Usage: stripMine <number of strips> <depth per strip>")
  6.     return
  7. end
  8.  
  9. local strips = tonumber(args[1])
  10. local depth = tonumber(args[2])
  11.  
  12. assert(loadfile("utils"))()
  13. assert(loadfile("movement"))()
  14.  
  15. local blacklist = {
  16.     "minecraft:cobblestone",
  17.     "minecraft:dirt",
  18.     "minecraft:stone",
  19.     "ProjRed:Exploration:projectred.exporation.ore",
  20.     "minecraft:gravel"
  21. }
  22.  
  23. local items = {
  24.     end_chest = "EnderStorage:enderChest"
  25. }
  26.  
  27.  
  28. local function selectiveMining(direction)
  29.     direction = direction or "forward"
  30.     local inspectionMethod
  31.     local digMethod
  32.  
  33.     if direction == "forward" then
  34.         inspectionMethod = turtle.inspect
  35.         digMethod = turtle.dig
  36.     elseif direction == "up" then
  37.         inspectionMethod = turtle.inspectUp
  38.         digMethod = turtle.digUp
  39.     elseif direction == "down" then
  40.         inspectionMethod = turtle.inspectDown
  41.         digMethod = turtle.digDown
  42.     else
  43.         print("selectiveMining(direction): Expects direction to be one of: ['up', 'down','forward', nil]")
  44.         return false
  45.     end
  46.  
  47.     local success, data = inspectionMethod()
  48.     if not success then
  49.         return false
  50.     end
  51.  
  52.     if inList(data.name, blacklist) then
  53.         return false
  54.     end
  55.  
  56.     digMethod()
  57.     return true
  58. end
  59.  
  60.  
  61. local function deposit()
  62.     local inventory = getInventory()
  63.     if #inventory < 10 then
  64.         return false
  65.     end
  66.  
  67.     for k, v in pairs(inventory) do
  68.         if v.name == items.end_chest then
  69.             turtle.select(v.slot)
  70.             turtle.placeUp()
  71.             break
  72.         end
  73.     end
  74.  
  75.     for k, v in pairs(inventory) do
  76.         if v.name ~= items.end_chest then
  77.             turtle.select(v.slot)
  78.             turtle.dropUp()
  79.         end
  80.     end
  81.  
  82.     turtle.digUp()
  83. end
  84.  
  85.  
  86. local function mineLocal()
  87.     --Main section
  88.     while turtle.dig() do end
  89.     f()
  90.     selectiveMining("down")
  91.     while turtle.digUp() do end
  92.     deposit()
  93.     --Left wall
  94.     l()
  95.     selectiveMining()
  96.     u()
  97.     selectiveMining()
  98.     r()
  99.     selectiveMining("up")
  100.     --Right wall
  101.     r()
  102.     selectiveMining()
  103.     d()
  104.     selectiveMining()
  105.     l()
  106. end
  107.  
  108. local function mineStrip(depth)
  109.     for d = 1, depth do
  110.         mineLocal()
  111.     end
  112. end
  113.  
  114. local function handleTurn(strip)
  115.     local turnFunction = (strip % 2 == 1) and turtle.turnLeft or turtle.turnRight
  116.     turnFunction()
  117.     mineLocal()
  118.     mineLocal()
  119.     mineLocal()
  120.     turnFunction()
  121. end
  122.  
  123.  
  124. local function mine(strips, depth)
  125.     for strip = 1, strips do
  126.         mineStrip(depth)
  127.         handleTurn(strip)
  128.     end
  129. end
  130.  
  131. mine(strips, depth)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement