Advertisement
Guest User

Untitled

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