Advertisement
Blackhome

Basic Turtle Movements (save as move)

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