ladyDia

gps builder

Aug 19th, 2021 (edited)
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.62 KB | None | 0 0
  1. local a = {}
  2. local args = {...}
  3.  
  4. local counter = 4
  5. local numbering = 5
  6.  
  7. local posX = 0
  8. local posY = 0
  9. local posZ = 0
  10.  
  11. local centerX = 0
  12. local centerY = 0
  13. local centerZ = 0
  14.  
  15. local buildHeight = 0
  16.  
  17. posX, posY, posZ = gps.locate(5)
  18.  
  19. local startX = posX
  20. local startY = posY
  21. local startZ = posZ
  22.  
  23. local direction = 0
  24. local startDirect = 0
  25.  
  26. local inventory = 1
  27.  
  28. function a.orient()
  29.     turtle.forward()
  30.     posX, posY, posZ = gps.locate(5)
  31.  
  32.     if posX>startX then
  33.         direction = 0
  34.     end
  35.     if posZ>startZ then
  36.         direction = 1
  37.     end
  38.     if posX<startX then
  39.         direction = 2
  40.     end
  41.     if posZ<startZ then
  42.         direction = 3
  43.     end
  44.     startDirect = direction
  45.     turtle.back()
  46. end
  47.  
  48. function a.moveTo(targetX,targetY,targetZ)
  49.     posX, posY, posZ = gps.locate(5)
  50.     print(gps.locate(5))
  51.     while posY > targetY do
  52.         turtle.down()
  53.         posX, posY, posZ = gps.locate(5)
  54.     end
  55.     while posY < targetY do
  56.         turtle.up()
  57.         posX, posY, posZ = gps.locate(5)
  58.     end
  59.  
  60.     if posX > targetX then
  61.         a.rotateTo(2)
  62.     end
  63.     if posX < targetX then
  64.         a.rotateTo(0)
  65.     end
  66.     while posX ~= targetX do
  67.         turtle.forward()
  68.         posX, posY, posZ = gps.locate(5)
  69.     end
  70.  
  71.     if posZ > targetZ then
  72.         a.rotateTo(3)
  73.     end
  74.     if posZ < targetZ then
  75.         a.rotateTo(1)
  76.     end
  77.     while posZ ~= targetZ do
  78.         turtle.forward()
  79.         posX, posY, posZ = gps.locate(5)
  80.     end
  81. end
  82.  
  83. function a.rotateTo(targetD)
  84.     while direction ~= targetD do
  85.         if direction > 3 then
  86.             direction = 0
  87.         end
  88.         if direction < 0 then
  89.             direction = 3
  90.         end
  91.         if direction < targetD then
  92.             direction = direction + 1
  93.             turtle.turnRight()
  94.         end
  95.         if direction > targetD then
  96.             direction = direction - 1
  97.             turtle.turnLeft()
  98.         end
  99.     end
  100. end
  101.  
  102. function a.buildSquare(targetX, targetY, targetZ, size)
  103.     a.moveTo(targetX, targetY, targetZ)
  104.     for x=0, (size-1) do
  105.         for z=0, (size-1) do
  106.             a.moveTo(targetX+x-(math.floor(size/2+size%2)), targetY, targetZ+z-(math.floor(size/2+size%2)))
  107.             if posX == targetX-(math.floor(size/2+size%2)) or posX == targetX+(math.floor(size/2)-size%2) or posZ == targetZ-(math.floor(size/2+size%2)) or posZ == targetZ+(math.floor(size/2)-size%2) then
  108.                 a.buildDown()
  109.             end
  110.         end
  111.     end
  112. end
  113.  
  114. function a.buildPlatform(targetX, targetY, targetZ, size)
  115.     a.moveTo(targetX, targetY, targetZ)
  116.     for x=0, size-1 do
  117.         for z=0, size-1 do
  118.             a.moveTo(targetX+x-(math.floor(size/2+size%2)), targetY, targetZ+z-(math.floor(size/2+size%2)))
  119.             a.buildDown()
  120.         end
  121.     end
  122. end
  123.  
  124. function a.digHole(targetX, targetY, targetZ, size)
  125.     a.moveTo(targetX, targetY, targetZ)
  126.     for x=0, size-1 do
  127.         for z=0, size-1 do
  128.             a.moveTo(targetX+x-(math.floor(size/2+size%2)), targetY, targetZ+z-(math.floor(size/2+size%2)))
  129.             turtle.digDown()       
  130.         end
  131.     end
  132. end
  133.  
  134. function a.buildDiamond(targetX, targetY, targetZ, size)
  135.     a.moveTo(targetX, targetY, targetZ)
  136.     size = size+2
  137.     for x=0, size-1 do
  138.         for z=0, size-1 do
  139.             diff = math.abs(x-math.floor(size/2))
  140.             print(diff)
  141.             if z > diff and z < size-diff-1 then
  142.                 a.moveTo(targetX+x-(math.floor(size/2+size%2))+math.floor(size/2-size%2), targetY, targetZ+z-(math.floor(size/2+size%2))+math.floor(size/2-size%2))
  143.                 a.buildDown()
  144.             end    
  145.         end
  146.     end
  147. end
  148.  
  149. function a.buildAntiDiamond(targetX, targetY, targetZ, size)
  150.     a.moveTo(targetX, targetY, targetZ)
  151.     size = size+2
  152.     for x=0, size-1 do
  153.         for z=0, size-1 do
  154.             diff = math.abs(x-math.floor(size/2))
  155.             print(diff)
  156.             if z < diff and z > size-diff-1 then
  157.                 a.moveTo(targetX+x-(math.floor(size/2+size%2)), targetY, targetZ+z-(math.floor(size/2+size%2)))
  158.                 a.buildDown()
  159.             end    
  160.         end
  161.     end
  162. end
  163.  
  164. function a.digDiamond(targetX, targetY, targetZ, size)
  165.     a.moveTo(targetX, targetY, targetZ)
  166.     size = size+2
  167.     for x=0, size-1 do
  168.         for z=0, size-1 do
  169.             diff = math.abs(x-math.floor(size/2))
  170.             print(diff)
  171.             if z > diff and z < size-diff-1 then
  172.                 a.moveTo(targetX+x-(math.floor(size/2+size%2)), targetY, targetZ+z-(math.floor(size/2+size%2)))
  173.                 a.buildDown()
  174.             end    
  175.         end
  176.     end
  177. end
  178.  
  179. function a.digAntiDiamond(targetX, targetY, targetZ, size)
  180.     a.moveTo(targetX, targetY, targetZ)
  181.     size = size+2
  182.     for x=0, size-1 do
  183.         for z=0, size-1 do
  184.             diff = math.abs(x-math.floor(size/2))
  185.             print(diff)
  186.             if z < diff and z > size-diff-1 then
  187.                 a.moveTo(targetX+x-(math.floor(size/2+size%2)), targetY, targetZ+z-(math.floor(size/2+size%2)))
  188.                 a.buildDown()
  189.             end    
  190.         end
  191.     end
  192. end
  193.  
  194. function a.buildDiamondTest(targetX, targetY, targetZ, size)
  195.     a.moveTo(targetX, targetY, targetZ)
  196.     size = size+2
  197.     for x=0, size-1 do
  198.         for z=0, size-1 do
  199.             diff = math.abs(x-math.floor(size/2))
  200.             print(diff)
  201.             if z > diff and z < size-diff-1 then
  202.                 a.moveTo(targetX+x-(math.floor(size/2)), targetY, targetZ+z-(math.floor(size/2)))
  203.                 a.buildDown()
  204.             end    
  205.         end
  206.     end
  207. end
  208.  
  209. function a.buildDown()
  210.     if turtle.getItemCount() == 0 then
  211.         inventory = inventory+1
  212.     end
  213.     if inventory > 16 then
  214.         a.checkSupply()
  215.     else
  216.         turtle.select(inventory)
  217.         turtle.placeDown()
  218.     end
  219. end
  220.  
  221. function a.checkComp(name)
  222.     found = false
  223.     for i=1, 16 do
  224.         turtle.select(i)
  225.         block = turtle.getItemDetail(turtle.getSelectedSlot())
  226.         if name == block.name then
  227.             inventory = i
  228.             found = true
  229.         end
  230.     end
  231.     if found == false then
  232.         posX, posY, posZ = gps.locate(5)
  233.         tempDirect = direction
  234.         tempX = posX
  235.         tempY = posY
  236.         tempZ = posZ
  237.         a.moveTo(startX,tempY+1,startZ)
  238.         a.moveTo(startX,startY,startZ)
  239.         a.rotateTo(startDirect)
  240.         turtle.turnLeft()
  241.         print("Give me more")
  242.         print(name)
  243.         while turtle.getItemCount() <10 do
  244.             sleep(1)
  245.         end
  246.         turtle.turnRight()
  247.         a.moveTo(startX,tempY+1,startZ)
  248.         a.moveTo(tempX,tempY+1,tempZ)
  249.         a.moveTo(tempX,tempY,tempZ)
  250.     end
  251. end
  252.  
  253. function a.placeComp(name)
  254.     a.checkComp(name)
  255.     turtle.place()
  256. end
  257.  
  258. function a.checkSupply()
  259.     turtle.select(16)
  260.     if turtle.getItemCount() < 10 then
  261.         posX, posY, posZ = gps.locate(5)
  262.         tempX = posX
  263.         tempY = posY
  264.         tempZ = posZ
  265.         a.moveTo(startX,tempY,startZ)
  266.         a.moveTo(startX,startY,startZ)
  267.         a.rotateTo(startDirect)
  268.         turtle.turnLeft()
  269.         print("Not enough blocks")
  270.         while turtle.getItemCount() <10 do
  271.             turtle.suck()
  272.             sleep(1)
  273.         end
  274.         turtle.turnRight()
  275.         a.moveTo(startX,tempY,startZ)
  276.         a.moveTo(tempX,tempY,tempZ)
  277.         inventory = 1
  278.     end
  279.     turtle.select(inventory)
  280. end
  281.  
  282. function a.checkIfComp(block)
  283.     if block == "minecraft:glass_pane" then
  284.         return true
  285.     end
  286.     if block == "minecraft:dispenser" then
  287.         return true
  288.     end
  289.     if block == "minecraft:observer" then
  290.         return true
  291.     end
  292. end
  293.  
  294. a.orient()
  295.  
  296. for i=0, tonumber(args[1]) do
  297.     turtle.forward()
  298. end
  299. posX, posY, posZ = gps.locate(5)
  300.  
  301. centerX, centerY, centerZ = gps.locate(5)
  302.  
  303. print("Starting building")
  304.  
  305. if tonumber(args[2]) == 1 then
  306.     for y = 0, 20 do
  307.         a.buildSquare(centerX, centerY+y, centerZ, 5)
  308.         buildHeight = y
  309.     end
  310.     a.buildPlatform(centerX, centerY+buildHeight, centerZ, 21)
  311.     a.digHole(centerX, centerY+buildHeight, centerZ, 3)
  312.     buildHeight = buildHeight+1
  313.     a.buildSquare(centerX, centerY+buildHeight, centerZ, 21)
  314.     buildHeight = buildHeight+1
  315.     a.buildSquare(centerX, centerY+buildHeight, centerZ, 21)
  316.     buildHeight = buildHeight+1
  317.     a.buildSquare(centerX, centerY+buildHeight, centerZ, 21)
  318.     buildHeight = buildHeight+1
  319.     a.buildPlatform(centerX, centerY+buildHeight, centerZ, 21)
  320.  
  321.     posX, posY, posZ = gps.locate(5)
  322.     a.moveTo(startX,posY,startZ)
  323.     a.moveTo(startX,startY,startZ)
  324. end
  325. if tonumber(args[2]) == 2 then
  326.     for y=0, 20 do
  327.         a.buildDiamond(centerX, centerY+y, centerZ, 3)
  328.         a.moveTo(centerX, centerY+y, centerZ)
  329.         turtle.digDown()
  330.         buildHeight = y
  331.     end
  332.     for y=0, 6 do
  333.         a.buildDiamond(centerX, posY, centerZ, 21)
  334.         a.moveTo(centerX, posY, centerZ)
  335.         turtle.digDown()
  336.         a.buildDiamond(centerX, posY+1, centerZ, 5)
  337.         a.moveTo(centerX, posY, centerZ)
  338.         turtle.digDown()
  339.         a.buildDiamond(centerX, posY+1, centerZ, 5)
  340.         a.moveTo(centerX, posY, centerZ)
  341.         turtle.digDown()
  342.         buildHeight = y
  343.     end
  344.     a.buildDiamond(centerX, posY+1, centerZ, 42)
  345. end
  346. if tonumber(args[2]) == 3 then
  347.     a.buildDiamondTest(centerX, centerY, centerZ, tonumber(args[3]))
  348.     a.moveTo(centerX, centerY+1, centerZ)
  349.     a.buildDown()
  350. end
  351. if tonumber(args[2]) == 4 then
  352.     for y=0, 20 do
  353.         a.buildDiamondTest(centerX, centerY+y, centerZ, 3)
  354.         a.moveTo(centerX, centerY+y, centerZ)
  355.         turtle.digDown()
  356.         buildHeight = y
  357.     end
  358.     for y=0, 6 do
  359.         a.buildDiamondTest(centerX, posY, centerZ, 21)
  360.         a.moveTo(centerX, posY, centerZ)
  361.         turtle.digDown()
  362.         a.buildDiamondTest(centerX, posY+1, centerZ, 5)
  363.         a.moveTo(centerX, posY, centerZ)
  364.         turtle.digDown()
  365.         a.buildDiamondTest(centerX, posY+1, centerZ, 5)
  366.         a.moveTo(centerX, posY, centerZ)
  367.         turtle.digDown()
  368.         a.moveTo(centerX, posY+1, centerZ)
  369.         buildHeight = y
  370.     end
  371.     a.buildDiamondTest(centerX, posY+1, centerZ, 42)
  372. end
Add Comment
Please, Sign In to add comment