Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.50 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. else
  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.  
  199.  
  200. function round(num)
  201. return math.floor(num+0.5)
  202. end
  203.  
  204.  
  205. --Max value in a table
  206. function maxtab(a)
  207. local values = {}
  208. for k,v in pairs(a) do
  209. values[#values+1] = v
  210. end
  211. table.sort(values)
  212. return values[#values]
  213. end
  214.  
  215. --Min value in a table
  216. function mintab(a)
  217. local values = {}
  218. for k,v in pairs(a) do
  219. values[#values+1] = v
  220. end
  221. table.sort(values)
  222. return values[1]
  223. end
  224.  
  225. --Moves turtle up (it breaks the block above it first (has gavelshield)
  226. function UpdigMoveUp()
  227. if turtle.detectUp() then
  228. turtle.digUp()
  229. end
  230. graveldigUp()
  231. turtle.up()
  232. end
  233.  
  234.  
  235. --Down dig
  236. function Ddig()
  237. if turtle.detectDown() then
  238. turtle.digDown()
  239. end
  240. end
  241.  
  242.  
  243. --Dig N movedown
  244. function dignmovedown()
  245. Ddig()
  246. turtle.down()
  247. end
  248.  
  249. --Code:
  250.  
  251.  
  252.  
  253. if dim == 3 then
  254. while locY < Ymax do --3D Building Loop This while loop build one volume
  255.  
  256.  
  257.  
  258. Zx = {}
  259. while X - 1 < Xmax+1 do
  260. print("Table Filling")
  261. for Ypresicion = -j, j, 1 do
  262. 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
  263. end
  264. X = X + i --Upcounting of the increment
  265. end
  266. X = Xmin
  267. tabZmax = maxtab(Zx)
  268. tabZmin = mintab(Zx)
  269.  
  270. if math.fmod(Zmax,2) == 0 then
  271. Zmax = Zmax + 1
  272. end
  273.  
  274. while locZ <= Zmax and locZ >= Zmin do --This while loop build one floor
  275.  
  276. print("Strip building")
  277. while locX <= Xmax and locX >= Xmin do --This while loop builds one strip
  278.  
  279. --if tabZmax == tabZmax and tabZmin == tabZmin then
  280. print("Starting For loop strip builder")
  281. for Xpos = (locX-0.5)/(i)*(j*2+1), (locX+0.5)/(i)*(2*j+1) , 1 do
  282. if Zx[Xpos] == Zx[Xpos] then
  283. --print("no nan value in Zx[Xpos]")
  284.  
  285. Correspondence() --Checks whether the value of Zx[Xpos] and locZ correspond
  286. --print("X:",locX," Z:",locZ, " Eq: ", Eq(Xpos), " Zx[Xpos]:",Zx[Xpos])
  287. end
  288. end
  289.  
  290. --else
  291. -- print("nan failure to start strip loop")
  292. -- end
  293. placed = 0 --Reset of the placed variable
  294. dignmove()
  295.  
  296.  
  297. TurtleRefuel()
  298. if closetoHomeZ == 1 then
  299. locX = locX + 1 --This is X coordinate for strip away
  300. else
  301. locX = locX - 1 --This is X coordinate for strip back
  302. end
  303. end
  304.  
  305. if closetoHomeZ == 1 and locZ < Zmax and locZ > Zmin then --Turn around at the end of a 'strip'
  306. turtle.turnLeft()
  307. dignmove()
  308. turtle.turnLeft()
  309. locX = Xmax
  310. closetoHomeZ = 0 --Change from far to close
  311. else
  312. turtle.turnRight()
  313. dignmove()
  314. turtle.turnRight()
  315. locX = Xmin
  316. closetoHomeZ = 1 --Change from close to far
  317.  
  318. end
  319.  
  320.  
  321.  
  322. dignmove()
  323.  
  324. if closetoHomeY == 1 then
  325. locZ = locZ + 1 --This is Z coordinate for floor away
  326. else
  327. locZ = locZ - 1 --This is Z coordinate for floor back
  328. end
  329.  
  330. end
  331.  
  332. if closetoHomeZ == 0 and locZ < Zmax and locZ > Zmin then --Turn around at the end of a 'strip'
  333. turtle.turnLeft()
  334. dignmove()
  335. turtle.turnLeft()
  336.  
  337. --Change from far to close
  338. else
  339. turtle.turnRight()
  340. dignmove()
  341. turtle.turnRight()
  342.  
  343. --Change from close to far
  344.  
  345. end
  346. locY = locY + 1 --Keeps track of Y coordinate
  347.  
  348. --3D module
  349. if closetoHomeY == 1 and locY < Ymax and locY >= Ymin then --Turn around at the end of a 'floor'
  350. turtle.turnLeft()
  351. UpdigMoveUp()
  352. turtle.turnLeft()
  353. locZ = Zmax
  354.  
  355. closetoHomeY = 0 --Change from far to close
  356.  
  357.  
  358. else
  359. turtle.turnRight()
  360. UpdigMoveUp()
  361. turtle.turnRight()
  362. locZ = Zmin
  363.  
  364. closetoHomeY = 1 --Change from close to far
  365.  
  366. end
  367.  
  368. end
  369. elseif dim == 2 then
  370. locZ = locZ - 1
  371. while X < Xmax do
  372. print("Table Filling")
  373.  
  374. table.insert(Zx,X/i,Eq(X)) --!!! Perhaps add better Y presicion !!! --Filling in the locations of the blocks in the table
  375.  
  376. X = X + i --Upcounting of the increment
  377. end
  378. X = Xmin
  379. tabZmax = maxtab(Zx)
  380. tabZmin = mintab(Zx)
  381.  
  382. if math.fmod(Zmax,2) == 0 then
  383. Zmax = Zmax + 1
  384. end
  385.  
  386. while locZ <= Zmax do --2D building loop
  387.  
  388. print("Strip building")
  389. while locX <= Xmax and locX >= Xmin do
  390. for Xpos = (locX-0.5)/i, (locX+0.5)/i , 1 do
  391. Correspondence() --Checks whether the value of Zx[Xpos] and locZ correspond
  392. --print("X:",locX," Z:",locZ, " EqZ: ", EqZ(Xpos), " Zx[Xpos]:",Zx[Xpos])
  393.  
  394. end
  395. placed = 0 --Reset of the placed variable
  396. dignmove()
  397.  
  398.  
  399. TurtleRefuel()
  400. locX = locX + 1 --Keeps track of the X coordinate
  401. end
  402.  
  403. if math.fmod(locZ,2) == 0 and locZ < Zmax then --Turn around at the end of a 'strip'
  404. turtle.turnLeft()
  405. dignmove()
  406. turtle.turnLeft()
  407. closetoHome = 0 --Far away from start
  408. else
  409. turtle.turnRight()
  410. dignmove()
  411. turtle.turnRight()
  412. closetoHome = 1 --Close to start
  413.  
  414. end
  415. dignmove()
  416. locX = Xmin
  417. locZ = locZ + 1 --Keeps track of the Z coordinate change in the math.mod block
  418.  
  419.  
  420. end
  421.  
  422.  
  423.  
  424.  
  425. end --2D-3D if loop closer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement