Alterbix

flatten

Aug 30th, 2020
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. local function printheader()
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. print("-----------------------------------")
  5. print("FlatIt             | RXDV Laboratories")
  6. print("-----------------------------------")
  7. end
  8. local function invcheck()
  9. while true do
  10. for n=1,9 do
  11.   if turtle.getItemCount(n) > 0 then
  12.    return n
  13.   end
  14. end
  15. printheader()
  16. print("")
  17. print("")
  18. print("ERROR: No Blocks in Inventory. ")
  19. print("    Please load any block into ")
  20. print("    inventory.")
  21. sleep(1)
  22. end
  23. end
  24. local function eatforward()
  25. -- x,y,z = gps.locate( 2, true )
  26. while not turtle.detectDown() do
  27.   turtle.down()
  28.   dy = dy - 1
  29. end
  30. while dy < 0 do
  31.   turtle.up()
  32.   dy = dy + 1
  33.   turtle.select(invcheck())
  34.   turtle.placeDown()
  35. end
  36. while turtle.detect() do
  37.   turtle.dig()
  38.   turtle.up()
  39.   dy = dy + 1
  40. end
  41. while dy > 0 do
  42.   turtle.down()
  43.   dy = dy - 1
  44. end
  45. turtle.forward()
  46. print("nom")
  47. end
  48. local function checkturn()
  49. if curdir == 0 then
  50. if dir == "left" then
  51.   curdir = 1
  52.   turtle.turnLeft()
  53.   eatforward()
  54.   turtle.turnLeft()
  55.   print("1")
  56.   return true
  57. end
  58. if dir == "right" then
  59.   curdir = 1
  60.   turtle.turnRight()
  61.   eatforward()
  62.   turtle.turnRight()
  63.   print("2")
  64.   return true
  65. end
  66. end
  67. if curdir == 1 then
  68. if dir == "right" then
  69.   curdir = 0
  70.   turtle.turnLeft()
  71.   eatforward()
  72.   turtle.turnLeft()
  73.   print("3")
  74.   return true
  75. end
  76. if dir == "left" then
  77.   curdir = 0
  78.   turtle.turnRight()
  79.   eatforward()
  80.   turtle.turnRight()
  81.   print("4")
  82.   return true
  83. end
  84. end
  85. end
  86. local function eatfar()
  87. while ddist < dist do
  88.   ddist = ddist + 1
  89. --  eaten = eaten + 1
  90.   eatforward()
  91. end
  92. end
  93. local function eatall()
  94. while dside < side do
  95.   eatfar()
  96.   ddist = 0
  97.   checkturn()
  98.   dside = dside + 1
  99. end
  100. eatfar()
  101. end
  102. local tArgs = { ... }
  103. if #tArgs < 3  then
  104. printheader()
  105. print("Land Flatter for Turtles.  by Dalva")
  106. print("")
  107. print("")
  108. print("USAGE : flatit <left/right>  ")
  109. print("         <length> <width>")
  110. print("EX       : flatit 10 right 5")
  111. print("NOTE  : Do not use in areas where ")
  112. print("         trees are present.")
  113. return false
  114. end
  115. if not tArgs[1] == left and tArgs[1] == right then
  116. printheader()
  117. print("")
  118. print("")
  119. print("ERROR: Unknown Direction: " ..tArgs[1])
  120. print("Please input either left/right")
  121. print("")
  122. return false
  123. end
  124. dy = 0
  125. ddist = 0
  126. dside = 0
  127. curdir = 0
  128. dist = tonumber(tArgs[2])
  129. side = tonumber(tArgs[3])
  130. dir = (tArgs[1])
  131. printheader()
  132. print("")
  133. print("")
  134. print("Beginning Flattening Operation...")
  135. print("Length   : " ..dist)
  136. print("Width     : " ..side)
  137. print("Direction : " ..dir)
  138. print("")
  139. eatall()
  140. printheader()
  141. print("")
  142. print("")
  143. print("SUCCESS: Flattening Completed")
Add Comment
Please, Sign In to add comment