Advertisement
cul8ter

turtle_utils.lua

Oct 11th, 2023 (edited)
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. local util={}
  2. util.find=function(name)
  3.    for i=1,16 do
  4.        local item=turtle.getItemDetail(i)
  5.        if item and ((type(name)=="table" and name[item.name]) or item.name==name) then
  6.            return i
  7.        end
  8.    end
  9. end
  10. util.dig=function()
  11.     local worked,block=turtle.inspect()
  12.     while worked and block~="mythicmetals:unobtainium_ore" do
  13.         turtle.dig()
  14.         os.sleep(0.2)
  15.         worked,block=turtle.inspect()
  16.     end
  17. end
  18. util.left=function(i)
  19.     for _=1,i do
  20.         turtle.turnLeft()
  21.     end
  22. end
  23. util.right=function(i)
  24.     for _=1,i do
  25.         turtle.turnRight()
  26.     end
  27. end
  28. util.forward=function(i)
  29.     for _=1,i do
  30.         turtle.forward()
  31.     end
  32. end
  33. util.back=function(i)
  34.     for _=1,i do
  35.         turtle.back()
  36.     end
  37. end
  38. util.digup=function()
  39.     local worked,block=turtle.inspectUp()
  40.     while worked and block~="mythicmetals:unobtainium_ore" do
  41.         turtle.digUp()
  42.         os.sleep(0.2)
  43.         worked,block=turtle.inspect()
  44.     end
  45. end
  46. util.up=function(i)
  47.     for _=1,i do
  48.         turtle.up()
  49.     end
  50. end
  51. util.down=function(i)
  52.     for _=1,i do
  53.         turtle.down()
  54.     end
  55. end
  56. function checkFront(blockName,fuzzy)
  57.     worked,block=turtle.inspect()
  58.     if worked and (
  59.             block.name==blockName or (
  60.                 fuzzy and string.find(
  61.                     block.name,blockName
  62.                 )
  63.             )
  64.         ) then
  65.         turtle.dig()
  66.         turtle.forward()
  67.         spin(blockName,fuzzy)
  68.         turtle.back()
  69.     end
  70. end
  71. function checkDown(blockName,fuzzy)
  72.     worked,block=turtle.inspectDown()
  73.     if worked and (
  74.             block.name==blockName or (
  75.                 fuzzy and string.find(
  76.                     block.name,blockName
  77.                 )
  78.             )
  79.         ) then
  80.         turtle.digDown()
  81.         turtle.down()
  82.         spin(blockName,fuzzy)
  83.         turtle.up()
  84.     end
  85. end
  86. function checkUp(blockName,fuzzy)
  87.     worked,block=turtle.inspectUp()
  88.     if worked and (
  89.             block.name==blockName or (
  90.                 fuzzy and string.find(
  91.                     block.name,blockName
  92.                 )
  93.             )
  94.         ) then
  95.         turtle.digUp()
  96.         turtle.up()
  97.         spin(blockName,fuzzy)
  98.         turtle.down()
  99.     end
  100. end
  101. function spin(blockName,fuzzy)
  102.     checkDown(blockName,fuzzy)
  103.     for _=1,4 do
  104.         checkFront(blockName,fuzzy)
  105.         turtle.turnLeft()
  106.     end
  107.     checkUp(blockName,fuzzy)
  108. end
  109. util.veinmine=spin
  110. util.fuel={}
  111. util.fuel["minecraft:coal"]=true
  112. util.fuel["minecraft:charcoal"]=true
  113. util.fuel["minecraft:oak_planks"]=true
  114. util.fuel["modern_industrialization:lignite_coal"]=true
  115. util.fuel["mythicmetals:morkite"]=true
  116. util.trash={}
  117. util.trash["minecraft:cobbled_deepslate"]=true
  118. util.trash["minecraft:cobblestone"]=true
  119. util.trash["minecraft:tuff"]=true
  120. return util
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement