Stravides

Netherturtle

Mar 21st, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.16 KB | None | 0 0
  1. --[[
  2. Author: Stravides
  3. Program: Turtle EnderQuarry Placement
  4. Date: 20th March 2014
  5. Usage: free for non profit or non commercial.
  6.  
  7. Summary of functionality:
  8. Will do different actions depending upon World (Nether or overworld)
  9. Overworld expects to be at a height not to need digging or cutting
  10. Nether expects to have to dig in front and below and to be at a height.
  11.  
  12. Program will place the enderquarry, tesseract wire up the 2, however it is assumed that the
  13. tesseract will have receive power and send items already set and redstone turned off.
  14.  
  15. The turtle will then place the fences needed to make up to a 64x64 quarry - this WILL bypass any towny or other faction setting
  16. it is your responsibility to make sure that when you set the turtle free - there will be no
  17. griefing.
  18.  
  19. The Turtle will place The enderquarry directly where you place the turtle.  This will be the lower leftmost part
  20. of the quarry.  By default, the quarry will then extend right for maxwidth-1 then turn left
  21. --]]
  22.  
  23. --[[
  24. Turtle Slots
  25. Item                        Slots
  26. 4 Full stacks fences        1-4
  27. Enderquarry                 9
  28. Gold Pipe x 2               10
  29. Tesseract Pre configured    11
  30. --]]
  31.  
  32.  
  33.  
  34. -- Variables
  35. local arg = { ... }
  36. xlen = tonumber(arg[1])     -- get x Length
  37. ylen = tonumber(arg[2])     -- get y Length
  38. minQSize=7
  39. if xlen or ylen < minQSize then
  40.     print("Sorry minimum quarry size is "..minQSize.."x"..minQSize)
  41.  
  42. end
  43. clockwise = false
  44. if arg[3] == "-c" then
  45.   clockwise = true
  46. elseif arg[3] == "-cf" then
  47.   cost_only = true
  48. end
  49.  
  50. -- set up Turtle Slots
  51. fslot = 1
  52. maxFenceSlots=4
  53. EQslot=9    -- EnderQuarry
  54. GPSlot=10   -- Gold Pipe
  55. TSlot=11    -- Tesseract
  56. foundSlot = false
  57.  
  58. positionx = radius   --no fking idea <--
  59. positiony = radius   --no fking idea <--
  60. facing = 0
  61.  
  62. -- Constants
  63.  
  64.  
  65. -- Functions
  66.  
  67. function turnRightTrack()
  68.   turtle.turnRight()
  69.   facing = facing + 1
  70.   if facing >= 4 then
  71.     facing = 0
  72.   end
  73. end
  74.  
  75. function turnLeftTrack()
  76.   turtle.turnLeft()
  77.   facing = facing - 1
  78.   if facing < 0 then
  79.     facing = 3
  80.   end
  81. end
  82.  
  83. function safeForward()
  84.   success = false
  85.   while not success do
  86.     success = turtle.forward()
  87.     if not success then
  88.       print("Blocked attempting to move forward.")
  89.       print("Please clear and press enter to continue.")
  90.       io.read()
  91.     end
  92.   end
  93. end
  94.  
  95. function safeBack()
  96.   success = false
  97.   while not success do
  98.     success = turtle.back()
  99.     if not success then
  100.       print("Blocked attempting to move back.")
  101.       print("Please clear and press enter to continue.")
  102.       io.read()
  103.     end
  104.   end
  105. end
  106.  
  107. function safeUp()
  108.   success = false
  109.   while not success do
  110.     success = turtle.up()
  111.     if not success then
  112.       print("Blocked attempting to move up.")
  113.       print("Please clear and press enter to continue.")
  114.       io.read()
  115.     end
  116.   end
  117. end
  118.  
  119. function safeDown()
  120.   success = false
  121.   while not success do
  122.     success = turtle.down()
  123.     if not success then
  124.       print("Blocked attempting to move down.")
  125.       print("Please clear and press enter to continue.")
  126.       io.read()
  127.     end
  128.   end
  129. end
  130.  
  131. function moveY(targety)
  132.   if targety == positiony then
  133.     return
  134.   end
  135.  
  136.   if (facing ~= 0 and facing ~= 2) then -- check axis
  137.     turnRightTrack()
  138.   end
  139.  
  140.   while targety > positiony do
  141.     if facing == 0 then
  142.       safeForward()
  143.     else
  144.       safeBack()
  145.     end
  146.     positiony = positiony + 1
  147.   end
  148.  
  149.   while targety < positiony do
  150.     if facing == 2 then
  151.       safeForward()
  152.     else
  153.       safeBack()
  154.     end
  155.     positiony = positiony - 1
  156.   end
  157. end
  158.  
  159. function moveX(targetx)
  160.   if targetx == positionx then
  161.     return
  162.   end
  163.  
  164.   if (facing ~= 1 and facing ~= 3) then -- check axis
  165.     turnRightTrack()
  166.   end
  167.  
  168.   while targetx > positionx do
  169.     if facing == 1 then
  170.       safeForward()
  171.     else
  172.       safeBack()
  173.     end
  174.     positionx = positionx + 1
  175.   end
  176.  
  177.   while targetx < positionx do
  178.     if facing == 3 then
  179.       safeForward()
  180.     else
  181.       safeBack()
  182.     end
  183.     positionx = positionx - 1
  184.   end
  185. end
  186.  
  187. function navigateTo(targetx, targety)
  188.   -- Cost calculation mode - don't move
  189.   if cost_only then
  190.     return
  191.   end
  192.  
  193.   if facing == 0 or facing == 2 then -- Y axis
  194.     moveY(targety)
  195.     moveX(targetx)
  196.   else
  197.     moveX(targetx)
  198.     moveY(targety)
  199.   end
  200. end
  201.  
  202. function placeBlock()
  203.   -- Cost calculation mode - don't move
  204.   blocks = blocks + 1
  205.   if cost_only then
  206.     return
  207.   end
  208.  
  209.   if turtle.getItemCount(cslot) == 0 then
  210.     foundSlot = false
  211.     while not foundSlot do
  212.       for i = 1,4 do
  213.         if turtle.getItemCount(i) > 0 then
  214.           foundSlot = i
  215.           break
  216.         end
  217.       end
  218.       if not foundSlot then
  219.         -- No resources
  220.         print("Out of building materials. Please refill and press enter to continue.")
  221.         io.read()
  222.       end
  223.     end
  224.     cslot = foundSlot
  225.     turtle.select(foundSlot)
  226.   end
  227.  
  228.   turtle.placeDown()
  229. end
  230.  
  231. function checkFenceStocks()
  232.   if turtle.getItemCount(fslot) == 0 then
  233.     foundSlot = false
  234.     while not foundSlot do
  235.       for i = 1,maxFenceSlots do
  236.         if turtle.getItemCount(i) > 0 then
  237.           foundSlot = i
  238.           break
  239.         end
  240.       end
  241.       if not foundSlot then
  242.         -- No resources
  243.         print("Out of Fences. Please refill slots 1-" ..maxFenceSlots.." and press enter to continue.")
  244.         io.read()
  245.       end
  246.     end
  247.     cslot = foundSlot
  248.     turtle.select(foundSlot)
  249.   end
  250. end
  251.  
  252. function calculateFences(xlen,ylen)
  253.     fence=(2*xlen)+(2*ylen)-5 -- minus 5 for corners and the quarry
  254.     print("You are going to need " ..fence.." fences. Put fences in slots 1-4 and then Press Enter")
  255.     print("Make sure you have set me up correctly")
  256.     io.read()
  257. end
  258.        
  259. function setFences(xlen,ylen)
  260.     checkFenceStocks()
  261.     turtle.digDown()
  262.     turtle.placeDown()
  263.     for i = 1, (xlen-2)/2 do
  264.         turtle.dig()
  265.         safeForward()
  266.         checkFenceStocks()
  267.         turtle.digDown()
  268.         turtle.placeDown()
  269.     end
  270.     turnLeftTrack()
  271.     for i = 1, (ylen-1) do
  272.         turtle.dig()
  273.         safeForward()
  274.         checkFenceStocks()
  275.         turtle.digDown()
  276.         turtle.placeDown()
  277.     end
  278.     turnLeftTrack()
  279.     for i = 1, (xlen-1) do
  280.         turtle.dig()
  281.         safeForward()
  282.         checkFenceStocks()
  283.         turtle.digDown()
  284.         turtle.placeDown()
  285.     end
  286.     turnLeftTrack()
  287.     for i = 1, (ylen-1) do
  288.         turtle.dig()
  289.         safeForward()
  290.         checkFenceStocks()
  291.         turtle.digDown()
  292.         turtle.placeDown()
  293.     end
  294.     turnLeftTrack()
  295.     for i = 1, (xlen-2)/2 do
  296.         turtle.dig()
  297.         safeForward()
  298.         checkFenceStocks()
  299.         turtle.digDown()
  300.         turtle.placeDown()
  301.     end
  302. end
  303.  
  304. function setupQuarry() 
  305.     turtle.safeForward()
  306.     turtle.safeForward()
  307.     turnLeftTrack()
  308.     turtle.digDown()
  309.     turtle.safeDown()
  310.     turtle.safeBack()
  311.     turtle.select(EQslot)
  312.     turtle.place()
  313.     safeUp()
  314.     turtle.select(Tslot)
  315.     turtle.placeDown()
  316.     safeUp()
  317.     turtle.select(GPslot)
  318.     turtle.placeDown()
  319.     safeForward()
  320.     turtle.placeDown()
  321.     turnRightTrack()
  322.     turnRightTrack()
  323.     safeForward()
  324.     safeForward()
  325.     safeDown()
  326. end
  327.  
  328.    
  329. -- Runtime
  330.  
  331. calculateFences(xlen,ylen)
  332. setFences(xlen,ylen)
  333. setupQuarry() -- This sets the quarry etc so make sure that the area is clear
  334. print("Click the EnderQuarry to start")
Advertisement
Add Comment
Please, Sign In to add comment