Advertisement
Guest User

Untitled

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