Jameelo

mineLib

Apr 26th, 2025 (edited)
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | Gaming | 0 0
  1. --[[
  2.     Library focussed on moving about & mining
  3. ]]
  4.  
  5. os.loadAPI("common/storageLib.lua")
  6.  
  7. function digForward(length) -- Variable length dig forward command.
  8.     if length == nil then
  9.         length = 1 -- default
  10.     end
  11.     for _ = 1,length,1 do        
  12.         -- keep digging until nothing remains in front of you
  13.         repeat
  14.             turtle.dig()
  15.             os.sleep(0.1)
  16.         until not turtle.detect()
  17.  
  18.         turtle.forward()
  19.         if storageLib.everySlotTaken() == true then
  20.             print("Storage full! Dumping items...")
  21.             dumpItems()
  22.         end
  23.     end
  24. end
  25.  
  26. function placeMoveForward(length, block) -- places the currently selected block & moves forward.
  27.     --[[
  28.         True - returned as length was reached
  29.         False - returned due to lack of items
  30.     ]]
  31.  
  32.     for _ = 1,length,1 do        
  33.         if turtle.getItemCount() == 0 then -- if no blocks are left, reload.
  34.             newSlot = storageLib.findItemBF(block)
  35.             if newSlot > 0 then -- if there is another stack in the inventory
  36.                 turtle.select(newSlot) -- select another instance of the block
  37.             else
  38.                 return false -- ran outta blocks
  39.             end
  40.         end
  41.  
  42.         if turtle.detect() then -- if there is an obstacle, even though there shouldn't be.
  43.             turtle.dig() -- This opens up the possibility of filling the inventory I guess? Not an issue atm.
  44.         end
  45.  
  46.         if not turtle.detectDown() then
  47.             turtle.placeDown()
  48.         end
  49.         turtle.forward()
  50.     end
  51.  
  52.     return true
  53. end
Advertisement
Add Comment
Please, Sign In to add comment