Advertisement
Pranshul

luatest.lua

Jul 31st, 2021
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.92 KB | None | 0 0
  1. --for i = 1,16 do
  2.   --turtle.select(i)
  3.   --slotItemName = turtle.getItemDetail()
  4.   --if not(slotItemName.name == "minecraft:diamond") then
  5.     --turtle.drop()
  6.   --end
  7. --end
  8. toNotMine = {"turtle","computer","chest","furnace","wool"}
  9. toKeep = {"diamond","coal","iron","lead","redstone","copper","gold","galena"}
  10. function orient()
  11. initX,initY,initZ = gps.locate()
  12. turtle.forward()
  13. newX,newY,newZ = gps.locate()
  14. turtle.back()
  15. xOrient = initX - newX
  16. zOrient = initZ - newZ
  17. if xOrient == 1 then
  18.   turtle.turnRight()
  19.   turtle.turnRight() end
  20. if zOrient == 1 then turtle.turnRight() end
  21. if zOrient == -1 then turtle.turnLeft() end
  22. end
  23.  
  24. function mine()
  25.   dontMineAhead = 0
  26.   success1, blockAhead = turtle.inspect()
  27.   for i = 1,#toNotMine do
  28.     if success1 == true then
  29.       if string.match(tostring(blockAhead.name),toNotMine[i]) ~= nil then dontMineAhead = 1
  30.       end
  31.     end
  32.   end
  33.   if dontMineAhead ~= 1 then turtle.dig() end
  34.   if dontMineAhead == 1 then avoidAhead() end
  35. end
  36. function mineAbove()
  37.   dontMineAbove = 0
  38.   success2, blockAbove = turtle.inspectUp()
  39.   for i = 1,#toNotMine do
  40.     if success2 == true then
  41.       if string.match(tostring(blockAbove.name),toNotMine[i]) ~= nil then dontMineAbove = 1
  42.       end
  43.     end
  44.   end
  45.   if dontMineAbove ~= 1 then turtle.digUp() end
  46.   if dontMineAbove == 1 then avoidAbove() end
  47. end
  48. function mineBelow()
  49.   dontMineBelow = 0
  50.   success3, blockBelow = turtle.inspectDown()
  51.   for i = 1,#toNotMine do
  52.     if success3 == true then
  53.       if string.match(tostring(blockBelow.name),toNotMine[i]) ~= nil then dontMineBelow = 1
  54.       end
  55.     end
  56.   end
  57.   if dontMineBelow ~= 1 then turtle.digDown() end
  58.   if dontMineBelow == 1 then avoidBelow() end
  59. end
  60. function avoidAhead()
  61.  
  62. end
  63. function avoidAbove()
  64.  
  65. end
  66. function avoidBelow()
  67.  
  68. end
  69.  
  70. function mineComplete()
  71.   mine()
  72.   mineAbove()
  73.   mineBelow()
  74. end
  75.  
  76. ----------------------------------
  77.  
  78. turtle.select(1)
  79. turtle.refuel()
  80. xDir = 1
  81. yDir = 1
  82. zDir = 1
  83. x,y,z = gps.locate()
  84. Coords2 = {50,100,50}
  85.  
  86. orient()
  87. if x > Coords2[1] then xDis = x - Coords2[1] xDir = 0 end
  88. if x <= Coords2[1] then xDis = Coords2[1] - x end
  89. if xDir == 0 then turtle.turnRight() turtle.turnRight() end
  90. for i =1,xDis do
  91.   mineComplete() turtle.forward()
  92. end
  93. if z > Coords2[3] then zDis = z - Coords2[3] zDir = 0 end
  94. if z <= Coords2[3] then zDis = Coords2[3] - z end
  95. if ((zDir == 0 and xDir == 0) or (zDir == 1 and xDir == 1)) then turtle.turnLeft() zTurn = 1 end
  96. if ((zDir == 1 and xDir == 0)or(zDir == 0 and zDir == 1)) then turtle.turnRight() zTurn = 0 end
  97. for i =1,zDis do
  98.   mineComplete() turtle.forward()
  99. end
  100. if y > Coords2[2] then yDis = y - Coords2[2] yDir = 0 end
  101. if y <= Coords2[2] then yDis = Coords2[2] - y end
  102. for i = 1,yDis do
  103.   if yDir == 1 then mineAbove() turtle.up() end
  104.   if yDir == 0 then mineBelow() turtle.down() end
  105. end
  106. if zTurn == 1 then turtle.turnRight() end
  107. if zTurn == 0 then turtle.turnLeft() end
  108.  
  109.  
  110.  
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement