Advertisement
Guest User

Untitled

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