Diamond_anvil

Yet another simple ComputerCraft tower builder

Jun 28th, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. --[[ Tower Builder
  2.  
  3. This is a code fragment to a larger future project. The intent is to demonstrate
  4. a problem I am having placing ladders using a ComputerCraft Turtle in FTB Ultimate 1.4.7 v 1.1.2.
  5.  
  6. This code only produces the desired results if the turtle is initially placed facing SOUTH!
  7.  
  8. As it stands this code isn't very useful at the moment. Hopefully some day it will be usable by others.
  9.  
  10.  
  11. blocks go in the first 12 slots
  12. ladders go in 13-15
  13. fuel in 16 - not implemented yet
  14.  
  15. ]]
  16.  
  17. activeslot = 1 -- current slot for pulling building blocks from
  18. ladderslot = 13 -- current slot for pulling ladders from
  19. MaxBlock = 12 -- last slot to look in for building blocks
  20. blockcount = 0 -- running total of successful plocks placed
  21. MinFuelLevel = 10 -- Minimum initial fuel level
  22. TowerHeight = 3 -- How high to make the tower to initial platform
  23.  
  24. startfuel = turtle.getFuelLevel()
  25.  
  26. function fillrup()
  27. turtle.select(16)
  28. if turtle.getFuelLevel() < MinFuelLevel then
  29. print("refueling from slot 16(",turtle.getItemCount(16) , ")")
  30. if turtle.getItemCount(16) < 1 then
  31. print("Place fuel in slot 16 and press Enter")
  32. read()
  33. end -- do we have aningthing in slot 16 to refuel with?
  34. turtle.refuel() -- *****add future checks to see if we have just enough fuel to complete the job
  35. end -- fuel status check
  36. end -- fillerup
  37.  
  38. function placeLadder()
  39. ladderslot = 13
  40. if turtle.getItemCount(ladderslot) > 0 then
  41. turtle.select(ladderslot)
  42. if not turtle.placeDown(ladderslot) then
  43. print("I can't place the ladder \nPlease fix and hit Enter")
  44. read()
  45. end
  46. elseif ladderslot < 16 then -- search inventory for a block in valid slots
  47. while ladderslot < 16 and turtle.getItemCount(ladderslot) < 1 do
  48. ladderslot = ladderslot + 1
  49. turtle.select(ladderslot)
  50. end -- while
  51. while not turtle.placeDown(ladderslot) do
  52. print(" can't place the ladder \nPlease fix, reload and hit Enter")
  53. read()
  54. end
  55. end
  56. if turtle.getItemCount(ladderslot) == 0 and ladderslot >= 15 then
  57. print("I seem to be out of ladders")
  58. print("Please refill slots 13-15 \nand press Enter to continue.")
  59. read()
  60. end
  61. end -- function placeLadder
  62.  
  63. function placeBlock()
  64. activeslot = 1
  65. if turtle.getItemCount(activeslot) > 0 then
  66. turtle.select(activeslot)
  67. if turtle.place(activeslot) then blockcount = blockcount +1 end
  68. elseif activeslot < MaxBlock then -- search inventory for a block in valid slots
  69. while activeslot < MaxBlock and turtle.getItemCount(activeslot) < 1 do
  70. activeslot = activeslot + 1
  71. turtle.select(activeslot)
  72. end -- while
  73. if turtle.getItemCount(activeslot) > 0 and turtle.place(activeslot) then blockcount = blockcount + 1 end
  74. end
  75. if turtle.getItemCount(activeslot) == 0 and activeslot == MaxBlock then
  76. print("I seem to be out of building materials")
  77. print("Please refill slots 1-12 \nand press Enter to continue.")
  78. -- os.pullEvent("key")
  79. read()
  80. end
  81. end -- Function placeBlock
  82.  
  83.  
  84. -- Future fuel check location fuel slot = 16
  85. fillrup()
  86.  
  87. print("Place blocks in top 3 rows of slots 1-12 \nNO sand,gravel, glass and the like\nladders in 13-15 and fuel in 16")
  88.  
  89. while (turtle.getItemCount(activeslot) < 1) and (activeslot < MaxBlock + 1) do -- skip empty slots at the begining of inventory
  90. activeslot = activeslot + 1
  91. end -- while
  92.  
  93. if activeslot > MaxBlock then
  94. print("I can't seem to find any \nbuilding materials in slots 1-", MaxBlock)
  95. print("please reload turtle")
  96. print("press Enter to continue")
  97. read()
  98. end
  99.  
  100. while turtle.getItemCount(ladderslot) < 1 and ladderslot < 16 do -- looking for ladders
  101. ladderslot = ladderslot + 1
  102. end -- while looking for ladders
  103.  
  104. if ladderslot > 15 then -- no ladders found
  105. print("I seem to be out of ladders")
  106. print("Please refill slots 13-15 \nand press Enter to continue.")
  107. read()
  108. end -- no ladders found
  109.  
  110. for j = 1, TowerHeight do -- tower height
  111.  
  112. for i = 1,4 do -- build walls
  113. if i == 3 and j < 3 then turtle.turnLeft() end -- make the door to the tower face the user
  114.  
  115. if j > 1 and i == 1 then
  116. placeLadder()
  117. end
  118.  
  119. placeBlock()
  120.  
  121. if not (i == 3 and j < 3) then turtle.turnLeft() end
  122. end -- build walls
  123. turtle.up() -- next row
  124. end -- tower height
  125.  
  126. placeLadder() -- finish up placing ladder sections
  127.  
  128. print("Fuel used = ", startfuel - turtle.getFuelLevel(), " Block count = ",blockcount)
  129.  
  130. print("I seem to be done. Have a nice day:)")
Advertisement
Add Comment
Please, Sign In to add comment