Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.49 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)")
  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. if dim == 3 and InputEquation == 1 then
  23. 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;")
  24. end
  25. dim = tonumber(Args[3])
  26.  
  27. mirror = tonumber(Args[4])
  28.  
  29. Zmax = tonumber(Args[10])
  30. Zmin = tonumber(Args[9])
  31. Z = {}
  32.  
  33. Xmax = tonumber(Args[6])
  34. Xmin = tonumber(Args[5])
  35. X = Xmin
  36.  
  37.  
  38. if dim > 2 then
  39. Ymax = tonumber(Args[8])
  40. Ymin = tonumber(Args[7])
  41. Y = Zmin
  42. end
  43.  
  44. a = tonumber(Args[11])
  45. b = tonumber(Args[12])
  46. c = tonumber(Args[13])
  47. d = tonumber(Args[14])
  48. e = tonumber(Args[15])
  49. j = tonumber(Args[16])
  50. locX = Xmin
  51. locZ = Zmin
  52. locY = Ymin
  53. Zx = {}
  54. Yx = {}
  55. closetoHomeY = 1
  56. closetoHomeZ = 1
  57. Xpos = 1
  58. Zx[Xpos] = 1
  59.  
  60.  
  61. u = 2 --Basic slot selection
  62. closetoHome = 1 --Close to start
  63.  
  64. --Functions:
  65. function Correspondence()
  66. if Zx[Xpos] ~= nil and Zx[-Xpos]== nil and mirror <= 2 and mirror ~=0 then
  67. print("inside if statement1")
  68. if (round(Zx[Xpos]) == locZ or round(Zx[Xpos]) == -locZ) and placed~=1 then
  69. print("Will place a block")
  70. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  71. placed = 1
  72. end
  73. elseif Zx[-Xpos]~= nil and Zx[Xpos]== nil and mirror >= 2 and mirror ~=0 then
  74. print("inside if statement2")
  75. if (round(Zx[-Xpos]) == locZ or round(Zx[-Xpos]) == -locZ) and placed~=1 then
  76. print("Will place a block")
  77. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  78. placed = 1
  79. end
  80.  
  81. elseif Zx[-Xpos]~= nil and Zx[Xpos]~= nil then
  82. print("inside if statement3")
  83. if (round(Zx[-Xpos]) == locZ or round(Zx[-Xpos]) == -locZ or round(Zx[Xpos]) == locZ or round(Zx[Xpos]) == -locZ ) and placed~=1 then
  84. print("Will place a block")
  85. BlockplaceDown() --Does NOT replace blocks (except water/lava)
  86. placed = 1
  87. end
  88.  
  89. end
  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.  
  198.  
  199. function round(num)
  200. return math.floor(num+0.5)
  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.fmod(Zmax,2) == 0 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. if Zx[Xpos] == Zx[Xpos] then
  282. --print("no nan value in Zx[Xpos]")
  283.  
  284. Correspondence() --Checks whether the value of Zx[Xpos] and locZ correspond
  285. --print("X:",locX," Z:",locZ, " Eq: ", Eq(Xpos), " Zx[Xpos]:",Zx[Xpos])
  286. end
  287. end
  288.  
  289. --else
  290. -- print("nan failure to start strip loop")
  291. -- end
  292. placed = 0 --Reset of the placed variable
  293. dignmove()
  294.  
  295.  
  296. TurtleRefuel()
  297. if closetoHomeZ == 1 then
  298. locX = locX + 1 --This is X coordinate for strip away
  299. else
  300. locX = locX - 1 --This is X coordinate for strip back
  301. end
  302. end
  303.  
  304. if closetoHomeZ == 1 and locZ < Zmax and locZ > Zmin then --Turn around at the end of a 'strip'
  305. turtle.turnLeft()
  306. dignmove()
  307. turtle.turnLeft()
  308. locX = Xmax
  309. closetoHomeZ = 0 --Change from far to close
  310. else
  311. turtle.turnRight()
  312. dignmove()
  313. turtle.turnRight()
  314. locX = Xmin
  315. closetoHomeZ = 1 --Change from close to far
  316.  
  317. end
  318.  
  319.  
  320.  
  321. dignmove()
  322.  
  323. if closetoHomeY == 1 then
  324. locZ = locZ + 1 --This is Z coordinate for floor away
  325. else
  326. locZ = locZ - 1 --This is Z coordinate for floor back
  327. end
  328.  
  329. end
  330.  
  331. if closetoHomeZ == 0 and locZ < Zmax and locZ > Zmin then --Turn around at the end of a 'strip'
  332. turtle.turnLeft()
  333. dignmove()
  334. turtle.turnLeft()
  335.  
  336. --Change from far to close
  337. else
  338. turtle.turnRight()
  339. dignmove()
  340. turtle.turnRight()
  341.  
  342. --Change from close to far
  343.  
  344. end
  345. locY = locY + 1 --Keeps track of Y coordinate
  346.  
  347. --3D module
  348. if closetoHomeY == 1 and locY < Ymax and locY >= Ymin then --Turn around at the end of a 'floor'
  349. turtle.turnLeft()
  350. UpdigMoveUp()
  351. turtle.turnLeft()
  352. locZ = Zmax
  353.  
  354. closetoHomeY = 0 --Change from far to close
  355.  
  356.  
  357. else
  358. turtle.turnRight()
  359. UpdigMoveUp()
  360. turtle.turnRight()
  361. locZ = Zmin
  362.  
  363. closetoHomeY = 1 --Change from close to far
  364.  
  365. end
  366.  
  367. end
  368. elseif dim == 2 then
  369. locZ = locZ - 1
  370. while X < Xmax do
  371. print("Table Filling")
  372.  
  373. table.insert(Zx,X/i,Eq(X)) --!!! Perhaps add better Y presicion !!! --Filling in the locations of the blocks in the table
  374.  
  375. X = X + i --Upcounting of the increment
  376. end
  377. X = Xmin
  378. tabZmax = maxtab(Zx)
  379. tabZmin = mintab(Zx)
  380.  
  381. if math.fmod(Zmax,2) == 0 then
  382. Zmax = Zmax + 1
  383. end
  384.  
  385. while locZ <= Zmax do --2D building loop
  386.  
  387. print("Strip building")
  388. while locX <= Xmax and locX >= Xmin do
  389. for Xpos = (locX-0.5)/i, (locX+0.5)/i , 1 do
  390. Correspondence() --Checks whether the value of Zx[Xpos] and locZ correspond
  391. --print("X:",locX," Z:",locZ, " EqZ: ", EqZ(Xpos), " Zx[Xpos]:",Zx[Xpos])
  392.  
  393. end
  394. placed = 0 --Reset of the placed variable
  395. dignmove()
  396.  
  397.  
  398. TurtleRefuel()
  399. locX = locX + 1 --Keeps track of the X coordinate
  400. end
  401.  
  402. if math.fmod(locZ,2) == 0 and locZ < Zmax then --Turn around at the end of a 'strip'
  403. turtle.turnLeft()
  404. dignmove()
  405. turtle.turnLeft()
  406. closetoHome = 0 --Far away from start
  407. else
  408. turtle.turnRight()
  409. dignmove()
  410. turtle.turnRight()
  411. closetoHome = 1 --Close to start
  412.  
  413. end
  414. dignmove()
  415. locX = Xmin
  416. locZ = locZ + 1 --Keeps track of the Z coordinate change in the math.mod block
  417.  
  418.  
  419. end
  420.  
  421.  
  422.  
  423.  
  424. end --2D-3D if loop closer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement