Advertisement
Guest User

Untitled

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