Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.05 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, mirrors, 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. --Mirros is for mirroring in either X, Y or Z axis. For mirror over X-axis do mirror <= 2, for Z-axis do mirror >= 2. For neither do mirror = 0
  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. mirror = tonumber(Args[4])
  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 = tonumber(Args[11])
  41. b = tonumber(Args[12])
  42. c = tonumber(Args[13])
  43. d = tonumber(Args[14])
  44. e = tonumber(Args[15])
  45. locX = Xmin
  46. locZ = Zmin
  47. locY = Ymin
  48. Zx = {}
  49. Yx = {}
  50. closetoHomeY = 1
  51. closetoHomeZ = 1
  52.  
  53.  
  54. u = 2 --Basic slot selection
  55. closetoHome = 1 --Close to start
  56.  
  57. --Functions:
  58.  
  59. function Eq(Xc,Yc)
  60. if InputEquation == 1 then
  61. if dim == 2 then
  62. return (b/a)*math.sqrt(a^2-Xc^2) --Rewriten Ellipse of form "x^2/a^2+y^2/b^2==1"
  63. elseif dim == 3 then
  64. return (b/(a*c))*math.sqrt(a^2*c^2-c^2*Xc^2-a^2*Yc^2) --3D Ellipse
  65. end
  66.  
  67. elseif InputEquation == 2 then --Polynomial
  68. if dim == 2 then
  69. return a*X^4+b*X^3+c*X^2+d*X+e
  70. elseif dim == 3 then
  71.  
  72. end
  73. elseif InputEquation == 3 then
  74.  
  75. end
  76. end
  77.  
  78. --Refuels turtle
  79. function TurtleRefuel() --Refuel
  80. if turtle.getFuelLevel() < 320 and turtle.getItemCount(1) > 3 then
  81. turtle.select(1)
  82. turtle.refuel(3)
  83. print("TurtleRefueling")
  84. end
  85. turtle.select(u)
  86. end
  87.  
  88. --Item slot selection , for block selection (ignores first item slot which is usually reserved for fuel)
  89. function SlotSelection()
  90.  
  91. if turtle.getItemCount(u) == 0 then
  92. for k=1,16 do
  93. if turtle.getItemCount(u) == 0 then
  94.  
  95. if u < 16 then
  96. u=u+1
  97. turtle.select(u)
  98. else
  99. turtle.select(2)
  100. u=2
  101. end
  102. end
  103. end
  104. end
  105. end
  106.  
  107. --Place underneath (down) block (even on water and lava)
  108. function BlockplaceDown()
  109. SlotSelection()
  110. if turtle.detectDown() then
  111. bool,data = turtle.inspectDown()
  112. if data.name == "minecraft:lava" and data.name == "minecraft:water" and data.name == "minecraft:flowing_water" and data.name == "minecraft:flowing_lava" then
  113. turtle.placeDown()
  114. end
  115. else
  116. turtle.placeDown()
  117. end
  118. end
  119.  
  120. --graveldigforward
  121. function graveldig() --Gravel Shield for digging and the digging
  122. os.sleep(9/20)
  123. if turtle.detect() then
  124. bool,data=turtle.inspect()
  125. while data.name ~= "minecraft:flowing_water" and data.name ~= "minecraft:flowing_lava" and turtle.inspect()~= false do
  126. turtle.dig()
  127. os.sleep(9/20)
  128. bool,data=turtle.inspect()
  129. end
  130. end
  131. end
  132.  
  133. --Gravel Shield (Ensures that when digging up it will keep digging until all falling blocks are dealt with
  134. function graveldigUp() --Gravel Shield for Up digging and the digging Up
  135. os.sleep(9/20)
  136. if turtle.detectUp() then
  137. bool,data=turtle.inspectUp()
  138. while data.name ~= "minecraft:flowing_water" and data.name ~= "minecraft:flowing_lava" and turtle.inspectUp()~= false do
  139. turtle.digUp()
  140. os.sleep(9/20)
  141. bool,data=turtle.inspect()
  142. end
  143. end
  144. end
  145.  
  146. --Forward (in front) dig if something is detected (NO GRAVEL SHIELD!!!)
  147. function Fdig()
  148. if turtle.detect() then
  149. turtle.dig()
  150. end
  151. end
  152.  
  153. --Dig N move
  154. function dignmove()
  155. Fdig()
  156. graveldig()
  157. turtle.forward()
  158. end
  159.  
  160.  
  161. function round(num)
  162. return math.floor(num+0.5)
  163. end
  164.  
  165.  
  166. --Max value in a table
  167. function maxtab(a)
  168. local values = {}
  169. for k,v in pairs(a) do
  170. values[#values+1] = v
  171. end
  172. table.sort(values)
  173. return values[#values]
  174. end
  175.  
  176. --Min value in a table
  177. function mintab(a)
  178. local values = {}
  179. for k,v in pairs(a) do
  180. values[#values+1] = v
  181. end
  182. table.sort(values)
  183. return values[1]
  184. end
  185.  
  186. --Moves turtle up (it breaks the block above it first (has gavelshield)
  187. function UpdigMoveUp()
  188. if turtle.detectUp() then
  189. turtle.digUp()
  190. end
  191. graveldigUp()
  192. turtle.up()
  193. end
  194.  
  195.  
  196. --Down dig
  197. function Ddig()
  198. if turtle.detectDown() then
  199. turtle.digDown()
  200. end
  201. end
  202.  
  203.  
  204. --Dig N movedown
  205. function dignmovedown()
  206. Ddig()
  207. turtle.down()
  208. end
  209.  
  210. --Code:
  211.  
  212.  
  213.  
  214. if dim == 3 then
  215. while locY < Ymax do --3D Building Loop This while loop build one volume
  216.  
  217.  
  218.  
  219.  
  220. while X < Xmax do
  221. print("Table Filling")
  222.  
  223. table.insert(Zx,X/i,Eq(X,locY)) --Filling in the locations of the blocks in the table
  224.  
  225. X = X + i --Upcounting of the increment
  226. end
  227.  
  228. tabZmax = maxtab(Zx)
  229. tabZmin = mintab(Zx)
  230.  
  231. if math.fmod(tabZmax,2) == 0 then
  232. tabZmax = tabZmax + 1
  233. end
  234.  
  235. while locZ <= Zmax and locZ >= Zmin do --This while loop build one floor
  236.  
  237. print("Strip building")
  238. while locX <= Xmax and locX >= Xmin do --This while loop builds one strip
  239.  
  240. --if tabZmax == tabZmax and tabZmin == tabZmin then
  241. print("Starting For loop strip builder")
  242. for Xpos = (locX-0.5)/i, (locX+0.5)/i , 1 do
  243. if Zx[Xpos] == Zx[Xpos] then
  244. if Zx[Xpos] ~= nil and Zx[-Xpos]== nil and mirror <= 2 and mirror ~=0 then
  245. if (round(Zx[Xpos]) == locZ or round(Zx[Xpos]) == -locZ) and placed~=1 then
  246. print("Will place a block")
  247. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  248. placed = 1
  249. end
  250. elseif Zx[-Xpos]~= nil and Zx[Xpos]== nil and mirror >= 2 and mirror ~=0 then
  251. if (round(Zx[-Xpos]) == locZ or round(Zx[-Xpos]) == -locZ) and placed~=1 then
  252. print("Will place a block")
  253. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  254. placed = 1
  255. end
  256.  
  257. elseif Zx[-Xpos]~= nil and Zx[Xpos]~= nil then
  258. if (round(Zx[-Xpos]) == locZ or round(Zx[-Xpos]) == -locZ or round(Zx[Xpos]) == locZ or round(Zx[Xpos]) == -locZ ) and placed~=1 then
  259. print("Will place a block")
  260. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  261. placed = 1
  262. end
  263.  
  264. end
  265. print("X:",locX," Z:",locZ, " Eq: ", Eq(Xpos), " Zx[Xpos]:",Zx[Xpos])
  266. else
  267. print("nan value in Zx[Xpos]")
  268. end
  269. --print("X:",locX," Z:",locZ, " Eq: ", Eq(Xpos), " Zx[Xpos]:",Zx[Xpos])
  270.  
  271. end
  272.  
  273. --else
  274. -- print("nan failure to start strip loop")
  275. -- end
  276. placed = 0 --Reset of the placed variable
  277. dignmove()
  278.  
  279.  
  280. TurtleRefuel()
  281. if closetoHomeZ == 1 then
  282. locX = locX + 1 --This is X coordinate for strip away
  283. else
  284. locX = locX - 1 --This is X coordinate for strip back
  285. end
  286. end
  287.  
  288. if closetoHomeZ == 1 and locZ < Zmax and locZ > Zmin then --Turn around at the end of a 'strip'
  289. turtle.turnLeft()
  290. dignmove()
  291. turtle.turnLeft()
  292. locX = Xmax
  293. closetoHomeZ = 0 --Change from far to close
  294. else
  295. turtle.turnRight()
  296. dignmove()
  297. turtle.turnRight()
  298. locX = Xmin
  299. closetoHomeZ = 1 --Change from close to far
  300.  
  301. end
  302.  
  303.  
  304.  
  305. dignmove()
  306.  
  307. if closetoHomeY == 1 then
  308. locZ = locZ + 1 --This is Z coordinate for floor away
  309. else
  310. locZ = locZ - 1 --This is Z coordinate for floor back
  311. end
  312.  
  313. end
  314.  
  315. turtle.turnLeft()
  316. dignmove()
  317. turtle.turnLeft()
  318. locY = locY + 1 --Keeps track of Y coordinate
  319.  
  320. --3D module
  321. if closetoHomeY == 1 and locY < Ymax and locY >= Ymin then --Turn around at the end of a 'floor'
  322. turtle.turnLeft()
  323. UpdigMoveUp()
  324. turtle.turnLeft()
  325. locZ = Zmax
  326.  
  327. closetoHomeY = 0 --Change from far to close
  328.  
  329.  
  330. else
  331. turtle.turnRight()
  332. UpdigMoveUp()
  333. turtle.turnRight()
  334. locZ = Zmin
  335.  
  336. closetoHomeY = 1 --Change from close to far
  337.  
  338. end
  339.  
  340. end
  341.  
  342.  
  343.  
  344.  
  345. end --3D if loop closer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement