Advertisement
Blackhome

move

Jan 6th, 2025 (edited)
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | Gaming | 0 0
  1. -- tries to refuel till possible
  2. local function refuelProcess()
  3.     local cnt = 0
  4.     local bFueld = false
  5.     local slot = turtle.getSelectedSlot()
  6.     while not bFueld do
  7.         for i = 1, 16, 1 do
  8.             if turtle.getItemCount(i) > 0 then
  9.                 turtle.select(i)
  10.                 local item = turtle.getItemDetail()
  11.                 if item then
  12.                     if not (item.name == "minecraft:chest") then
  13.                         local ok, err = turtle.refuel()
  14.                     end
  15.                 end
  16.             end
  17.         end
  18.         if turtle.getFuelLevel() > 0 then
  19.             print("New fuel level:   " .. tostring(turtle.getFuelLevel()))
  20.             turtle.select(slot)
  21.             return true
  22.         end
  23.         if cnt == 0 then
  24.             print("Pls enter fuel to continue")
  25.         end
  26.         cnt = 1
  27.     end
  28.     turtle.select(slot)
  29.     return true
  30. end
  31.  
  32. -- Checks if fuel is available or starts refuel process
  33. local function fuelCheck()
  34.     if turtle.getFuelLevel() > 0 then
  35.         return
  36.     else
  37.         refuelProcess()
  38.     end
  39. end
  40.  
  41. -- Digs in given direction till turtle can move
  42. local function Forward()
  43.     fuelCheck()
  44.  
  45.     local b = false
  46.     while not b do
  47.         b = turtle.forward()
  48.         if not b then
  49.             turtle.dig()
  50.         end
  51.     end
  52. end
  53. local function Up()
  54.     fuelCheck()
  55.  
  56.     local b = false
  57.     while not b do
  58.         b = turtle.up()
  59.         if not b then
  60.             turtle.digUp()
  61.         end
  62.     end
  63. end
  64. local function Down()
  65.     fuelCheck()
  66.  
  67.     local b = false
  68.     while not b do
  69.         b = turtle.down()
  70.         if not b then
  71.             turtle.digDown()
  72.         end
  73.     end
  74. end
  75.  
  76. -- Turn turtle 180°
  77. local function turnBack()
  78.     turtle.turnLeft()
  79.     turtle.turnLeft()
  80. end
  81.  
  82. return { Forward = Forward, Up = Up, Down = Down, turnBack = turnBack, refuelProcess = refuelProcess }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement