Advertisement
Guest User

Untitled

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