Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.13 KB | None | 0 0
  1. --Equation Builder:
  2.  
  3. --Initialize:
  4. print("hi")
  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); then a,b,c,d,e parameters of eq; fill in: f = 1")
  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. j = 1/i --Opposite incrementer
  23. f = tonumber(Args[16]) --Fill in : f = 1
  24. if dim == 3 and InputEquation == 1 then
  25. 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;")
  26. end
  27. dim = tonumber(Args[3])
  28.  
  29. mirror = tonumber(Args[4])
  30.  
  31. Zmax = tonumber(Args[10])
  32. Zmin = tonumber(Args[9])
  33. Z = {}
  34.  
  35. Xmax = tonumber(Args[6])
  36. Xmin = tonumber(Args[5])
  37. X = Xmin
  38.  
  39.  
  40. if dim > 2 then
  41. Ymax = tonumber(Args[8])
  42. Ymin = tonumber(Args[7])
  43. Y = Zmin
  44. end
  45.  
  46. a = tonumber(Args[11])
  47. b = tonumber(Args[12])
  48. c = tonumber(Args[13])
  49. d = tonumber(Args[14])
  50. e = tonumber(Args[15])
  51.  
  52. locX = Xmin
  53. locZ = Zmin
  54. locY = Ymin
  55. Zx = {}
  56. Yx = {}
  57. closetoHomeY = 1
  58. closetoHomeZ = 1
  59. closetoHomeX = 1
  60. Xpos = 1
  61. Zx[Xpos] = 1
  62.  
  63.  
  64. u = 2 --Basic slot selection
  65.  
  66. --Functions:
  67. function Correspondence(a)
  68. --print("no nan value in Zx[Xpos]")
  69.  
  70. --(round(Zx[a]) <= locZ and round(Zx[a]) >= -locZ and f == 1)
  71. if (round(Zx[a]) == locZ or (round(Zx[a]) == -locZ and mirror <= 2 and mirror ~= 0)) and placed~=1 then
  72. --print("Will place a block")
  73. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  74. placed = 1
  75. elseif isempty(round(Zx[a])) == false then
  76. --print("not nil blockplacing maybe")
  77. if (round(Zx[a]) >= math.abs(locZ) and f == 1) and placed~=1 then
  78. --print("Will place a block")
  79. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  80. placed = 1
  81. elseif (round(Zx[a]) <= math.abs(locZ) and f == 2) and placed~=1 then
  82. --print("Will place a block")
  83. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  84. placed = 1
  85. end
  86. end
  87.  
  88. --if (round(Zx[-a]) == locZ or round(Zx[-a]) == -locZ or round(Zx[a]) == locZ or round(Zx[a]) == -locZ ) and placed~=1 then
  89. -- print("Will place a block")
  90. -- BlockplaceDown() --Does NOT replace blocks (except water/lava)
  91. -- placed = 1
  92. --end
  93.  
  94.  
  95. end
  96.  
  97. function Eq(Xc,Yc)
  98. if InputEquation == 1 then
  99. if dim == 2 then
  100. return (b/a)*math.sqrt(a^2-Xc^2) --Rewriten Ellipse of form "x^2/a^2+y^2/b^2==1"
  101. elseif dim == 3 then
  102. return math.sqrt(a+b*Xc^2+c*Yc^2) --3D Ellipse and hyperbola
  103. end
  104.  
  105. elseif InputEquation == 2 then --Polynomial
  106. if dim == 2 then
  107. return a*X^4+b*X^3+c*X^2+d*X+e
  108. elseif dim == 3 then
  109.  
  110. end
  111. elseif InputEquation == 3 then
  112. if dim == 2 then
  113.  
  114. elseif dim == 3 then
  115.  
  116. end
  117. end
  118. end
  119.  
  120. --Refuels turtle
  121. function TurtleRefuel() --Refuel
  122. if turtle.getFuelLevel() < 320 and turtle.getItemCount(1) > 3 then
  123. turtle.select(1)
  124. turtle.refuel(3)
  125. print("TurtleRefueling")
  126. end
  127. turtle.select(u)
  128. end
  129.  
  130. --Item slot selection , for block selection (ignores first item slot which is usually reserved for fuel)
  131. function SlotSelection()
  132.  
  133. if turtle.getItemCount(u) == 0 then
  134. for k=2,16 do
  135. if turtle.getItemCount(u) == 0 then
  136.  
  137. if u < 16 then
  138. u=u+1
  139. turtle.select(u)
  140. else
  141. turtle.select(2)
  142. u=2
  143. end
  144. end
  145. end
  146. if turtle.getItemCount(u) ==0 then
  147. emptyInven = true
  148. end
  149. else
  150. emptyInven = false
  151. end
  152. end
  153.  
  154. function ChestSucking()
  155. for k=2,16 do
  156. turtle.select(k)
  157. turtle.suck()
  158. end
  159. turtle.select(u)
  160. emptyInven = false
  161. end
  162. --Place underneath (down) block (even on water and lava)
  163. function BlockplaceDown()
  164. SlotSelection()
  165. if emptyInven ~= true then
  166. if turtle.detectDown()then
  167. bool,data = turtle.inspectDown()
  168. if data.name == "minecraft:lava" and data.name == "minecraft:water" and data.name == "minecraft:flowing_water" and data.name == "minecraft:flowing_lava" then
  169. if turtle.placeDown() then
  170. placed = 1
  171. end
  172. end
  173. else
  174. if turtle.placeDown() then
  175. placed = 1
  176. end
  177. end
  178. else
  179. print("Empty inventory!")
  180. end
  181. end
  182.  
  183.  
  184.  
  185. --Turn around
  186. function turnaround()
  187. turtle.turnLeft()
  188. turtle.turnLeft()
  189. end
  190.  
  191. --graveldigforward
  192. function graveldig() --Gravel Shield for digging and the digging
  193. os.sleep(9/20)
  194. if turtle.detect() then
  195. bool,data=turtle.inspect()
  196. while data.name ~= "minecraft:flowing_water" and data.name ~= "minecraft:flowing_lava" and turtle.inspect()~= false do
  197. turtle.dig()
  198. os.sleep(9/20)
  199. bool,data=turtle.inspect()
  200. end
  201. end
  202. end
  203.  
  204. --Gravel Shield (Ensures that when digging up it will keep digging until all falling blocks are dealt with
  205. function graveldigUp() --Gravel Shield for Up digging and the digging Up
  206. os.sleep(9/20)
  207. if turtle.detectUp() then
  208. bool,data=turtle.inspectUp()
  209. while data.name ~= "minecraft:flowing_water" and data.name ~= "minecraft:flowing_lava" and turtle.inspectUp()~= false do
  210. turtle.digUp()
  211. os.sleep(9/20)
  212. bool,data=turtle.inspect()
  213. end
  214. end
  215. end
  216.  
  217. --Forward (in front) dig if something is detected (NO GRAVEL SHIELD!!!)
  218. function Fdig()
  219. if turtle.detect() then
  220. turtle.dig()
  221. end
  222. end
  223.  
  224. --Dig N move
  225. function dignmove()
  226. Fdig()
  227. graveldig()
  228. if turtle.forward()==false then --Mob Shield
  229. while turtle.forward()==false do
  230. turtle.attack()
  231. end
  232. end
  233. end
  234. --Checks emptyness
  235. function isempty(s)
  236. return s == nil or s == ' '
  237. end
  238. --Rounding numbers
  239. function round(num)
  240. if num ~= nil and num ~= nan then
  241. return math.floor(num+0.5)
  242. else
  243. return
  244. end
  245. end
  246.  
  247.  
  248. --Max value in a table
  249. function maxtab(a)
  250. local values = {}
  251. for k,v in pairs(a) do
  252. values[#values+1] = v
  253. end
  254. table.sort(values)
  255. return values[#values]
  256. end
  257.  
  258. --Min value in a table
  259. function mintab(a)
  260. local values = {}
  261. for k,v in pairs(a) do
  262. values[#values+1] = v
  263. end
  264. table.sort(values)
  265. return values[1]
  266. end
  267.  
  268. --Moves turtle up (it breaks the block above it first (has gavelshield)
  269. function UpdigMoveUp()
  270. if turtle.detectUp() then
  271. turtle.digUp()
  272. end
  273. graveldigUp()
  274. if turtle.up()==false then
  275. while turtle.up()==false do
  276. turtle.attackUp()
  277. end
  278. end
  279. end
  280.  
  281.  
  282. --Down dig
  283. function Ddig()
  284. if turtle.detectDown() then
  285. turtle.digDown()
  286. end
  287. end
  288.  
  289.  
  290. --Dig N movedown
  291. function dignmovedown()
  292. Ddig()
  293. if turtle.down()==false then
  294. while turtle.down()==false do
  295. turtle.attackDown()
  296. end
  297. end
  298. end
  299.  
  300. --Code:
  301.  
  302.  
  303.  
  304. if dim == 3 then
  305. while locY <= Ymax do
  306. while locX <= Xmax and locX >= Xmin do
  307. while locZ <= Zmax and locZ >= Zmin do
  308.  
  309. TurtleRefuel()
  310. if Eq(locX-i, locY) == Eq(locX-i,locY) and Eq(locX+i,locY) == Eq(locX+i,locY) then
  311. for Xvar = locX-i,locX+i,i/10 do
  312. for Yvar = locY-i,locY+i,i/10 do
  313. if (((round(Eq(Xvar,Yvar)) <= round(locZ)+i and round(Eq(Xvar,Yvar)) >= round(locZ)-i)
  314. or (round(Eq(Xvar,Yvar)) <= -round(locZ)+i and round(Eq(Xvar,Yvar)) >= -round(locZ)-i)
  315. or (round(Eq(locX,locY)) >= math.abs(round(locZ)) and f == 1)
  316. or (round(Eq(locX,locY)) <= math.abs(round(locZ)) and f == 2)) and placed ~= 1) then
  317. BlockplaceDown()
  318.  
  319. end
  320. if emptyInven == true then
  321. break
  322. end
  323. end
  324. end
  325. end
  326.  
  327.  
  328. if emptyInven == true then --Module for empty inventory and refill
  329. print("inside empty inventory")
  330. if closetoHomeZ == 1 then --Turns around if turtle is facing away from chest
  331. turnaround()
  332. end
  333. for k = 1, locZ-Zmin do --Moves back to starting X axis
  334. dignmove()
  335. end
  336.  
  337. turtle.turnRight()
  338.  
  339. for k = 1 , locX-Xmin do --Moves back to starting Z axis
  340. dignmove()
  341. end
  342.  
  343. turtle.turnLeft()
  344.  
  345. for k = 1 , locY - Ymin do
  346. dignmove()
  347. end
  348.  
  349. ChestSucking()
  350.  
  351. for k = 1 , locY - Ymin do
  352. dignmove()
  353. end
  354.  
  355. turtle.turnLeft()
  356.  
  357. for k = 1 ,locX-Xmin do --Moves back to starting Z axis
  358. dignmove()
  359. end
  360.  
  361. turtle.turnLeft()
  362.  
  363. for k = 1, locZ-Zmin do --Moves back to starting X axis
  364. dignmove()
  365. end
  366. if closetoHomeZ == 0 then
  367. turnaround()
  368. end
  369.  
  370.  
  371.  
  372. BlockplaceDown()
  373.  
  374.  
  375. end
  376. placed = 0
  377. dignmove()
  378. if closetoHomeZ == 1 then --going towards Zmax
  379. locZ = locZ + 1
  380. else --away from Zmax
  381. locZ = locZ - 1
  382. end
  383.  
  384. end
  385.  
  386.  
  387. if closetoHomeZ == 1 and locX <= Xmax and locX >= Xmin then
  388.  
  389. if closetoHomeX == 1 then
  390. turtle.turnRight()
  391. dignmove()
  392. turtle.turnRight()
  393. locX = locX + 1
  394. elseif closetoHomeX == 0 then
  395. turtle.turnLeft()
  396. dignmove()
  397. turtle.turnLeft()
  398.  
  399. locX = locX - 1
  400. end
  401. closetoHomeZ = 0 --away from Zmax
  402. elseif closetoHomeZ == 0 and locX <= Xmax and locX >= Xmin then
  403.  
  404. --going towards Zmax
  405. if closetoHomeX == 1 then
  406. turtle.turnLeft()
  407. dignmove()
  408. turtle.turnLeft()
  409. locX = locX + 1
  410. elseif closetoHomeX == 0 then
  411. turtle.turnRight()
  412. dignmove()
  413. turtle.turnRight()
  414. locX = locX - 1
  415. end
  416. closetoHomeZ = 1
  417. end
  418.  
  419. dignmove()
  420. if closetoHomeZ == 1 then --going towards Zmax
  421. locZ = locZ + 1
  422. else --away from Zmax
  423. locZ = locZ - 1
  424. end
  425.  
  426. end
  427.  
  428.  
  429. UpdigMoveUp()
  430. locY = locY + 1
  431.  
  432. if closetoHomeZ == closetoHomeX then --Turns back into the correct strip
  433. turtle.turnLeft()
  434. dignmove()
  435. turtle.turnRight()
  436.  
  437. else
  438. turtle.turnRight()
  439. dignmove()
  440. turtle.turnLeft()
  441. end
  442.  
  443.  
  444.  
  445. if closetoHomeX == 1 then --X coordinate for the block above, reverse change of variables because block above
  446. closetoHomeX = 0
  447. locX = locX - 1
  448. elseif closetoHomeX == 0 then
  449. closetoHomeX = 1
  450. locX = locX + 1
  451. end
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458. end
  459.  
  460.  
  461. elseif dim == 2 then
  462.  
  463. while locX <= Xmax and locX >= Xmin do
  464. while locZ <= Zmax and locZ >= Zmin do
  465.  
  466. TurtleRefuel()
  467. if Eq(locX-i) == Eq(locX-i) and Eq(locX+i) == Eq(locX+i) then
  468. for Xvar = locX-i,locX+i,i/10 do
  469. if (((round(Eq(Xvar)) <= round(locZ)+i and round(Eq(Xvar)) >= round(locZ)-i)
  470. or (round(Eq(Xvar)) <= -round(locZ)+i and round(Eq(Xvar)) >= -round(locZ)-i)
  471. or (round(Eq(locX)) >= math.abs(round(locZ)) and f == 1)
  472. or (round(Eq(locX)) <= math.abs(round(locZ)) and f == 2)) and placed ~= 1) then
  473. BlockplaceDown()
  474.  
  475. end
  476. if emptyInven == true then
  477. break
  478. end
  479. end
  480. end
  481.  
  482.  
  483. if emptyInven == true then --Module for empty inventory and refill
  484. print("inside empty inventory")
  485. if closetoHomeZ == 1 then --Turns around if turtle is facing away from chest
  486. turnaround()
  487. end
  488. for k = 1, locZ-Zmin do --Moves back to starting X axis
  489. dignmove()
  490. end
  491.  
  492. turtle.turnRight()
  493.  
  494. for k = 1 , locX-Xmin do --Moves back to starting Z axis
  495. dignmove()
  496. end
  497.  
  498. turtle.turnLeft()
  499.  
  500. ChestSucking()
  501.  
  502.  
  503. turtle.turnLeft()
  504.  
  505. for k = 1 ,locX-Xmin do --Moves back to starting Z axis
  506. dignmove()
  507. end
  508.  
  509. turtle.turnLeft()
  510.  
  511. for k = 1, locZ-Zmin do --Moves back to starting X axis
  512. dignmove()
  513. end
  514. if closetoHomeZ == 0 then
  515. turnaround()
  516. end
  517.  
  518. BlockplaceDown()
  519.  
  520.  
  521. end
  522. placed = 0
  523. dignmove()
  524. if closetoHomeZ == 1 then --going towards Zmax
  525. locZ = locZ + 1
  526. else --away from Zmax
  527. locZ = locZ - 1
  528. end
  529.  
  530. end
  531.  
  532. if closetoHomeZ == 1 and locX < Xmax then
  533. turtle.turnRight()
  534. dignmove()
  535. turtle.turnRight()
  536. closetoHomeZ = 0 --away from Zmax
  537. elseif closetoHomeZ == 0 and locX < Xmax then
  538. turtle.turnLeft()
  539. dignmove()
  540. turtle.turnLeft()
  541. closetoHomeZ = 1 --going towards Zmax
  542. end
  543. locX = locX + 1
  544.  
  545. dignmove()
  546. if closetoHomeZ == 1 then --going towards Zmax
  547. locZ = locZ + 1
  548. else --away from Zmax
  549. locZ = locZ - 1
  550. end
  551.  
  552.  
  553. end
  554.  
  555.  
  556.  
  557. end --2D-3D if loop closer
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567. print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement