Advertisement
Maxwelljonez

MJZ Flattener

Aug 14th, 2023 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | Gaming | 0 0
  1. --{program="MJZ Flattener",version="1.0"}
  2. -- WIP !
  3. ---------------------------------------
  4. -- 14.8.23 v1.0 initial
  5. ---------------------------------------
  6. -- ToDo:
  7. -- Make it work with defined height
  8.  
  9. ---------------------------------------
  10. ---- DESCRIPTION ----------------------
  11. ---------------------------------------
  12. --[[
  13.  
  14. A simple but yet expandable ground flattener
  15.  
  16. --]]
  17.  
  18. ---------------------------------------
  19. ---- PARAMETERS -----------------------
  20. ---------------------------------------
  21.  
  22. local cVersion ="1.0"
  23. local cPrgName ="MJZ Flatty"
  24. local debugging=false
  25.  
  26. --[[
  27. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  28. Do not change anything below if you
  29. don't want the code to break!
  30. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  31. ]]--
  32.  
  33. ---------------------------------------
  34. ---- VARIABLES ------------------------
  35. ---------------------------------------
  36. local time = os.time()
  37. local formattedTime = textutils.formatTime(time, true)
  38. local width
  39. local length
  40. local height
  41.  
  42. ---------------------------------------
  43. ---- tArgs ----------------------------
  44. ---------------------------------------
  45. local tArgs = {...}
  46. if #tArgs >= 1 then -- no error check
  47. blnAskForParameters=false
  48. if tArgs[1]=="help" then blnShowUsage=true end
  49. if tArgs[1]=="setup" then blnAutoSetup=true end
  50. if tArgs[1]=="set-up" then blnAutoSetup=true end
  51. if tonumber(tArgs[1])~=nil then
  52. maxCounter=tonumber(tArgs[1])
  53. end
  54. end
  55.  
  56. -- Function to print debug information
  57. local function debug_print(txt, ...)
  58. if debugging then
  59. io.write(string.format(txt .. "\n", ...))
  60. end
  61. end
  62.  
  63. ---------------------------------------
  64. -- BASIC FUNCTIONS FOR TURTLE CONTROL -
  65. ---------------------------------------
  66. local function ss(s) turtle.select(s) debug_print("Selecting Slot") end
  67. local function ff() turtle.forward() debug_print("Moving Forward") end
  68. local function bb() turtle.back() debug_print("moving backward") end
  69. local function up() turtle.up() debug_print("moving up") end
  70. local function dn() turtle.down() debug_print("moving down") end
  71. local function tl() turtle.turnLeft() debug_print("turning left") end
  72. local function tr() turtle.turnRight() debug_print("turning right") end
  73. local function df() turtle.dig() debug_print("digging forward") end
  74. local function def() turtle.detect() debug_print("detecting forward") end
  75. local function dd() turtle.digDown() debug_print("digging down") end
  76. local function ded() turtle.detectDown() debug_print("detecting down") end
  77. local function du() turtle.digUp() debug_print("digging up") end
  78. local function deu() turtle.detectUp() debug_print("detecting up") end
  79.  
  80. local function digfu()
  81. if turtle.detect() then df() end
  82. if turtle.detectUp() then du() end
  83. end
  84.  
  85. local function digSides()
  86. tl()
  87. if turtle.detect() then df() end
  88. up()
  89. if turtle.detect() then df() end
  90. tr() tr()
  91. if turtle.detect() then df() end
  92. dn()
  93. if turtle.detect() then df() end
  94. tl()
  95. end
  96.  
  97. local function goRow()
  98. for l = 1, length-1 do
  99. digfu()
  100. digSides()
  101. ff()
  102. sleep(1)
  103. l = l + 1
  104. end
  105. end
  106.  
  107. local function goBack()
  108. for b = 1, length-1 do
  109. bb()
  110. b = b + 1
  111. end
  112. end
  113.  
  114. ---------------------------------------
  115. ---- run -----------------------------
  116. ---------------------------------------
  117. -- Asking for the size
  118. term.clear()
  119. term.setCursorPos(1,1)
  120. print("Started .. ")
  121. print("-------------------")
  122. print("Let's flatten dat surface.")
  123. print("What's the length?")
  124. length = read()
  125. -- print("-------------------")
  126. -- print("What's the width? (going to the right side)")
  127. -- width = read()
  128. print("-------------------")
  129. print("What's the height?")
  130. height = read()
  131. term.clear()
  132. term.setCursorPos(1,1)
  133. write("Flattening at height ") print(height)
  134. write("and length ") print(length)
  135. -- write("x")
  136. -- write (width)
  137. print(".")
  138. textutils.slowWrite("Turtle started at " .. formattedTime, 100)
  139. print("")
  140.  
  141. for h= 1, height/2+1 do
  142. goRow()
  143. digSides()
  144. goBack()
  145. du() up() du() up()
  146. h = h + 1
  147. end
  148. for hh= 1, height/2+1 do
  149. dn() dn()
  150. end
  151.  
  152.  
  153.  
  154. print("Done " .. length .. " blocks")
  155. print("and " .. height .. " high")
  156. textutils.slowWrite("Job finished at " .. formattedTime .. "\n", 50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement