Advertisement
Pranshul

luatest.lua

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