Advertisement
JoshP95

Platform 1

Jun 13th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. --[[
  2. Platform (1 wide)
  3. Created by Izzobot
  4. ]]--
  5.  
  6. FUEL_SLOT = 1
  7.  
  8. -- Functions
  9.  
  10. function refuel()
  11.     turtle.select(FUEL_SLOT)
  12.     items = turtle.getItemCount(FUEL_SLOT)
  13.     fuel = turtle.getFuelLevel(FUEL_SLOT)
  14.     if fuel == 0 then   -- When no fuel
  15.         if items ~= 0 then
  16.             print("Refuelling...")
  17.             turtle.refuel(FUEL_SLOT)
  18.             print("Refueled!")
  19.         else    -- If no fuel present
  20.             print("Add more fuel to slot " .. FUEL_SLOT)
  21.          error()
  22.         end
  23.     else
  24.         print("Fuel level sufficient")
  25.     end
  26. end
  27.  
  28. function digForward()
  29.     while turtle.detect() do
  30.         turtle.dig()
  31.     end
  32. end
  33.  
  34. function moveForward()
  35.     if turtle.getFuelLevel() == 0 then
  36.         refuel()
  37.     end
  38.  
  39.     while (not turtle.forward()) do
  40.         if (turtle.detect()) then
  41.             turtle.dig()
  42.         else
  43.             turtle.attack()
  44.         end
  45.     end  
  46. end
  47.  
  48. function placeDown()
  49.     changeSlot()
  50.     turtle.placeDown()
  51. end
  52.  
  53. function placeUp()
  54.     changeSlot()
  55.     turtle.placeUp()
  56. end
  57.  
  58. function placeForward()
  59.     changeSlot()
  60.     turtle.place()
  61. end
  62.  
  63. function moveUp()
  64.     if turtle.getFuelLevel() == 0 then
  65.         refuel()
  66.     end
  67.  
  68.     while turtle.up() == false do
  69.         turtle.digUp()
  70.     end  
  71. end
  72.  
  73. function moveDown()
  74.     if turtle.getFuelLevel() == 0 then
  75.         refuel()
  76.     end
  77.  
  78.     while turtle.down() == false do
  79.         turtle.digDown()
  80.     end
  81. end
  82.  
  83. function enoughItems()
  84.     t = 0
  85.     for slot=2,16 do -- Count the number of blocks
  86.         t = t + turtle.getItemCount(slot)
  87.     end
  88.     if t < l then
  89.         print("More blocks required.")
  90.         error()
  91.     end
  92. end
  93.  
  94. function changeSlot()
  95.     if turtle.getItemCount() == 0 then
  96.         for i=2,16 do
  97.             turtle.select(i)
  98.             if turtle.getItemCount(i) ~= 0 then
  99.                 break
  100.             end
  101.         end
  102.     end
  103. end
  104.  
  105. -- Start of Code
  106. turtle.select(2)
  107. print(" ")
  108. print("[Platform 1 Wide]\n")
  109. io.write("Length: ")
  110. l = tonumber(read())
  111. print(" ")
  112. enoughItems()
  113. print("Building...")
  114.  
  115. for i=1,l do
  116.     digForward()
  117.     moveForward()
  118.     placeDown()
  119. end
  120.  
  121. print("Platform complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement