Advertisement
Greyman27

mine_modded

Nov 29th, 2024 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.46 KB | None | 0 0
  1. os.loadAPI("grey_api/move.lua")
  2. os.loadAPI("grey_api/util.lua")
  3.  
  4. local start_depth = 16 --go down this many blocks before digging
  5. local length = 16 --strip length in blocks - forward
  6. local width = 1 --number of strips- right
  7. local height = 1 -- number of levels of strips - down
  8. local current_width = width
  9. local current_height = height
  10. local floor_spacing = 5
  11. local fuels = {"minecraft:coal"}
  12. local minimum_fuel_level = util.max(100, start_depth, length, width, height)
  13. local important_ores = {["minecraft:coal"]=true,["minecraft:diamond_ore"]=true,["minecraft:iron_ore"]=true,["minecraft:redstone_ore"]=true,["minecraft:gold_ore"]=true,["minecraft:lapis_ore"]=true}
  14.  
  15. --tests block in direction dir.
  16. --if block["name"] is in important_ores
  17. function test(dir)
  18.     dir = dir or "forward" --can be forward, up or down
  19.     local b,block = nil
  20.    
  21.     if dir=="up" then
  22.         b,block = turtle.inspectUp()
  23.     elseif dir=="down" then
  24.         b,block = turtle.inspectDown()
  25.     else
  26.         b,block = turtle.inspect()
  27.     end
  28.    
  29.     if b and important_ores[block["name"]] then
  30.         print("Found Vein of "..block["name"])
  31.         return dig_vein(dir)
  32.     else
  33.         if dir=="up" then
  34.             return turtle.digUp()
  35.         elseif dir=="down" then
  36.             return turtle.digDown()
  37.         else
  38.             return turtle.dig()
  39.         end
  40.     end
  41. end
  42.  
  43. function dig_home(go_x,go_y,go_z,go_face)
  44.     if go_x==nil then
  45.         go_x = true
  46.     end
  47.     if go_y==nil then
  48.         go_y = true
  49.     end
  50.     if go_z==nil then
  51.         go_z = true
  52.     end
  53.     if go_face==nil then
  54.         go_face = true
  55.     end
  56.    
  57.     local _x = move.get_x()
  58.     local _y = move.get_y()
  59.     local _z = move.get_z()
  60.    
  61.     --go x
  62.     if go_x then
  63.         if _x > 0 then
  64.             move.face(2)
  65.         else
  66.             move.face(0)
  67.         end
  68.         for i=1,util.abs(_x) do
  69.             test()
  70.             move.go()
  71.             test("up")
  72.             test("down")
  73.         end
  74.     end
  75.     --go z
  76.     if go_z then
  77.         if _z > 0 then
  78.             move.face(3)
  79.         else
  80.             move.face(1)
  81.         end
  82.         for i=1,util.abs(_z) do
  83.             test()
  84.             move.go()
  85.             test("up")
  86.             test("down")
  87.         end
  88.     end
  89.     --go y
  90.     if go_y then
  91.         for i=1,util.abs(_y) do
  92.             if _y>0 then
  93.                 test("down")
  94.                 move.go("down")
  95.             else
  96.                 test("up")
  97.                 move.go("up")
  98.             end
  99.         end
  100.     end
  101.     --go face
  102.     if go_face then
  103.         move.face(0)
  104.     end
  105. end
  106.  
  107. function dig_vein(dir, block_name)
  108.     dir = dir or "forward" --can be forward, up or down
  109.     return true
  110. end
  111.  
  112. function refuel()
  113.     while turtle.getFuelLevel()<=minimum_fuel_level and util.fuel(1,fuels) do end
  114.     if turtle.getFuelLevel()<=0 then
  115.         print("out of fuel")
  116.         return false
  117.     elseif turtle.getFuelLevel()<=minimum_fuel_level then
  118.         print("low on fuel")
  119.     end
  120.     return true
  121. end
  122.  
  123. function mine_line()
  124.     if not refuel() then return false end
  125.     test()
  126.     move.go()
  127.     test("down")
  128.     test("up")
  129.     return not util.is_full()
  130. end
  131.  
  132. function mine_turn()
  133.     if not refuel() then return false end
  134.     local old_facing = move.get_facing()
  135.     move.face(1)
  136.     for i=1,3 do
  137.         test()
  138.         move.go()
  139.         test("up")
  140.         test("down")
  141.     end
  142.     if old_facing==0 then
  143.         move.face(2)
  144.     elseif old_facing==2 then
  145.         move.face(0)
  146.     end
  147.     return true
  148. end
  149.  
  150. function mine_down()
  151.     if not refuel() then return false end
  152.     current_width = width
  153.    
  154.     dig_home(true,false,true,true)
  155.     for i=1,floor_spacing do
  156.         test("down")
  157.         move.go("down",1)
  158.     end
  159.     test("down")
  160.    
  161.     return true
  162. end
  163.  
  164. function mine()
  165.     --mine down to start height
  166.     refuel()
  167.     for i=1,start_depth do
  168.         test("down")
  169.         move.go("down")
  170.     end
  171.     test("down")
  172.    
  173.     while true do
  174.         for i=1,length-1 do
  175.             mine_line()
  176.         end
  177.         current_width = current_width-1
  178.         if current_width<=0 then
  179.             current_height = current_height-1
  180.             if current_height <= 0 then
  181.                 print("done")
  182.                 dig_home()
  183.                 break
  184.             else
  185.                 mine_down()
  186.             end
  187.         else
  188.             mine_turn()
  189.         end
  190.     end
  191. end
  192.  
  193. if length<=0 or width<=0 or height<=0 then print("invalid strip mine dimensions") return false end
  194. move.reset_position()
  195. mine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement