Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. --Equation Builder:
  2.  
  3. --Initialize:
  4.  
  5. turtle.select(2)
  6.  
  7. --Printables:
  8.  
  9. io.write("Input equation, increment size, number of dimensions, parameters, limits first dimension (lower upper), limits second dimension (lower upper), limits third dimension (lower upper)")
  10. --Input equation: 1 for ellipse, 2 for parabola, 3 for etc
  11. --Parameters is table of form: {a,b,c,d,e}
  12. --Wireless Connection:
  13. --Not yes
  14.  
  15. --Variables:
  16. Args = {...}
  17.  
  18. --Parameters:
  19.  
  20. InputEquation = tonumber(Args[1])
  21. i = tonumber(Args[2]) --Incrementer
  22. dim = tonumber(Args[3])
  23.  
  24.  
  25. Zmax = tonumber(Args[10])
  26. Zmin = tonumber(Args[9])
  27. Z = {}
  28.  
  29. Xmax = tonumber(Args[6])
  30. Xmin = tonumber(Args[5])
  31. X = Xmin
  32.  
  33.  
  34. if dim > 2 then
  35. Ymax = tonumber(Args[8])
  36. Ymin = tonumber(Args[7])
  37. Y = Zmin
  38. end
  39.  
  40. a = Args[11]
  41. b = Args[12]
  42. c = Args[13]
  43. d = Args[14]
  44. e = Args[15]
  45. locX = Xmin
  46. locZ = Zmin
  47. Zx = {}
  48. Yx = {}
  49.  
  50. u = 2 --Basic slot selection
  51. closetoHome = 1 --Close to start
  52.  
  53. --Functions:
  54.  
  55. function EqZ(Xc)
  56. if InputEquation == 1 then
  57. if dim == 2 then
  58. return (b/a)*math.sqrt(a^2-Xc^2) --Rewriten Ellipse of form "x^2/a^2+y^2/b^2==1"
  59. elseif dim == 3 then
  60.  
  61. end
  62.  
  63. elseif InputEquation == 2 then
  64.  
  65. elseif InputEquation == 3 then
  66.  
  67. end
  68. end
  69.  
  70. --Refuels turtle
  71. function TurtleRefuel() --Refuel
  72. if turtle.getFuelLevel() < 320 and turtle.getItemCount(1) > 3 then
  73. turtle.select(1)
  74. turtle.refuel(3)
  75. print("TurtleRefueling")
  76. end
  77. turtle.select(u)
  78. end
  79.  
  80. --Item slot selection , for block selection (ignores first item slot which is usually reserved for fuel)
  81. function SlotSelection()
  82.  
  83. if turtle.getItemCount(u) == 0 then
  84. for k=1,16 do
  85. if turtle.getItemCount(u) == 0 then
  86.  
  87. if u < 16 then
  88. u=u+1
  89. turtle.select(u)
  90. else
  91. turtle.select(2)
  92. u=2
  93. end
  94. end
  95. end
  96. end
  97. end
  98.  
  99. --Place underneath (down) block (even on water and lava)
  100. function BlockplaceDown()
  101. SlotSelection()
  102. if turtle.detectDown() then
  103. bool,data = turtle.inspectDown()
  104. if data.name == "minecraft:lava" and data.name == "minecraft:water" and data.name == "minecraft:flowing_water" and data.name == "minecraft:flowing_lava" then
  105. turtle.placeDown()
  106. end
  107. else
  108. turtle.placeDown()
  109. end
  110. end
  111.  
  112. --graveldigforward
  113. function graveldig() --Gravel Shield for digging and the digging
  114. os.sleep(9/20)
  115. if turtle.detect() then
  116. bool,data=turtle.inspect()
  117. while data.name ~= "minecraft:flowing_water" and data.name ~= "minecraft:flowing_lava" and turtle.inspect()~= false do
  118. turtle.dig()
  119. os.sleep(9/20)
  120. bool,data=turtle.inspect()
  121. end
  122. end
  123. end
  124.  
  125. --Forward (in front) dig if something is detected (NO GRAVEL SHIELD!!!)
  126. function Fdig()
  127. if turtle.detect() then
  128. turtle.dig()
  129. end
  130. end
  131.  
  132. --Dig N move
  133. function dignmove()
  134. Fdig()
  135. graveldig()
  136. turtle.forward()
  137. end
  138.  
  139.  
  140. function round(num)
  141. return math.floor(num+0.5)
  142. end
  143.  
  144. --Max value in a table
  145. function maxtab(a)
  146. local values = {}
  147. for k,v in pairs(a) do
  148. values[#values+1] = v
  149. end
  150. table.sort(values)
  151. return values[#values]
  152. end
  153.  
  154.  
  155.  
  156.  
  157. --Code:
  158.  
  159. while X < Xmax do
  160. print("Table Filling")
  161.  
  162. table.insert(Zx,X/i,EqZ(X)) --Filling in the locations of the blocks in the table
  163.  
  164. X = X + i --Upcounting of the increment
  165.  
  166. if dim == 3 then
  167. while Z < Zmax do
  168. Yz[Eqy] = Z --Filling in the locations of the blocks in the table
  169. Z = Z + i --Upcounting of the increment
  170. end
  171. end
  172. end
  173. tabZmax = maxtab(Zx)
  174. while locZ < tabZmax do
  175.  
  176. print("Strip building")
  177. while locX < Xmax and locX >= Xmin do
  178. for Xpos = (locX-0.5)/i, (locX+0.5)/i , 1 do
  179. if Zx[Xpos] ~= nil then
  180. if round(Zx[Xpos]) == locZ or round(Zx[Xpos]) == -locZ or math.floor(Zx[Xpos]) == locZ or math.ceil(Zx[Xpos]) == locZ or math.floor(Zx[Xpos]) == -locZ or math.ceil(Zx[Xpos]) == -locZ then
  181.  
  182. print("Will place a block")
  183. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  184. placed = 1
  185. end
  186. end
  187.  
  188. print(Zx[Xpos])
  189.  
  190. end
  191. dignmove()
  192.  
  193.  
  194. TurtleRefuel()
  195. print("X:",locX," Z:",locZ, "EqZ: ", EqZ(locX))
  196. locX = locX + 1 --Keeps track of the X coordinate
  197. end
  198.  
  199. if math.fmod(locZ,2) == 0 and locZ < tabZmax then --Turn around at the end of a 'strip'
  200. turtle.turnLeft()
  201. dignmove()
  202. turtle.turnLeft()
  203. closetoHome = 0 --Far away from start
  204. else
  205. turtle.turnRight()
  206. dignmove()
  207. turtle.turnRight()
  208. closetoHome = 1 --Close to start
  209.  
  210. end
  211. locX = Xmin + 1
  212. locZ = locZ + 1 --Keeps track of the Z coordinate change in the math.mod block
  213.  
  214.  
  215. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement