Scheballs

RailPy_v0.1

Oct 6th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.70 KB | None | 0 0
  1. local tArgs = { ... }
  2. local dis = tonumber(tArgs[1])
  3. local PylonCount = math.floor(dis/28)
  4. local y = 0
  5. local p = 0
  6. --Slots in Turtle Inventory for Items to be placed
  7. local cPath = 1 --cPath = SandStone
  8. local Edge = 5 --Edge = Oak Planks
  9. local uPath = 9 --uPath = Stone Slabs
  10.  
  11. --EnderChest slots containing items for Restocking, one item per chest
  12. local cPathEnChest = 4 --enderchest with SandStone
  13. local EdgeEnChest = 8 --enderchest with Oak Planks
  14. local uPathEnChest = 12 --enderchest with Stone Slabs
  15.  
  16. --Variables used to calculate distance traveled for the little guy
  17. local startmoves = turtle.getFuelLevel()
  18. local endmoves = 0
  19. local moves = 0
  20.  
  21. --====================================================
  22. --Rail Way Building Functions
  23. --====================================================
  24. local  dumpCrap, getItems, CheckslotCount, goingDown, DownPlace, PlaceBlock, placeUnderPath, PlaceSlab, checkHeight, BuildPylon, goingDownSlab, DownPlaceSlab
  25.  
  26. --Clear the Turtle inventory of slots not used from above declarations
  27. --by dumping them into the Enderchest placed in slot 16
  28. --Slot numbers are hard coded so adjust if needed.
  29. dumpCrap = function()
  30.     turtle.digUp()
  31.     turtle.select(16)
  32.     turtle.placeUp()
  33.     turtle.select(2)
  34.     turtle.dropUp()
  35.     turtle.select(3)
  36.     turtle.dropUp()
  37.     turtle.select(6)
  38.     turtle.dropUp()
  39.     turtle.select(7)
  40.     turtle.dropUp()
  41.     turtle.select(10)
  42.     turtle.dropUp()
  43.     turtle.select(11)
  44.     turtle.dropUp()
  45.     turtle.select(13)
  46.     turtle.dropUp()
  47.     turtle.select(14)
  48.     turtle.dropUp()
  49.     turtle.select(15)
  50.     turtle.dropUp()
  51.     turtle.select(16)
  52.     turtle.digUp()
  53. end
  54.  
  55. --Restocking Function
  56. getItems = function(slot,chestslot)
  57.     turtle.select(15)
  58.     turtle.digUp()
  59.     turtle.select(chestslot)
  60.     turtle.placeUp()
  61.     turtle.select(slot)
  62.     turtle.suckUp()
  63.     turtle.select(chestslot)
  64.     turtle.digUp()
  65. end
  66.  
  67. --Check how many items are left and restock if needed
  68. CheckslotCount = function(slot,chestslot)
  69.     if turtle.getItemCount(slot) < 1 then
  70.         getItems(slot,chestslot)
  71.     end
  72. end
  73.  
  74. --Checks to see how high to build the pathway
  75. checkHeight = function()
  76.   if turtle.detectDown() then
  77.     for i = 1, 10 do
  78.       turtle.up()
  79.       sleep(0.2)   
  80.     end
  81.   else
  82.     turtle.down()
  83.     sleep(0.2)
  84.     checkHeight()
  85.   end
  86. end
  87.  
  88. --==========================================================================
  89. --Pylon Building Functions
  90. --==========================================================================
  91.  
  92. --Travels down to see how much room there is to place blocks ( Sets variable y )
  93. goingDown = function(slot,chestslot)
  94.     turtle.down()
  95.     y = y + 1
  96.     DownPlace(slot,chestslot)
  97. end
  98.  
  99. goingDownSlab = function(slot,chestslot)
  100.     turtle.down()
  101.     y = y + 1
  102.     DownPlaceSlab(slot,chestslot)
  103. end
  104.  
  105. --Places blocks in a 1x1 column to a height "y" that was set by the function goingDown()
  106. PlaceBlock = function(slot,chestslot)
  107.     for i = 1, y do
  108.         CheckslotCount(slot,chestslot)
  109.         turtle.select(slot)
  110.         turtle.placeDown()
  111.         turtle.up()
  112.     end
  113. end
  114.  
  115. --Checks wether to run PlaceBlock when it finds a block below itself, or goingDown if it does not detect a block below itself.
  116. DownPlace = function(slot,chestslot)
  117.     if turtle.detectDown() then
  118.         PlaceBlock(slot,chestslot)
  119.     else
  120.         goingDown(slot,chestslot)
  121.     end
  122. end
  123.  
  124. DownPlaceSlab = function(slot,chestslot)
  125.     if turtle.detectDown() then
  126.         PlaceSlab(slot,chestslot)
  127.     else
  128.         goingDownSlab(slot,chestslot)
  129.     end
  130. end
  131.  
  132. --This adds the small double slab supports underneath the path
  133. placeUnderPath = function(slot,chestslot)
  134.     turtle.digDown()
  135.     turtle.down()
  136.     turtle.digDown()
  137.     CheckslotCount(slot,chestslot)
  138.     turtle.select(uPath)
  139.     turtle.placeDown()
  140.     turtle.placeDown()
  141.     turtle.up()
  142. end
  143.  
  144. --Uses the value of y set by the function goingDown to place two slabs in order to fill the whole column.
  145. PlaceSlab = function(slot,chestslot)
  146.     for i = 1, y-1 do
  147.         CheckslotCount(slot,chestslot)
  148.         turtle.select(slot)
  149.         turtle.placeDown()
  150.         turtle.placeDown()
  151.         turtle.up()
  152.     end
  153. end
  154.  
  155. --======================================================================
  156. -- Pylon Building Function
  157. --======================================================================
  158.  
  159. BuildPylon = function()
  160.     p = p + 1
  161.     turtle.digDown()
  162.     turtle.up()
  163.    
  164.     y=0
  165.     DownPlace(Edge,EdgeEnChest)
  166.    
  167.     turtle.up()
  168.     turtle.dig()
  169.     turtle.forward()
  170.     turtle.down()
  171.    
  172.     placeUnderPath(uPath,uPathEnChest)
  173.    
  174.     turtle.select(cPath)
  175.     turtle.placeDown() 
  176.     turtle.turnRight()
  177.     turtle.turnRight()
  178.     turtle.dig()
  179.     turtle.forward()
  180.     turtle.dig()
  181.     turtle.forward()
  182.     turtle.digDown()
  183.  
  184.     placeUnderPath(uPath,uPathEnChest)
  185.    
  186.     turtle.turnRight()
  187.     turtle.dig()
  188.     turtle.forward()
  189.    
  190.     y = 0
  191.     DownPlaceSlab(uPath,uPathEnChest)
  192.    
  193.     turtle.select(Edge)
  194.     turtle.placeDown() 
  195.     turtle.turnRight()
  196.     turtle.dig()
  197.     turtle.forward()
  198.     turtle.select(Edge)
  199.     turtle.placeDown()
  200.     turtle.turnLeft()
  201.     turtle.dig()
  202.     turtle.forward()
  203.     turtle.dig()
  204.     turtle.forward()
  205.     turtle.select(Edge)
  206.     turtle.placeDown()
  207.     turtle.turnRight()
  208.     turtle.turnRight()
  209.     turtle.dig()
  210.     turtle.forward()
  211.     turtle.digDown()
  212.    
  213.     y = 0
  214.     DownPlace(Edge,EdgeEnChest)
  215.    
  216.     turtle.select(Edge)
  217.     turtle.placeDown()
  218.     turtle.dig()
  219.     turtle.forward()
  220.     turtle.digDown()
  221.     turtle.select(Edge)
  222.     turtle.placeDown()
  223.     turtle.turnLeft()
  224.     turtle.dig()
  225.     turtle.forward()
  226.     turtle.digDown()
  227.    
  228.     y = 0
  229.     DownPlaceSlab(uPath,uPathEnChest)
  230.    
  231.     turtle.select(Edge)
  232.     turtle.placeDown()
  233.     turtle.turnRight()
  234.     turtle.dig()
  235.     turtle.forward()
  236.     turtle.dig()
  237.     turtle.forward()
  238.     turtle.digDown()
  239.    
  240.     y = 0
  241.     DownPlaceSlab(uPath,uPathEnChest)
  242.    
  243.     turtle.select(Edge)
  244.     turtle.placeDown()
  245.     turtle.turnRight()
  246.     turtle.dig()
  247.     turtle.forward()
  248.     turtle.turnLeft()
  249.     turtle.dig()
  250.     turtle.forward()
  251.     turtle.dig()
  252.     turtle.forward()
  253.     turtle.select(Edge)
  254.     turtle.placeDown()
  255.     turtle.turnRight()
  256.     turtle.turnRight()
  257.     turtle.dig()
  258.     turtle.forward()
  259.     turtle.digDown()
  260.    
  261.     y = 0
  262.     DownPlace(Edge,EdgeEnChest)
  263.    
  264.     turtle.select(Edge)
  265.     turtle.placeDown()
  266.     turtle.dig()
  267.     turtle.forward()
  268.     turtle.select(Edge)
  269.     turtle.placeDown()
  270.     turtle.turnLeft()
  271.     turtle.dig()
  272.     turtle.forward()
  273.     turtle.digDown()
  274.    
  275.     y=0
  276.     DownPlaceSlab(uPath,uPathEnChest)
  277.    
  278.     turtle.select(Edge)
  279.     turtle.placeDown()
  280.     turtle.turnRight()
  281.     turtle.dig()
  282.     turtle.forward()
  283.     turtle.select(cPath)
  284.     turtle.placeDown() 
  285.     turtle.turnRight()
  286.     turtle.dig()
  287.     turtle.forward()
  288.     turtle.select(cPath)
  289.     turtle.placeDown()
  290.    
  291.     --Clean Up and Restock Inventory
  292.     dumpCrap()
  293.     CheckslotCount(cPath,cPathEnChest)
  294.     CheckslotCount(Edge,EdgeEnChest)
  295.     CheckslotCount(uPath,uPathEnChest)
  296.    
  297. end
  298.  
  299. --==========================================================================
  300. -- Main Railway building Script
  301. --==========================================================================
  302.  
  303. for i = 1, dis do
  304.     if i % 28 == 0 then
  305.         BuildPylon()
  306.         turtle.forward()
  307.         turtle.forward()
  308.         --Print out progress
  309.         endmoves = turtle.getFuelLevel()
  310.         moves = startmoves - endmoves
  311.         print( p .. " of " .. PylonCount .. " Pylons built")
  312.         print( turtle.getFuelLevel() .. " = Current Fuel Level")
  313.         print("I've moved " .. moves .. " meters so far.")
  314.         print("===============================")
  315.     end
  316.        
  317. checkHeight()
  318.  
  319.  turtle.digDown()
  320.  turtle.select(uPath)
  321.  turtle.placeDown()
  322.  turtle.turnLeft()
  323.  turtle.dig()
  324.  turtle.select(Edge)
  325.  turtle.place()
  326.  
  327.  turtle.turnRight()
  328.  turtle.turnRight()
  329.  turtle.dig()
  330.  
  331.  turtle.select(Edge)
  332.  turtle.place()
  333.  
  334.  turtle.turnLeft()
  335.  turtle.dig()
  336.  
  337.  turtle.forward()
  338.  turtle.turnRight()
  339.  turtle.turnRight()
  340.  turtle.select(cPath)
  341.  turtle.place()
  342.  
  343.  turtle.turnRight()
  344.  turtle.turnRight()
  345.  
  346.  if i % 4 == 0 then
  347.     dumpCrap()
  348.  end
  349.  
  350.  CheckslotCount(cPath,cPathEnChest)
  351.  CheckslotCount(Edge,EdgeEnChest)
  352.  CheckslotCount(uPath,uPathEnChest)
  353.  print( i .. " of " .. dis .. " meters of railway built")
  354. end
Advertisement
Add Comment
Please, Sign In to add comment