Acuena

Platform maker 1.0

Jun 7th, 2013
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. -- * ------------------------------* --
  2. -- * Platform maker 1.0            * --
  3. -- * Made by: Acuena               * --
  4. -- * Usage: platform length width  * --
  5. -- * ----------------------------- * --
  6.  
  7. -- Variables
  8. curslot = 2
  9. fuelused = 0
  10. blocksplaced = -1
  11. totalnrblocks = 0
  12.  
  13. -- Functions
  14.  
  15. function moveforward()
  16.  while not turtle.forward() do
  17.  checkfuel()
  18.  end
  19. end
  20.  
  21. function checkfuel()
  22.  if turtle.getFuelLevel() < 1 then
  23.    turtle.select(1)
  24.    if not turtle.refuel(1) then
  25.     print("No fuel in slot 1, awaiting fuel")
  26.     while not turtle.refuel(1) do
  27.     end
  28.     print("Successfully refueld, continuing")
  29.     end
  30.     fuelused = fuelused + 1
  31.   turtle.select(curslot)
  32.  end
  33. end
  34.  
  35. function turnright()
  36.  turtle.turnRight()
  37.  moveforward()
  38.  turtle.turnRight()
  39. end
  40.  
  41. function turnleft()
  42.  turtle.turnLeft()
  43.  moveforward()
  44.  turtle.turnLeft()
  45. end
  46.  
  47. function checkblockcount()
  48.   if turtle.getItemCount(curslot) == 0 then
  49.    selnextslot()
  50.  end
  51. end
  52.  
  53. function selnextslot()
  54.  curslot = curslot + 1
  55.  if curslot > 16 then
  56.  print("Out of blocks, terminating")
  57.  error()
  58.  end
  59. turtle.select(curslot)
  60. end
  61.  
  62. function place()
  63. checkblockcount()
  64. turtle.placeDown()
  65. blocksplaced = blocksplaced + 1
  66. end
  67.  
  68. function countblocks()
  69. for i = 2,16 do
  70.   turtle.select(i)
  71.   totalnrblocks = totalnrblocks + turtle.getItemCount(i)
  72. end
  73.  
  74.  if not totalnrblocks == 0 then
  75.   totalnrblocks = totalnrblocks + 1
  76.  end
  77.  turtle.select(curslot)
  78. end
  79.  
  80.  
  81. -- Code
  82.  
  83.     local args = {...}
  84.     orient=false
  85. if #args ~= 2 then -- Check so it has both arguments
  86.     print("Usage: platform length width")
  87.     return
  88. end
  89.  
  90. length = tonumber(args[1])
  91. width = tonumber(args[2])
  92.  
  93. countblocks()
  94. need = length * width
  95.  
  96. if need > 960 then
  97. print("Unable to carry more than 960 block's")
  98. print("A platform with the size of:")
  99. print(length.."x"..width.." will need "..need.." blocks")
  100. print("Aborting run")
  101. error()
  102. end
  103.  
  104. if totalnrblocks < need then
  105.  print("Not enughe blocks, aborting")
  106.  print("Need: "..need)
  107.  print("Have: "..totalnrblocks.." block's")
  108.  error()
  109. end
  110.  
  111. moveforward()
  112. place()
  113. for xx = 1,width do
  114.     for x = 1, length-1 do
  115. --  place()
  116.  moveforward()
  117.  place()
  118.     end
  119.  
  120.     if orient == false then -- Should turn right
  121.   turnright()  
  122.   place()  
  123.     else -- Should turn left
  124.          turnleft()
  125.    place()
  126.     end
  127. orient = not orient
  128. end
  129. turtle.digDown()
  130.  
  131. print("Platform done")
  132. print("Block's placed: "..blocksplaced)
  133. print("Fuel used: "..fuelused)
Advertisement
Add Comment
Please, Sign In to add comment