Guest User

Minecraft Turtle Skybridge v1.0

a guest
Jan 1st, 2013
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.18 KB | None | 0 0
  1. -- ---------------------------------
  2. -- Various Variables and Settings --
  3. local currentSlot = 1
  4. local materialReferenceSlot = 14
  5. local anchorSlot = 15
  6. local torchSlot = 16
  7. local supplied = true
  8. local rowCount = 0
  9. local lampFreq = 6
  10.  
  11. -- --------------------
  12. -- Utility Functions --
  13.  
  14. -- checkSupply ensures that there is material to build with on hand
  15. local function checkSupply()
  16.     turtle.select(currentSlot)
  17.     -- If the current slot is empty
  18.     if turtle.getItemCount(currentSlot) == 0 then
  19.         -- bump up a slot
  20.         currentSlot = currentSlot + 1
  21.        
  22.         -- make sure it's not past the reference slot
  23.         if currentSlot == (anchorSlot + 1) then
  24.             supplied = false
  25.             currentSlot = currentSlot - 1
  26.             return
  27.         end
  28.        
  29.         -- still in the supplies section, so that's good
  30.         turtle.select(currentSlot)
  31.        
  32.         -- make sure it's the right material
  33.         if turtle.compareTo(materialReferenceSlot) then
  34.             supplied = true
  35.         else
  36.             supplied = false
  37.         end
  38.     -- if the current slot is NOT empty
  39.     else
  40.         -- make sure that the current slot still has the right material in it
  41.         if turtle.compareTo(materialReferenceSlot) then
  42.             supplied = true
  43.         else
  44.             supplied = false
  45.         end
  46.     end
  47. end
  48.  
  49. --
  50. local function forwardDig(mode)
  51.     if turtle.detect() then
  52.         turtle.dig()
  53.     end
  54.     if mode == "place" then
  55.         checkSupply()
  56.         turtle.place()
  57.     elseif mode == "move" then
  58.         turtle.forward()
  59.     else
  60.         -- do nothing
  61.     end
  62. end
  63.  
  64. local function downDig(mode)
  65.     if turtle.detectDown() then
  66.         turtle.digDown()
  67.     end
  68.     if mode == "place" then
  69.         checkSupply()
  70.         turtle.placeDown()
  71.     elseif mode == "move" then
  72.         turtle.down()
  73.     else
  74.         -- do nothing
  75.     end
  76. end
  77.  
  78. local function upDig(mode)
  79.     if turtle.detectUp() then
  80.         turtle.digUp()
  81.     end
  82.     if mode == "place" then
  83.         checkSupply()
  84.         turtle.placeUp()
  85.     elseif mode == "move" then
  86.         turtle.up()
  87.     else
  88.         -- do nothing
  89.     end
  90. end
  91.  
  92. local function turnAround()
  93.     -- It's not an ambiturn.
  94.     turtle.turnRight()
  95.     turtle.turnRight()
  96. end
  97.  
  98. local function placeTorch(whichWay)
  99.     turtle.select(torchSlot)
  100.     if whichWay == "forward" then
  101.         turtle.place()
  102.     elseif whichWay == "up" then
  103.         turtle.placeUp()
  104.     end
  105.     turtle.select(currentSlot)
  106. end
  107.  
  108. local function placeAnchor()
  109.     turtle.select(anchorSlot)
  110.     turtle.place()
  111.     turtle.select(currentSlot)
  112. end
  113.  
  114. -- -----------------
  115. -- Main Functions --
  116.  
  117. -- ensures the things needed (fuel, material, torches, world anchors) are on hand
  118. local function checkStarting()
  119.     local ReadyToGo = true
  120.     local ErrorList = {}
  121.    
  122.     -- Check that the 14th slot has a material for reference
  123.     if turtle.getItemCount(materialReferenceSlot) == 0 then
  124.         ReadyToGo = false
  125.         table.insert(ErrorList,"Reference Material missing in slot 14.")
  126.     end
  127.    
  128.     -- Slots 1 throuth 13 need to be at least 64 of the material in slot 14
  129.     for i = 1, 13 do
  130.         turtle.select(i)
  131.         if turtle.getItemCount(i) == 0 then
  132.             ReadyToGo = false
  133.             table.insert(ErrorList,"Missing material in slot "..tostring(i))
  134.         else
  135.             if not turtle.compareTo(14) then
  136.                 ReadyToGo = false
  137.                 table.insert(ErrorList,"Wrong material in slot "..tostring(i))
  138.             end
  139.         end
  140.     end
  141.    
  142.     -- Slot 15 needs to be at least 12 world anchor type objects
  143.     if turtle.getItemCount(anchorSlot) == 0 then
  144.         ReadyToGo = false
  145.         table.insert(ErrorList,"Anchor type object missing in slot 15.")
  146.     end
  147.    
  148.     -- Slot 16 needs to be at least 60 torch type objects
  149.     if turtle.getItemCount(torchSlot) <= 59 then
  150.         ReadyToGo = false
  151.         table.insert(ErrorList,"Insufficient torch objects missing in slot 16, should be 60-64.")
  152.     end
  153.    
  154.     -- Based on my calculations, with the above payload, we'll go about 180 meters/blocks.
  155.     -- That will take about 1,290 fuel with the movements planned
  156.     if turtle.getFuelLevel() < 1290 then
  157.         ReadyToGo = false
  158.         table.insert(ErrorList,"Turtle should have at least 1,290 fuel (17 coal/charcoal).  Please refuel.")
  159.     end
  160.    
  161.     if not ReadyToGo then
  162.         print("Cannot start building.  Issues:")
  163.         for i=1,#ErrorList do
  164.             print("  -"..tostring(ErrorList[i]))
  165.         end
  166.     else
  167.         print("Supplies/fuel appear to be ready.")
  168.         print("Starting...")
  169.     end
  170.     supplied = ReadyToGo
  171.     return ReadyToGo
  172. end
  173.  
  174. -- Create normal segment pair
  175. local function createNormal()
  176.     -- First section
  177.     forwardDig("move")
  178.     turtle.turnRight()
  179.     downDig("place")
  180.     forwardDig("place")
  181.     upDig("move")
  182.     upDig("")
  183.     turnAround()
  184.     forwardDig("move")
  185.     downDig("move")
  186.     downDig("place")
  187.     forwardDig("place")
  188.     turtle.turnRight()
  189.     forwardDig("move")
  190.     -- Second section
  191.     turtle.turnLeft()
  192.     downDig("place")
  193.     forwardDig("place")
  194.     upDig("move")
  195.     upDig("")
  196.     turnAround()
  197.     forwardDig("move")
  198.     downDig("move")
  199.     downDig("place")
  200.     forwardDig("place")
  201.     turtle.turnLeft()
  202. end
  203.  
  204. -- Create arch/light pair
  205. local function createArch()
  206.     -- First section, same as normal
  207.     forwardDig("move")
  208.     turtle.turnRight()
  209.     downDig("place")
  210.     forwardDig("place")
  211.     upDig("move")
  212.     upDig("")
  213.     turnAround()
  214.     forwardDig("move")
  215.     downDig("move")
  216.     downDig("place")
  217.     forwardDig("place")
  218.     turtle.turnRight()
  219.     forwardDig("move")
  220.     -- Second section, quite different, is an arch with torches
  221.     turtle.turnLeft()
  222.     downDig("place")
  223.     forwardDig("place")
  224.     upDig("move")
  225.     forwardDig("place")
  226.     upDig("move")
  227.     forwardDig("place")
  228.     upDig("place")
  229.     turnAround()
  230.     forwardDig("move")
  231.     turnAround()
  232.     placeTorch("forward")
  233.     turnAround()
  234.     upDig("place")
  235.     forwardDig("place")
  236.     downDig("move")
  237.     placeTorch("up")
  238.     forwardDig("place")
  239.     downDig("move")
  240.     forwardDig("place")
  241.     downDig("place")
  242.     turtle.turnLeft()
  243. end
  244.  
  245. -- Place/collect World Anchors to not overload system, but keep going sans player
  246. local function rollingAnchor()
  247.     turtle.back()
  248.     turtle.back()
  249.     placeAnchor()
  250.     turnAround()
  251.     for i = 1,16 do
  252.         turtle.forward()
  253.     end
  254.     turtle.dig()  -- nix the old world anchor
  255.     turtle.suck() -- try to pick it back up
  256.     turnAround()
  257.     for i = 1,16 do
  258.         turtle.forward()
  259.     end
  260.     -- Move over the new WA back to 'current position'
  261.     turtle.up()
  262.     turtle.forward()
  263.     turtle.forward()
  264.     turtle.down()
  265. end
  266.  
  267. -- --------
  268. -- Main --
  269.  
  270. if checkStarting() then
  271.     -- setup a first anchor
  272.     turnAround()
  273.     placeAnchor()
  274.     turnAround()
  275.    
  276.     while supplied do
  277.         for i = 1,3 do
  278.             createNormal()
  279.             createNormal()
  280.             createArch()
  281.         end
  282.         rollingAnchor()
  283.     end
  284. end
Advertisement
Add Comment
Please, Sign In to add comment