Axow01

exlp

Jun 29th, 2021 (edited)
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.70 KB | None | 0 0
  1. function escape(height, msg) -- escape function
  2.     if (msg) then
  3.         print('Escaping SOS')
  4.     end
  5.     local status = 1
  6.     while (status <= height) do
  7.         local up = turtle.detectUp()
  8.         if (up) then
  9.             turtle.digUp()
  10.         end
  11.         turtle.up()
  12.         status = status + 1
  13.     end
  14.     turtle.forward()
  15.     if msg then
  16.         print('Escaping Finished SOS Mode Shutdown')
  17.     end
  18. end
  19.  
  20. function refuel()
  21.     local inventorySlots = 16
  22.     local inventoryCheckingStatus = 1
  23.     while (inventoryCheckingStatus <= inventorySlots) do
  24.         turtle.select(inventoryCheckingStatus)
  25.         turtle.refuel()
  26.         local checkItem = turtle.getItemDetail(inventoryCheckingStatus)
  27.         if (checkItem ~= nil) then
  28.             if (checkItem.name == 'minecraft:coal' or checkItem.name == 'minecraft:coal_block') then
  29.                 local checkFuel = getFuelPerc()
  30.                 local howMany = turtle.getItemCount(inventoryCheckingStatus)
  31.                 if (checkFuel >= 100) then
  32.                     turtle.transferTo(16, howMany)
  33.                 else
  34.                     turtle.refuel()
  35.                 end
  36.             end
  37.         end
  38.         inventoryCheckingStatus = inventoryCheckingStatus + 1
  39.     end
  40.     turtle.select(1)
  41.     print('Refuel Finished !')
  42. end
  43.  
  44. function getFuelPerc()
  45.     local fuelLimit = turtle.getFuelLimit()
  46.     local fuelLevel = turtle.getFuelLevel()
  47.     local percentage = ((fuelLevel * 100) / fuelLimit)
  48.     print(percentage .. ' % Fuel in the turtle !')
  49.     return percentage
  50. end
  51.  
  52. local i = 0
  53.  
  54. function moveBot(blockAmount, direction)
  55.     if (direction == 'forward') then
  56.         print('Moving ' .. blockAmount .. ' blocks')
  57.         for i = 1, blockAmount, 1 do
  58.             turtle.forward()
  59.         end
  60.     elseif (direction == 'back') then
  61.         print('Moving ' .. blockAmount .. ' block')
  62.         for i = 1, blockAmount, 1 do
  63.             turtle.back()
  64.         end
  65.     elseif (direction == 'up') then
  66.         print('Moving ' .. blockAmount .. ' block')
  67.         for i = 1, blockAmount, 1 do
  68.             turtle.up()
  69.         end
  70.     elseif (direction == 'down') then
  71.         print('Moving ' .. blockAmount .. ' block')
  72.         for i = 1, blockAmount, 1 do
  73.             turtle.down()
  74.         end
  75.     else
  76.         print('Direction error !!')
  77.         return false
  78.     end
  79.     return true
  80. end
  81.  
  82. function turn(side)
  83.     if (side == 'left') then
  84.         turtle.turnLeft()
  85.         return true
  86.     elseif (side == 'right') then
  87.         turtle.turnRight()
  88.         return true
  89.     else
  90.         print('Error arguments side not valid !')
  91.         return false
  92.     end
  93. end
  94.  
  95.  
  96. function inventoryCheck(item)
  97.     local inventoryCap = 16
  98.     turtle.select(1)
  99.     local storageSlot = nil
  100.     local stackItems = false
  101.     for i = 1, inventoryCap, 1 do
  102.         --print(i)
  103.         turtle.select(i)
  104.         local info = turtle.getItemDetail()
  105.         if (info ~= nil) then
  106.             if(info.name == item) then
  107.                 if(stackItems ~= true) then
  108.                     stackItems = true
  109.                     storageSlot = i
  110.                 else
  111.                     if (stackItems == false) then
  112.                         storageSlot = i
  113.                     end
  114.                     turtle.transferTo(storageSlot)
  115.  
  116.                 end
  117.             end
  118.             print(info.name .. ' ' .. info.count .. 'X')
  119.         end
  120.     end
  121.     turtle.select(1)
  122.     local infoLast = turtle.getItemDetail(storageSlot)
  123.    
  124.     if (infoLast ~= nil) then
  125.         local final = {name = infoLast.name, count = infoLast.count, slot = storageSlot}
  126.         return final
  127.     else
  128.         return
  129.     end
  130. end
  131.  
  132. function deposit(side, item)
  133.     if (side == "left") then
  134.         turn('left')
  135.         turtle.select(inventoryInfo.slot)
  136.         turtle.drop()
  137.         turn('right')
  138.     elseif (side == 'right') then
  139.         turn('right')
  140.         turtle.select(inventoryCheck(item).slot)
  141.         turtle.drop()
  142.         turn('left')
  143.     elseif (side == 'back') then
  144.         turtle.select(inventoryInfo.slot)
  145.         turtle.dropBack()
  146.     end
  147.  
  148. end
  149.  
  150. function followBlock(blockName, long)
  151.     local side = nil
  152.     for i = 1, long, 1 do
  153.         local s, blockUnder = turtle.inspectDown()
  154.         blockUnder = blockUnder.name
  155.         if (blockUnder == blockName) then
  156.             moveBot(1, 'forward')
  157.         else
  158.             moveBot(1, 'back')
  159.             turn('left')
  160.             moveBot(1, 'forward')
  161.             blockUnder = turtle.inspectDown()
  162.             if (blockUnder ~= blockName) then
  163.                 moveBot(2, 'back')
  164.                 for b = 1, 2, 1 do
  165.                     turn('right')
  166.                 end
  167.             end
  168.         end
  169.     end
  170. end
Add Comment
Please, Sign In to add comment