Advertisement
PETREKILLAH

quarry

Sep 21st, 2024 (edited)
59
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 1 0
  1. function EatFuel()
  2.     for i = 1,16,1 do
  3.         local data = turtle.getItemDetail(i)
  4.         if data then
  5.             if data.name == "minecraft:coal" then
  6.                 turtle.select(i)
  7.                 turtle.refuel(1)
  8.                 return true
  9.             end
  10.         end
  11.     end
  12.     return false
  13. end
  14.  
  15. function CheckFuelAndRefuel()
  16.     local fuelLevel = turtle.getFuelLevel()
  17.     if fuelLevel == 0 then
  18.         if EatFuel() == false then
  19.             return false
  20.         end
  21.     end
  22. end
  23.  
  24. function CanGetHome(dist)
  25.     local fuelLevel = turtle.getFuelLevel()
  26.     if fuelLevel-1 <= dist then
  27.         local res = EatFuel()
  28.         return res
  29.     end
  30.     return true
  31. end
  32.  
  33. function ManageInventory()
  34.     AllowedItemsTable = {
  35.         ["minecraft:diamond"] = true,
  36.         ["minecraft:emerald"] = true,
  37.         ["minecraft:redstone"] = true,
  38.         ["minecraft:lapiz"] = true,
  39.         ["minecraft:coal"] = true,
  40.         ["galacticraftcore:basic_item"] = true,
  41.         ["galacticraftcore:basic_block_core"] = true,
  42.         ["minecraft:dye"] = true
  43.     }
  44.     for i = 1,16,1 do
  45.         local data = turtle.getItemDetail(i)
  46.         if data then
  47.             if AllowedItemsTable[data.name] == nil then
  48.                 turtle.select(i)
  49.                 turtle.drop()
  50.             end
  51.         end
  52.     end
  53. end
  54.  
  55. function Quarry()
  56.     local distance = 0
  57.     local digsuccess = true
  58.     local belowempty = false
  59.     local success = true
  60.     repeat
  61.         digsuccess = turtle.digDown()
  62.         belowempty = not turtle.detectDown()
  63.         success = digsuccess or belowempty
  64.         if success then
  65.             turtle.suckDown()
  66.             ManageInventory()
  67.             if CanGetHome(distance) then
  68.                 turtle.down()
  69.                 distance = distance + 1
  70.             else
  71.                 print("Cant get home with distance " .. distance .. " and fuel " .. turtle.getFuelLevel())
  72.                 break
  73.             end
  74.         else
  75.             print("Cant dig down anymore. So I'm going back up")
  76.         end
  77.     until(success == false)
  78.    
  79.     print("Going home")
  80.     for i = 1,distance,1 do
  81.         turtle.up()
  82.     end
  83. end
  84.  
  85. Quarry()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement