Advertisement
Guest User

Untitled

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