Advertisement
PETREKILLAH

stripminer

Sep 21st, 2024 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. TRAVEL_DIST = 64
  2.  
  3. function EatFuel()
  4.     for i = 1,16,1 do
  5.         local data = turtle.getItemDetail(i)
  6.         if data then
  7.             if data.name == "minecraft:coal" then
  8.                 turtle.select(i)
  9.                 turtle.refuel(1)
  10.                 return true
  11.             end
  12.         end
  13.     end
  14.     return false
  15. end
  16.  
  17. function CanGetHome(dist)
  18.     local fuelLevel = turtle.getFuelLevel()
  19.     if fuelLevel-1 <= dist then
  20.         local res = EatFuel()
  21.         return res
  22.     end
  23.     return true
  24. end
  25.  
  26. function ManageInventory()
  27.     AllowedItemsTable = {
  28.         ["minecraft:diamond"] = true,
  29.         ["minecraft:emerald"] = true,
  30.         ["minecraft:redstone"] = true,
  31.         ["minecraft:lapiz"] = true,
  32.         ["minecraft:coal"] = true,
  33.         ["minecraft:iron_ore"] = true,
  34.         ["galacticraftcore:basic_item"] = true,
  35.         ["galacticraftcore:basic_block_core"] = true,
  36.         ["minecraft:dye"] = true
  37.     }
  38.     for i = 1,16,1 do
  39.         local data = turtle.getItemDetail(i)
  40.         if data then
  41.             if AllowedItemsTable[data.name] == nil then
  42.                 turtle.select(i)
  43.                 turtle.drop()
  44.             end
  45.         end
  46.     end
  47.  
  48.     turtle.select(1)
  49. end
  50.  
  51.  
  52. function CheckFuelAndRefuel()
  53.     local fuelLevel = turtle.getFuelLevel()
  54.     if fuelLevel == 0 then
  55.         if EatFuel() == false then
  56.             return false
  57.         end
  58.     end
  59. end
  60.  
  61. function Mine()
  62.     local distance = 0
  63.     for i = 1,TRAVEL_DIST,1 do
  64.         local didDig = false
  65.         if CanGetHome(distance) then
  66.             local success, data = turtle.inspect()
  67.             if success then
  68.                 if data.name == "minecraft:gravel" or data.name == "minecraft:sand" then
  69.                     while(success) do
  70.                         didDig = turtle.dig() or didDig
  71.                         success, data = turtle.inspect()
  72.                     end
  73.                 else
  74.                     didDig = turtle.dig() or didDig
  75.                 end
  76.             end
  77.  
  78.             turtle.forward()
  79.             distance = distance + 1
  80.             didDig = turtle.digUp() or didDig
  81.             if didDig then
  82.                 turtle.suck()
  83.                 ManageInventory()
  84.             end
  85.         else
  86.             print("I can't get home if I continue")
  87.             break
  88.         end
  89.     end
  90.    
  91.     print("Going home")
  92.     for i = 1,distance,1 do
  93.         turtle.back()
  94.     end
  95. end
  96.  
  97. function Iterate()
  98.     local fuelLevel = turtle.getFuelLevel()
  99.     if fuelLevel-3 <= 0 then
  100.         local res = EatFuel()
  101.         if res == false then
  102.             print("Not enough fuel to mine another tunnel")
  103.             return false
  104.         end
  105.     end
  106.     turtle.turnLeft()
  107.     turtle.dig()
  108.     turtle.forward()
  109.     turtle.digUp()
  110.     turtle.dig()
  111.     turtle.forward()
  112.     turtle.digUp()
  113.     turtle.dig()
  114.     turtle.forward()
  115.     turtle.digUp()
  116.     turtle.turnRight()
  117. end
  118.  
  119. function main()
  120.     while true do
  121.         Mine()
  122.         local success = Iterate()
  123.         if success == false then
  124.             return
  125.         end
  126.     end
  127. end
  128.  
  129.  
  130. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement