Advertisement
Guest User

Untitled

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