Advertisement
johnneijzen

John Bridge Making Program

Dec 16th, 2014
1,775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.83 KB | None | 0 0
  1. --[[
  2. Version
  3.   0.05 5/31/2015
  4. Changelog
  5.   0.01 - First Draft
  6.   0.02 - Added 4 wide version
  7.   0.03 - small bug fixing and testing
  8.   0.04 dev - Testing And tweaking and add bleeding stuff
  9.   0.04 dev 2 - add speed code by making building process 2 sided not 1 sided
  10.   0.04 dev 3 - Size editing and Testing more
  11.   0.04 - fully tested and working
  12.   0.05 - small fix was made with distance count
  13. To Do List
  14.   Add more fetures
  15. --]]
  16.  
  17.  
  18. -- Locals Variables
  19. local noFuelNeeded = 0 -- Check if turtle is using no fuel config
  20. local itemFuel = turtle.getItemCount(1) -- Fuel Slot 1
  21. local itemFuel1 = turtle.getItemCount(2) -- Fuel Slot 2
  22. local distance = 0 -- Distance will dig
  23. local distanceCount = 0 -- Count the distance
  24. local missingFuel = 0 -- If there is missing fuel this will be 1
  25. local bridgeSize = 0 -- Brige Wide
  26. local currentSlot = 3 -- For checking on cobble
  27. local way = 0 -- Testing to Speed up the code
  28.  
  29. -- Checking On Items
  30. local function checking()
  31.     if noFuelNeeded == 0 then
  32.         if itemFuel == 0 then
  33.             missingFuel = 1
  34.         else
  35.             missingFuel = 0
  36.         end
  37.     end
  38.     if missingFuel == 1 then
  39.         print("Missing Fuel in Slot 1")
  40.     end
  41. end
  42.  
  43. local function recheck()
  44.     itemFuel = turtle.getItemCount(1)
  45.     itemFuel1 = turtle.getItemCount(2)
  46. end
  47.  
  48. local function reFuel()
  49.     if noFuelNeeded == 0 then
  50.         repeat
  51.             if turtle.getFuelLevel() < 120 then
  52.                 if itemFuel > 1 then
  53.                     turtle.select(1)
  54.                     turtle.refuel(1)
  55.                     itemFuel = itemFuel - 1
  56.                     turtle.select(3)
  57.                 elseif itemFuel1 > 1 then
  58.                     turtle.select(2)
  59.                     turtle.refuel(1)
  60.                     itemFuel1 = itemFuel1 - 1
  61.                     turtle.select(3)
  62.                 else
  63.                     print("out of fuel")
  64.                     os.shutdown()
  65.                 end
  66.             end
  67.         until turtle.getFuelLevel() >= 120
  68.     end
  69. end
  70.  
  71. local function blockPlaceRight()
  72.     turtle.forward()
  73.     turtle.down()
  74.     turtle.placeDown()
  75.     turtle.up()
  76.     turtle.placeDown()
  77.     turtle.turnRight()
  78.     turtle.forward()
  79.     turtle.down()
  80.     turtle.placeDown()
  81.     turtle.forward()
  82.     turtle.placeDown()
  83.     turtle.forward()
  84.     turtle.placeDown()
  85.     turtle.forward()
  86.     turtle.placeDown()
  87.     if bridgeSize == 5 then
  88.         turtle.forward()
  89.         turtle.placeDown()
  90.     end
  91.     if bridgeSize == 5 or bridgeSize == 4 then
  92.         turtle.forward()
  93.         turtle.placeDown()
  94.     end
  95.     turtle.up()
  96.     turtle.placeDown()
  97.     turtle.turnLeft()
  98. end
  99.  
  100. local function blockPlaceLeft()
  101.     turtle.forward()
  102.     turtle.down()
  103.     turtle.placeDown()
  104.     turtle.up()
  105.     turtle.placeDown()
  106.     turtle.turnLeft()
  107.     turtle.forward()
  108.     turtle.down()
  109.     turtle.placeDown()
  110.     turtle.forward()
  111.     turtle.placeDown()
  112.     turtle.forward()
  113.     turtle.placeDown()
  114.     turtle.forward()
  115.     turtle.placeDown()
  116.     if bridgeSize == 5 then
  117.         turtle.forward()
  118.         turtle.placeDown()
  119.     end
  120.     if bridgeSize == 5 or bridgeSize == 4 then
  121.         turtle.forward()
  122.         turtle.placeDown()
  123.     end
  124.     turtle.up()
  125.     turtle.placeDown()
  126.     turtle.turnRight()
  127. end
  128.  
  129. function main()
  130.     reFuel()
  131.     turtle.select(3) -- this be cobble slot select
  132.     repeat
  133.         reFuel()
  134.     repeat
  135.         if turtle.getItemCount(currentSlot) <= 8 then -- this code will switch turtle slot when cobble is less than 7
  136.         currentSlot = currentSlot + 1
  137.         elseif turtle.getItemCount(currentSlot) >= 8 then
  138.             currentSlot = currentSlot
  139.         else
  140.             os.shutdown()
  141.         end
  142.     until turtle.getItemCount(currentSlot) >= 8
  143.         turtle.select(currentSlot)
  144.         if way == 0 then
  145.             blockPlaceRight()
  146.             way = 1
  147.         else
  148.             blockPlaceLeft()
  149.             way = 0
  150.         end
  151.         distanceCount = distanceCount + 1
  152.     until distance == distanceCount
  153. end
  154.  
  155. function start()
  156.     print("Welcome To John Bridge Program")
  157.     print("This Program Make Brige Size From 3 Wide to 5 Wide")
  158.     print("Please Enter Brige Size")
  159.     input = io.read()
  160.     bridgeSize = tonumber(input)
  161.     print("Please Input Your Fuel In Slot 1 and Slot 2(Optional)")
  162.     print("Please Input How Far Brige Will Be")
  163.     input1 = io.read()
  164.     distance = tonumber(input1)
  165.     print("Turtle Will Make " .. distance .. " Long Brige")
  166.     if turtle.getFuelLevel() == "unlimited" then -- just check if config of fuel is to unlimited
  167.     noFuelNeeded = 1
  168.     end
  169.     checking()
  170.     if missingFuel == 1 then
  171.         repeat
  172.             print("Please Put In Items That Are Missing")
  173.             sleep(10)
  174.             recheck()
  175.             checking()
  176.         until missingFuel == 0
  177.     end
  178.     main()
  179. end
  180.  
  181. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement