spankyTheBeaver

Untitled

Aug 9th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.85 KB | None | 0 0
  1. local digX = 64 --multiple van 2
  2. local digY = 40
  3. local digZ = 64 --multiple van 4
  4.  
  5. --[[
  6.  
  7. ░ █ ▄ ▀
  8.  
  9.  
  10. place facing south
  11.  
  12. inefficient furthest corner
  13.  
  14.  
  15.  
  16. flopping weener
  17.  
  18. turtle inventory slots:
  19.  
  20. -------------
  21. |01|02|03|04|
  22. -------------
  23. |05|06|07|08|
  24. -------------
  25. |09|10|11|12|
  26. -------------
  27. |12|14|15|16|
  28. -------------
  29.  
  30. fuel chest in 15
  31. refueling in 14
  32. drop chest in 16
  33. inventory up to 13
  34.  
  35.  
  36.  
  37. all moving will involve digging and checking, stuff in its path will be destroyed
  38. coordinates and facing directions are updated inside the functions
  39.  
  40. x -> travel east and x increases, travel west and x decreases
  41. y -> height
  42. z -> travel south and z increases, travel north and z decreases
  43.  
  44. for cardinal direction facing:
  45.  
  46. 1=north
  47. 2=east
  48. 3=south
  49. 4=west
  50.  
  51. when moving forward, x and z change depending on facing:
  52.  
  53. 1=North, z=z-1
  54. ^
  55. |
  56. 4=west, x=x-1 <-- --> 2=east, x=x+1
  57. |
  58. v
  59. 3=south, z=z+1
  60.  
  61.  
  62. quary length and width are positive
  63. when digging the quarry in north and west directions, stopping values are zll and xll, zll = zhl - digZ, same for x
  64. zhl is start coordinate
  65. xhl is start coordinate
  66. ]]
  67.  
  68. --facing = 3 --face south when placed
  69. facing = 1 --face north blabla
  70.  
  71. facings = {"north", "east", "south", "west"} --needs local??
  72. directions = {"north", "east", "south", "west"}
  73.  
  74. dx = {0, 1, 0, -1} --these values come directly from the above shown windroos
  75. dz = {-1, 0, 1, 0} --e.g. if facing north and moving forward dx=0 and dz=-1
  76.  
  77. local maxInventorySlot = 13 --13 for drop() function, this is the last inventory slot to be used
  78. local fuelSlot = 14
  79. local fuelChestSlot = 15 --for reFuel()function
  80. local dropChestSlot = 16 --drop chest slot piggfucker
  81.  
  82. local xt = 0 --turtle start 588
  83. local xhl = 0 --quarry start -16
  84. local xll = -2 --multiples van 2
  85.  
  86. local yt = 54 --turtle start was 70
  87. local yhl = 54 --quarry start
  88. local yll = -2
  89.  
  90. local zt = 0 --turtle start was 583
  91. local zhl = 605 --quarry start 590
  92. local zll = -4 --moet in multiples van 4
  93.  
  94. local yTravel = 80
  95.  
  96. function turtleLeft() --CW = positive, CCW = negative
  97. facing = facing - 1 --silly table starts at 1,
  98. facing = (facing - 1) % 4 --but division remainder does not...
  99. facing = facing + 1 --substract 1 first, add it back when done
  100. turtle.turnLeft()
  101. end
  102.  
  103. function turtleRight()
  104. facing = facing - 1
  105. facing = (facing + 1) % 4
  106. facing = facing + 1
  107. turtle.turnRight()
  108. end
  109.  
  110. function face(direction)
  111. if direction == "north" then dir = 1
  112. elseif direction == "east" then dir = 2
  113. elseif direction == "south" then dir = 3
  114. elseif direction == "west" then dir = 4
  115. else
  116. end
  117. if dir - facing == 1 or dir - facing == -3 then
  118. while direction ~= facings[facing] do
  119. turtleRight()
  120. end
  121. else
  122. while direction ~= facings[facing] do
  123. turtleLeft()
  124. end
  125. end
  126. end
  127.  
  128. function turtleUp()
  129. local moved = false
  130. while not(moved) do
  131. turtle.digUp()
  132. drop()
  133. moved = turtle.up()
  134. reFuel()
  135. sleep(0.1)
  136. end
  137. yt = yt + 1
  138. end
  139.  
  140. function turtleUpNoDrop()
  141. local moved = false
  142. while not(moved) do
  143. turtle.digUp()
  144. moved = turtle.up()
  145. reFuel()
  146. sleep(0.1)
  147. end
  148. yt = yt + 1
  149. end
  150.  
  151. function turtleDown()
  152. local moved = false
  153. while not(moved) do
  154. turtle.digDown()
  155. drop()
  156. moved = turtle.down()
  157. reFuel()
  158. sleep(0.1)
  159. end
  160. yt = yt - 1
  161. end
  162.  
  163. function turtleDownNoDrop()
  164. local moved = false
  165. while not(moved) do
  166. turtle.digDown()
  167. moved = turtle.down()
  168. reFuel()
  169. sleep(0.1)
  170. end
  171. yt = yt - 1
  172. end
  173.  
  174. function turtleForward()
  175. local moved = false
  176. while not(moved) do
  177. turtle.dig()
  178. drop()
  179. moved = turtle.forward()
  180. reFuel()
  181. end
  182. xt = xt + dx[facing] --change in location will be looked up in tables
  183. zt = zt + dz[facing] --dx and dz, dependend on facing value
  184. end
  185.  
  186. function turtleForwardNoDrop()
  187. local moved = false
  188. while not(moved) do
  189. turtle.dig() --this should fix the fucking gravel from stopping my turtle
  190. --drop()
  191. moved = turtle.forward()
  192. reFuel()
  193. end
  194. xt = xt + dx[facing] --change in location will be looked up in tables
  195. zt = zt + dz[facing] --dx and dz, dependend on facing value
  196. end
  197.  
  198. function digDown() --double dick down, down and then forward for superefficiency
  199. local moved = false
  200. while not(moved) do
  201. turtle.digDown()
  202. drop()
  203. moved = turtle.down()
  204. reFuel()
  205. turtle.dig()
  206. drop()
  207. end
  208. yt = yt - 1
  209. end
  210.  
  211. function digUp() --double dick up, up and then forward for superefficiency
  212. local moved = false
  213. while not(moved) do
  214. turtle.digUp()
  215. drop()
  216. moved = turtle.up()
  217. reFuel()
  218. turtle.dig()
  219. drop()
  220. end
  221. yt = yt + 1
  222. end
  223.  
  224. function drop() --when last inventory slot has an item, place an enderchest and dump all
  225. if turtle.getItemCount(maxInventorySlot) > 0 then
  226. local moved = false
  227. while not(moved) do
  228. turtle.digUp()
  229. moved = turtle.up()
  230. reFuel()
  231. sleep(0.1)
  232. end
  233. yt = yt + 1
  234. turtle.select(dropChestSlot)
  235. turtle.placeDown()
  236. local slot = 1
  237. while slot <= maxInventorySlot do
  238. turtle.select(slot)
  239. turtle.dropDown()
  240. slot = slot + 1
  241. end
  242. turtle.select(dropChestSlot)
  243. turtle.digDown()
  244. turtle.select(1) --start filling those slots again
  245. turtle.down()
  246. yt = yt - 1
  247. end
  248. end
  249.  
  250. function dropNoEnder()
  251. if turtle.getItemCount(maxInventorySlot) > 0 then
  252. xSite = xt
  253. zSite = zt
  254. ySite = yt
  255. facingSite = facing
  256. gotoHomeNoDrop()
  257. face("north")
  258. local slot = 1
  259. while slot <= maxInventorySlot do
  260. turtle.select(slot)
  261. turtle.drop()
  262. slot = slot + 1
  263. end
  264. gotoSite()
  265. while facings[facing] ~= facings[facingSite] do
  266. turtleLeft()
  267. end
  268. turtle.select(1) --start filling those slots again
  269. end
  270. end
  271.  
  272. function gotoHome()
  273. gotoY(yTravel)
  274. gotoX(xHome)
  275. gotoZ(zHome)
  276. gotoY(yHome)
  277. end
  278.  
  279. function gotoHomeNoDrop()
  280. gotoYNoDrop(yTravel)
  281. gotoXNoDrop(xHome)
  282. gotoZNoDrop(zHome)
  283. gotoYNoDrop(yHome)
  284. end
  285.  
  286. function gotoSite()
  287. gotoY(yTravel)
  288. gotoZ(zSite)
  289. gotoX(xSite)
  290. gotoY(ySite)
  291. end
  292.  
  293. function reFuel()
  294. if turtle.getFuelLevel() < 20 then
  295. if turtle.getItemCount(fuelSlot) == 0 then
  296. local moved = false
  297. while not(moved) do
  298. turtle.digUp()
  299. moved = turtle.up()
  300. sleep(0.1)
  301. end
  302. yt = yt + 1
  303. turtle.select(15) --(fuelChestSlot)
  304. turtle.placeDown()
  305. turtle.select(14) --(fuelSlot)
  306. turtle.suckDown()
  307. turtle.select(15) --(fuelChestSlot)
  308. turtle.digDown()
  309. turtle.down()
  310. yt = yt - 1
  311. else
  312. end
  313. turtle.select(14) --(fuelSlot)
  314. turtle.refuel()
  315. turtle.select(1)
  316. else
  317. end
  318. end
  319.  
  320. function digPlaneToNorth()
  321. face("north") --facing north will reduce z
  322. while zt > zll + 1 do --1:0 > -8 + 1 is true
  323. while yt > yll do
  324. digDown()
  325. end
  326. turtleForward() ---1 -5
  327. turtleForward() ---2 -6
  328. turtle.dig()
  329. while yt < yhl do
  330. digUp()
  331. end
  332. turtleForward() ---3 -7
  333. if zt ~= zll + 1 then --was -7
  334. turtleForward() ---4 -8
  335. else
  336. end
  337. end
  338. end
  339.  
  340. function digPlaneToSouth()
  341. face("south") --facing north will reduce z
  342. while zt < zhl - 1 do -- -7 < 0 - 1 is true
  343. while yt > yll do
  344. digDown()
  345. end
  346. turtleForward() ---6 -2
  347. turtleForward() ---5 -1
  348. turtle.dig()
  349. while yt < yhl do
  350. digUp()
  351. end
  352. turtleForward() ---4 0
  353. if zt ~= zhl then --
  354. turtleForward() ---3 +1
  355. else
  356. end
  357. end
  358. end
  359.  
  360. function gotoX(Xtarget)
  361. while xt > Xtarget do
  362. face("west")
  363. while xt > Xtarget do
  364. turtleForward()
  365. end
  366. end
  367.  
  368. while xt < Xtarget do
  369. face("east")
  370. while xt < Xtarget do
  371. turtleForward()
  372. end
  373. end
  374. end
  375.  
  376. function gotoXNoDrop(Xtarget)
  377. while xt > Xtarget do
  378. face("west")
  379. while xt > Xtarget do
  380. turtleForwardNoDrop()
  381. end
  382. end
  383.  
  384. while xt < Xtarget do
  385. face("east")
  386. while xt < Xtarget do
  387. turtleForwardNoDrop()
  388. end
  389. end
  390. end
  391.  
  392. function gotoZ(Ztarget)
  393. while zt > Ztarget do
  394. face("north")
  395. while zt > Ztarget do
  396. turtleForward()
  397. end
  398. end
  399.  
  400. while zt < Ztarget do
  401. face("south")
  402. while zt < Ztarget do
  403. turtleForward()
  404. end
  405. end
  406. end
  407.  
  408. function gotoZNoDrop(Ztarget)
  409. while zt > Ztarget do
  410. face("north")
  411. while zt > Ztarget do
  412. turtleForwardNoDrop()
  413. end
  414. end
  415.  
  416. while zt < Ztarget do
  417. face("south")
  418. while zt < Ztarget do
  419. turtleForwardNoDrop()
  420. end
  421. end
  422. end
  423.  
  424. function gotoY(Ytarget)
  425. while yt > Ytarget do
  426. turtleDown()
  427. end
  428.  
  429. while yt < Ytarget do
  430. turtleUp()
  431. end
  432. end
  433.  
  434. function gotoYNoDrop(Ytarget)
  435. while yt > Ytarget do
  436. turtleDownNoDrop()
  437. end
  438.  
  439. while yt < Ytarget do
  440. turtleUpNoDrop()
  441. end
  442. end
  443.  
  444. function digCube()
  445. while xt > xll + 1 do -- while 0 > -4 true
  446. digPlaneToNorth()
  447. face("west")
  448. turtleForward() -- x=-1 -3
  449. digPlaneToSouth()
  450. if xt ~= xll + 1 then
  451. face("west")
  452. turtleForward() -- x=-2 -4
  453. else
  454. end
  455. end
  456. end
  457.  
  458. function quarryStart()
  459. xhl = xt
  460. yhl = yt
  461. zhl = zt
  462. xll = xhl - digX
  463. yll = yhl - digY
  464. zll = zhl - digZ
  465. digCube()
  466. end
  467.  
  468. function finalDrop()
  469. local slot = 1
  470. face("north")
  471. while slot <= maxInventorySlot do
  472. turtle.select(slot)
  473. turtle.drop()
  474. slot = slot + 1
  475. end
  476. end
  477.  
  478. function finaldrop2()
  479. local moved = false
  480. while not(moved) do
  481. turtle.digUp()
  482. moved = turtle.up()
  483. reFuel()
  484. sleep(0.1)
  485. end
  486. yt = yt + 1
  487. turtle.select(dropChestSlot)
  488. turtle.placeDown()
  489. local slot = 1
  490. while slot <= maxInventorySlot do
  491. turtle.select(slot)
  492. turtle.dropDown()
  493. slot = slot + 1
  494. end
  495. turtle.select(dropChestSlot)
  496. turtle.digDown()
  497. turtle.select(1) --start filling those slots again
  498. turtle.down()
  499. yt = yt - 1
  500. end
  501.  
  502. xHome = xt
  503. zHome = zt
  504. yHome = yt
  505.  
  506. term.clear()
  507.  
  508. quarryStart()
  509. face("south")
  510.  
  511. finaldrop2()
  512.  
  513.  
  514.  
  515.  
  516. --------facing test---------
  517. --[[
  518. while true do
  519. term.clear()
  520. term.setCursorPos(1,1)
  521. print("Select direction: north 1 /east 2 /south 3 /west 4 ")
  522. print("Current direction: "..facing)
  523. term.write(" ")
  524. direction = tostring(read())
  525. print(" ")
  526. face(direction)
  527. end
  528. --]]
Add Comment
Please, Sign In to add comment