Advertisement
Guest User

Untitled

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