Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.27 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. turtle.forward()
  229. end
  230. --Checks emptyness
  231. function isempty(s)
  232. return s == nil or s == ' '
  233. end
  234. --Rounding numbers
  235. function round(num)
  236. if num ~= nil and num ~= nan then
  237. return math.floor(num+0.5)
  238. else
  239. return
  240. end
  241. end
  242.  
  243.  
  244. --Max value in a table
  245. function maxtab(a)
  246. local values = {}
  247. for k,v in pairs(a) do
  248. values[#values+1] = v
  249. end
  250. table.sort(values)
  251. return values[#values]
  252. end
  253.  
  254. --Min value in a table
  255. function mintab(a)
  256. local values = {}
  257. for k,v in pairs(a) do
  258. values[#values+1] = v
  259. end
  260. table.sort(values)
  261. return values[1]
  262. end
  263.  
  264. --Moves turtle up (it breaks the block above it first (has gavelshield)
  265. function UpdigMoveUp()
  266. if turtle.detectUp() then
  267. turtle.digUp()
  268. end
  269. graveldigUp()
  270. turtle.up()
  271. end
  272.  
  273.  
  274. --Down dig
  275. function Ddig()
  276. if turtle.detectDown() then
  277. turtle.digDown()
  278. end
  279. end
  280.  
  281.  
  282. --Dig N movedown
  283. function dignmovedown()
  284. Ddig()
  285. turtle.down()
  286. end
  287.  
  288. --Code:
  289.  
  290.  
  291.  
  292. if dim == 3 then
  293. while locY <= Ymax do
  294. while locX <= Xmax and locX >= Xmin do
  295. while locZ <= Zmax and locZ >= Zmin do
  296.  
  297. TurtleRefuel()
  298. for Xvar = locX-i,locX+i,i/10 do
  299. for Yvar = locY-i,locY+i,i/10 do
  300. if (((round(Eq(Xvar,Yvar)) <= round(locZ)+i and round(Eq(Xvar,Yvar)) >= round(locZ)-i)
  301. or (round(Eq(Xvar,Yvar)) <= -round(locZ)+i and round(Eq(Xvar,Yvar)) >= -round(locZ)-i)
  302. or (round(Eq(locX,locY)) >= math.abs(round(locZ)) and f == 1)
  303. or (round(Eq(locX,locY)) <= math.abs(round(locZ)) and f == 2)) and placed ~= 1) then
  304. BlockplaceDown()
  305.  
  306. end
  307. if emptyInven == true then
  308. break
  309. end
  310. end
  311. end
  312.  
  313.  
  314.  
  315. if emptyInven == true then --Module for empty inventory and refill
  316. print("inside empty inventory")
  317. if closetoHomeZ == 1 then --Turns around if turtle is facing away from chest
  318. turnaround()
  319. end
  320. for k = 1, locZ-Zmin do --Moves back to starting X axis
  321. dignmove()
  322. end
  323.  
  324. turtle.turnRight()
  325.  
  326. for k = 1 , locX-Xmin do --Moves back to starting Z axis
  327. dignmove()
  328. end
  329.  
  330. turtle.turnLeft()
  331.  
  332. for k = 1 , locY - Ymin do
  333. dignmove()
  334. end
  335.  
  336. ChestSucking()
  337.  
  338. for k = 1 , locY - Ymin do
  339. dignmove()
  340. end
  341.  
  342. turtle.turnLeft()
  343.  
  344. for k = 1 ,locX-Xmin do --Moves back to starting Z axis
  345. dignmove()
  346. end
  347.  
  348. turtle.turnLeft()
  349.  
  350. for k = 1, locZ-Zmin do --Moves back to starting X axis
  351. dignmove()
  352. end
  353. if closetoHomeZ == 0 then
  354. turnaround()
  355. end
  356.  
  357.  
  358.  
  359. BlockplaceDown()
  360.  
  361.  
  362. end
  363. placed = 0
  364. dignmove()
  365. if closetoHomeZ == 1 then --going towards Zmax
  366. locZ = locZ + 1
  367. else --away from Zmax
  368. locZ = locZ - 1
  369. end
  370.  
  371. end
  372.  
  373.  
  374. if closetoHomeZ == 1 and locX < Xmax and locX > Xmin then
  375. turtle.turnRight()
  376. dignmove()
  377. turtle.turnRight()
  378. closetoHomeZ = 0
  379. if closetoHomeX == 1 then
  380. locX = locX + 1
  381. elseif closetoHomeX == 0 then
  382. locX = locX - 1
  383. end --away from Zmax
  384. elseif closetoHomeZ == 0 and locX < Xmax and locX > Xmin then
  385. turtle.turnLeft()
  386. dignmove()
  387. turtle.turnLeft()
  388. closetoHomeZ = 1 --going towards Zmax
  389. if closetoHomeX == 1 then
  390. locX = locX + 1
  391. elseif closetoHomeX == 0 then
  392. locX = locX - 1
  393. end
  394. end
  395.  
  396. dignmove()
  397. if closetoHomeZ == 1 then --going towards Zmax
  398. locZ = locZ + 1
  399. else --away from Zmax
  400. locZ = locZ - 1
  401. end
  402.  
  403. end
  404.  
  405. turnaround()
  406. if closetoHomeX == 1 then --going towards Zmax
  407. closetoHomeX = 0
  408. else --away from Zmax
  409. closetoHomeX = 1
  410. end
  411.  
  412. if closetoHomeZ == 1 then --going towards Zmax
  413. closetoHomeZ = 0
  414. else --away from Zmax
  415. closetoHomeZ = 1
  416. end
  417.  
  418. dignmove()
  419. if closetoHomeZ == 1 then --going towards Zmax
  420. locZ = locZ + 1
  421. else --away from Zmax
  422. locZ = locZ - 1
  423. end
  424.  
  425. UpdigMoveUp()
  426. locY = locY + 1
  427.  
  428.  
  429.  
  430. end
  431.  
  432.  
  433. elseif dim == 2 then
  434.  
  435. while locX <= Xmax and locX >= Xmin do
  436. while locZ <= Zmax and locZ >= Zmin do
  437.  
  438. TurtleRefuel()
  439. for Xvar = locX-i,locX+i,i/10 do
  440. if (((round(Eq(Xvar)) <= round(locZ)+i and round(Eq(Xvar)) >= round(locZ)-i)
  441. or (round(Eq(Xvar)) <= -round(locZ)+i and round(Eq(Xvar)) >= -round(locZ)-i)
  442. or (round(Eq(locX)) >= math.abs(round(locZ)) and f == 1)
  443. or (round(Eq(locX)) <= math.abs(round(locZ)) and f == 2)) and placed ~= 1) then
  444. BlockplaceDown()
  445.  
  446. end
  447. if emptyInven == true then
  448. break
  449. end
  450. end
  451.  
  452.  
  453.  
  454. if emptyInven == true then --Module for empty inventory and refill
  455. print("inside empty inventory")
  456. if closetoHomeZ == 1 then --Turns around if turtle is facing away from chest
  457. turnaround()
  458. end
  459. for k = 1, locZ-Zmin do --Moves back to starting X axis
  460. dignmove()
  461. end
  462.  
  463. turtle.turnRight()
  464.  
  465. for k = 1 , locX-Xmin do --Moves back to starting Z axis
  466. dignmove()
  467. end
  468.  
  469. turtle.turnLeft()
  470.  
  471. ChestSucking()
  472.  
  473.  
  474. turtle.turnLeft()
  475.  
  476. for k = 1 ,locX-Xmin do --Moves back to starting Z axis
  477. dignmove()
  478. end
  479.  
  480. turtle.turnLeft()
  481.  
  482. for k = 1, locZ-Zmin do --Moves back to starting X axis
  483. dignmove()
  484. end
  485. if closetoHomeZ == 0 then
  486. turnaround()
  487. end
  488.  
  489. BlockplaceDown()
  490.  
  491.  
  492. end
  493. placed = 0
  494. dignmove()
  495. if closetoHomeZ == 1 then --going towards Zmax
  496. locZ = locZ + 1
  497. else --away from Zmax
  498. locZ = locZ - 1
  499. end
  500.  
  501. end
  502.  
  503. if closetoHomeZ == 1 and locX < Xmax then
  504. turtle.turnRight()
  505. dignmove()
  506. turtle.turnRight()
  507. closetoHomeZ = 0 --away from Zmax
  508. elseif closetoHomeZ == 0 and locX < Xmax then
  509. turtle.turnLeft()
  510. dignmove()
  511. turtle.turnLeft()
  512. closetoHomeZ = 1 --going towards Zmax
  513. end
  514. locX = locX + 1
  515.  
  516. dignmove()
  517. if closetoHomeZ == 1 then --going towards Zmax
  518. locZ = locZ + 1
  519. else --away from Zmax
  520. locZ = locZ - 1
  521. end
  522.  
  523.  
  524. end
  525.  
  526.  
  527.  
  528. end --2D-3D if loop closer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement