Advertisement
Guest User

Untitled

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