Wiiplay123

Wii Miner v11.1

Mar 8th, 2016 (edited)
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.85 KB | None | 0 0
  1. local blacklist = {"minecraft:air","minecraft:leaves","minecraft:sand","minecraft:diorite","minecraft:andesite","minecraft:granite","minecraft:bedrock","minecraft:flowing_lava","minecraft:flowing_water","minecraft:lava","minecraft:water","minecraft:stone","minecraft:cobblestone","minecraft:dirt","minecraft:gravel","minecraft:clay","minecraft:torch","minecraft:soul_sand","minecraft:netherrack","minecraft:magma","minecraft:fire"}
  2. local superBlacklist = {"grass","snow","flower","computercraft","marble","limestone","chisel","quark","stone_bricks","plant"}
  3. local whitelist = {}
  4. local scanning = false
  5. local hasChest = (turtle.getItemCount(1) > 0 and turtle.getItemDetail(1).name == "enderstorage:ender_storage")
  6. turtle.select(hasChest and 2 or 1)
  7. if #({...}) == 1 and ({...})[1] == "nether" then
  8. table.insert(superBlacklist,"tconstruct")
  9. table.insert(superBlacklist,"tinker")
  10. elseif #({...}) > 0 then
  11. whitelist = {...}
  12. if ({...})[1] == "scan" then
  13. table.remove(whitelist,1)
  14. scanning = true
  15. end
  16. end
  17. local directions = {["north"]=1,["east"]=2,["south"]=3,["west"]=4}
  18. local directionStr = {"north","east","south","west"}
  19. local directionsVector = {{0,0,-1},{1,0,0},{0,0,1},{-1,0,0},{0,1,0},{0,-1,0}}
  20. local scanner = false
  21. local maxScan = 0
  22. term.clear()
  23. term.setCursorPos(1,1)
  24. print("Wii Turtle Miner Initialized")
  25. if peripheral.getType("right") == "plethora:scanner" then
  26.     scanner = peripheral.wrap("right")
  27. elseif peripheral.getType("left") == "plethora:scanner" then
  28.     scanner = peripheral.wrap("left")
  29. end
  30. if scanner then
  31. for i, v in pairs (scanner.scan()) do
  32. maxScan = math.max(v.x,maxScan)
  33. end
  34. print("Scanner found with radius "..maxScan)
  35. end
  36. print("Ender chest " ..(hasChest and "" or " not ").."present.")
  37. function selfScan(inScan)
  38. local test = math.floor(#inScan/2)
  39. if inScan[test].x == 0 and inScan[test].y == 0 and inScan[test].z == 0 then
  40.     return inScan[test]
  41. else
  42.     test = test + 1
  43.     if inScan[test].x == 0 and inScan[test].y == 0 and inScan[test].z == 0 then
  44.         return inScan[test]
  45.     else
  46.         for i, v in pairs(inScan) do
  47.             if v.x == 0 and v.y == 0 and v.z == 0 then
  48.                 return v
  49.             end
  50.         end
  51.     end
  52. end
  53. end
  54.  
  55. function chestDump()
  56. if hasChest and turtle.getItemCount(16) > 0 then
  57. turtle.select(16)
  58. repeat until not turtle.digUp()
  59. turtle.select(1)
  60. turtle.placeUp()
  61. for i = 2, 16 do
  62. turtle.select(i)
  63. turtle.dropUp(64)
  64. end
  65. turtle.select(1)
  66. turtle.digUp()
  67. end
  68. end
  69.  
  70. function compass(compassScan)
  71. local self = selfScan((compassScan ~= nil and compassScan or scanner.scan()))
  72. return self.state.facing
  73. end
  74.  
  75. function setDir(targetDirections)
  76. local targetDirection = (type(targetDirections) == "string" and targetDirections or directionStr[targetDirections])
  77. local currentDirection = compass()
  78. local leftTurns = (directions[currentDirection] - directions[targetDirection]) % 4
  79. if leftTurns == 1 then
  80. turtle.turnLeft()
  81. elseif leftTurns == 2 then
  82. turtle.turnLeft() turtle.turnLeft()
  83. elseif leftTurns == 3 then
  84. turtle.turnRight()
  85. end
  86. end
  87.  
  88. -- -x = west, x = east
  89. -- -z = north, z = south
  90. -- -y = down, y = up
  91.  
  92. function getBlock(x,y,z,scanned)
  93.     local width = (maxScan*2)+1
  94.     local scan = scanned[width ^ 2 * (x + maxScan) + width * (y + maxScan) + (z + maxScan) + 1]
  95.     --print(scan.name.." "..scan.x.." "..scan.y.." "..scan.z)
  96.     return scan
  97. end
  98.  
  99. function nav(x,y,z)
  100.     local initialScan = scanner.scan()
  101.     local initialDirection = compass(initialScan)
  102.     local canDoXFirst = true
  103.     local canDoZFirst = true
  104.     for i = 1, math.abs(x) do
  105.         if getBlock((x > 0 and i or -i), 0, 0, initialScan).name == "minecraft:bedrock" then
  106.             canDoXFirst = false
  107.             break
  108.         end
  109.     end
  110.     for i = 1, math.abs(z) do
  111.         if getBlock(x, 0, (z > 0 and i or -i), initialScan).name == "minecraft:bedrock" then
  112.             canDoXFirst = false
  113.             break
  114.         end
  115.     end
  116.     if not canDoXFirst then
  117.         for i = 1, math.abs(z) do
  118.             if getBlock(0, 0, (z > 0 and i or -i), initialScan).name == "minecraft:bedrock" then
  119.                 canDoZFirst = false
  120.                 break
  121.             end
  122.         end
  123.         for i = 1, math.abs(x) do
  124.             if getBlock((x > 0 and i or -i), 0, z, initialScan).name == "minecraft:bedrock" then
  125.                 canDoZFirst = false
  126.                 break
  127.             end
  128.         end
  129.        
  130.     end
  131.     if (not canDoXFirst) and (canDoZFirst) then
  132.         if z < 0 then
  133.             setDir("north")
  134.         elseif z >= 1 then
  135.             setDir("south")
  136.         end
  137.         for i = 1, math.abs(z) do
  138.             rForward()
  139.             mineOre()
  140.         end
  141.         if x < 0 then
  142.             setDir("west")
  143.         elseif x >= 1 then
  144.             setDir("east")
  145.         end
  146.         for i = 1, math.abs(x) do
  147.             rForward()
  148.             mineOre()
  149.         end
  150.         if x < 0 then
  151.             setDir("west")
  152.         elseif x >= 1 then
  153.             setDir("east")
  154.         end
  155.         for i = 1, math.abs(x) do
  156.             rBack()
  157.         end
  158.         if z < 0 then
  159.             setDir("north")
  160.         elseif z >= 1 then
  161.             setDir("south")
  162.         end
  163.         for i = 1, math.abs(z) do
  164.             rBack()
  165.         end
  166.     elseif canDoXFirst then
  167.         if x < 0 then
  168.             setDir("west")
  169.         elseif x >= 1 then
  170.             setDir("east")
  171.         end
  172.         for i = 1, math.abs(x) do
  173.             rForward()
  174.             mineOre()
  175.         end
  176.         if z < 0 then
  177.             setDir("north")
  178.         elseif z >= 1 then
  179.             setDir("south")
  180.         end
  181.         for i = 1, math.abs(z) do
  182.             rForward()
  183.             mineOre()
  184.         end
  185.         if z < 0 then
  186.             setDir("north")
  187.         elseif z >= 1 then
  188.             setDir("south")
  189.         end
  190.         for i = 1, math.abs(z) do
  191.             rBack()
  192.         end
  193.         if x < 0 then
  194.             setDir("west")
  195.         elseif x >= 1 then
  196.             setDir("east")
  197.         end
  198.         for i = 1, math.abs(x) do
  199.             rBack()
  200.         end
  201.         setDir(initialDirection)
  202.         return true
  203.     else
  204.         print("Bedrock blocks "..x.." "..y.." "..z)
  205.         return false
  206.     end
  207. end
  208.  
  209. function rBack()
  210. if not turtle.back() then
  211. turtle.turnLeft()
  212. turtle.turnLeft()
  213. if ({turtle.inspect()})[2].name == "minecraft:bedrock" then
  214. return false
  215. else
  216. repeat turtle.dig() until turtle.forward()
  217. end
  218. turtle.turnLeft()
  219. turtle.turnLeft()
  220. end
  221. return true
  222. end
  223.  
  224. function rUp()
  225. if not turtle.up() then
  226. if ({turtle.inspectUp()})[2].name == "minecraft:bedrock" then
  227. return false
  228. else
  229. repeat turtle.digUp() until turtle.up()
  230. end
  231. end
  232. return true
  233. end
  234.  
  235. function rDown()
  236. if not turtle.down() then
  237. if ({turtle.inspectDown()})[2].name == "minecraft:bedrock" then
  238. return false
  239. else
  240. repeat turtle.digDown() until turtle.down()
  241. end
  242. end
  243. return true
  244. end
  245.  
  246. function rForward()
  247. if not turtle.forward() then
  248. if ({turtle.inspect()})[2].name == "minecraft:bedrock" then
  249. return false
  250. else
  251. repeat turtle.dig() until turtle.forward()
  252. end
  253. end
  254. return true
  255. end
  256.  
  257. function check(things)
  258. local thing = (type(things) == "string" and {["name"] = things} or things)
  259. if thing ~= nil then
  260. if #whitelist > 0 then
  261. for i, v in pairs(whitelist) do
  262. if string.match(string.lower(thing.name),v) then
  263. return true
  264. end
  265. end
  266. else
  267. for i, v in pairs(blacklist) do
  268. if thing.name == v then
  269. return false
  270. end
  271. end
  272. for i, v in pairs(superBlacklist) do
  273. if string.match(string.lower(thing.name),v) then
  274. return false
  275. end
  276. end
  277. return true
  278. end
  279. end
  280. return false
  281. end
  282.  
  283. function turtleRefillThing()
  284. if turtle.getFuelLevel() ~= "unlimited" then
  285. if turtle.getFuelLevel() < (turtle.getFuelLimit() / 5) then
  286. local nums = {}
  287. for p = 1, 16 do
  288. local o = turtle.getItemDetail(p)
  289. if o ~= nil then
  290. if o.name == "minecraft:coal" or o.name == "minecraft:planks" or o.name == "minecraft:fence" then
  291. table.insert(nums,p)
  292. end
  293. end
  294. end
  295. for o, p in pairs(nums) do
  296. turtle.select(p)
  297. local itemName = (turtle.getItemDetail(p))
  298. if itemName == nil then
  299. itemName = {}
  300. itemName["name"] = "EMPTY"
  301. end
  302. if check(itemName) == false then
  303. turtle.select(p)
  304. turtle.drop()
  305. turtle.dropDown()
  306. turtle.dropUp()
  307. end
  308. while turtle.getFuelLevel() < turtle.getFuelLimit() / 5 and turtle.getItemCount(turtle.getSelectedSlot()) > 0 and turtle.getItemDetail(turtle.getSelectedSlot()) ~= nil do
  309. turtle.refuel()
  310. end
  311. if turtle.getFuelLevel() >= turtle.getFuelLimit() / 5 then
  312. break
  313. end
  314. end
  315. else
  316. turtle.refuel()
  317. end
  318. end
  319. chestDump()
  320. turtle.select(hasChest and 2 or 1)
  321. end
  322.  
  323. function clipDir(dir)
  324. return ((dir - 1) % 4) + 1
  325. end
  326.  
  327. function scanSides(sideScan)
  328. local currentScan = (sideScan ~= nil and sideScan or scanner.scan())
  329. local currentDirection = compass(currentScan)
  330. --local directionsVector = {["north"] = {0,0,-1},["east"] = {1,0,0},["south"] = {0,0,1},["west"] = {-1,0,0},["up"] = {0,1,0},["down"] = {0,-1,0}}
  331. --local leftTurns = (directions[currentDirection] - directions[targetDirection]) % 4
  332. local turtleSides = {["left"] = directionsVector[clipDir(directions[currentDirection] - 1)],["front"] = directionsVector[directions[currentDirection]],["right"] = directionsVector[clipDir(directions[currentDirection] + 1)],["back"] = directionsVector[clipDir(directions[currentDirection] - 2)],["up"] = directionsVector[5], ["down"] = directionsVector[6]}
  333. local blankSides = {}
  334. for i, v in pairs(turtleSides) do
  335. local blankSideX, blankSideY, blankSideZ = unpack(v)
  336. blankSides[i] = getBlock(blankSideX,blankSideY,blankSideZ,currentScan)
  337. end
  338. return blankSides
  339.  -- Left = -1, Front = 0, Right = 1, Back = 2
  340. end
  341.  
  342. function turnMine()
  343. if scanner then
  344. local initD = compass()
  345. local sides = scanSides()
  346. if check(sides["front"]) or check(sides["up"]) or check(sides["down"]) then
  347. mineOre()
  348. sides = scanSides()
  349. end
  350. if check(sides["right"]) then
  351. turtle.turnRight()
  352. mineOre()
  353. sides = scanSides()
  354. end
  355. if check(sides["back"]) then
  356. setDir(clipDir(directions[initD] + 2))
  357. mineOre()
  358. sides = scanSides()
  359. end
  360. if check(sides["left"]) then
  361. setDir(clipDir(directions[initD] + 3))
  362. mineOre()
  363. sides = scanSides()
  364. end
  365. setDir(initD)
  366. else
  367. for i = 1, 4 do
  368. turtle.turnLeft()
  369. if i < 4 then
  370. mineOre()
  371. end
  372. end
  373. end
  374. end
  375.  
  376. function vMult(tab, num)
  377. local tempTab = {}
  378. for i = 1, #tab do
  379. if type(tab[i]) == "number" then
  380. tempTab[i] = tab[i]*num
  381. else
  382. tempTab[i] = tab[i]
  383. end
  384. end
  385. end
  386.  
  387. function mineOre()
  388. turtleRefillThing()
  389. local startDir = "north"
  390. local mineScan = {}
  391. if scanner then
  392. mineScan = scanner.scan()
  393. startDir = compass(mineScan)
  394. sides = scanSides(mineScan)
  395. if check(sides["front"]) then
  396. turtle.dig()
  397. local dX, dY, dZ = unpack(directionsVector[directions[startDir]])
  398. if check(getBlock(dX,-1,dZ,mineScan)) or check(getBlock(dX,1,dZ,mineScan)) or check(getBlock(dX, dY, dZ, mineScan)) then
  399. rForward()
  400. if (check(getBlock(dX,-1,dZ,mineScan))) then
  401. turtle.digDown()
  402. if needsSpins2(scanner.scan(),-1) then
  403. rDown()
  404. turnMine()
  405. rUp()
  406. end
  407. end
  408. if (check(getBlock(dX,1,dZ,mineScan))) then
  409. turtle.digUp()
  410. if needsSpins2(scanner.scan(),1) then
  411. rUp()
  412. turnMine()
  413. rDown()
  414. end
  415. end
  416. turnMine()
  417. rBack()
  418. end
  419. end
  420. else
  421. local work, inspect = turtle.inspect()
  422. if work then
  423. if check(inspect) then
  424. turtle.dig()
  425. rForward()
  426. turtle.turnLeft()
  427. for i = 1, 3 do
  428. local wo, ex = turtle.inspect()
  429. if wo and check(ex) and swood then
  430. mineOre()
  431. end
  432. local wo2, ex2 = turtle.inspectDown()
  433. if wo2 and check(ex2) then
  434. local meow = turtle.digDown()
  435. if meow then
  436. rDown()
  437. turnMine()
  438. rUp()
  439. end
  440. end
  441. local wo3, ex3 = turtle.inspectUp()
  442. if wo3 and check(ex3) then
  443. local meow = turtle.digUp()
  444. if meow then
  445. rUp()
  446. turnMine()
  447. rDown()
  448. end
  449. end
  450. if i < 3 then
  451. turtle.turnRight()
  452. end
  453. end
  454. turtle.turnLeft()
  455. end
  456. rBack()
  457. end
  458. local worku, inspectu = turtle.inspectUp()
  459. if worku then
  460. if check(inspectu) then
  461. turtle.digUp()
  462. rUp()
  463. turnMine()
  464. rDown()
  465. end
  466. end
  467. local workd, inspectd = turtle.inspectDown()
  468. if workd then
  469. if check(inspectd) then
  470. turtle.digDown()
  471. rDown()
  472. turnMine()
  473. rUp()
  474. end
  475. end
  476. end
  477. end
  478.  
  479. function needsSpins(currentScanz,n,nAtScan)
  480. return (not scanner) or (scanner and (check(getBlock(1,(nAtScan - n),0,currentScanz)) or check(getBlock(-1,(nAtScan - n),0,currentScanz)) or check(getBlock(0,(nAtScan - n),1,currentScanz)) or check(getBlock(0,(nAtScan - n),-1,currentScanz))))
  481. end
  482.  
  483. function needsSpins2(currentScanz,n)
  484. return check(getBlock(1,n,0,currentScanz)) or check(getBlock(-1,n,0,currentScanz)) or check(getBlock(0,n,1,currentScanz)) or check(getBlock(0,n,-1,currentScanz))
  485. end
  486.  
  487. function mineLoop()
  488. turtleRefillThing()
  489. turtle.select(hasChest and 2 or 1)
  490. n = 0
  491. nAtScan = 0
  492. built = false
  493. done = false
  494. local currentScan = {}
  495. local firstDirection = "north"
  496. if scanner then
  497. firstDirection = compass()
  498. end
  499. while done == false do
  500. turtle.digDown()
  501. if (n == 0) then
  502. turtleRefillThing()
  503. rDown()
  504. n = n + 1
  505. end
  506. if scanner then
  507. local keepScanning = false
  508. repeat
  509. local currentScan = scanner.scan()
  510. nAtScan = n
  511. print("Scan at level "..n.." found "..(#currentScan).." blocks")
  512. local keepScanning2 = false
  513. for i = 1, #currentScan do
  514. if currentScan[i] and currentScan[i].name ~= nil then
  515. if currentScan[i].y == 0 and check(currentScan[i]) then
  516. print("Located "..currentScan[i].name.." at "..currentScan[i].x.." "..currentScan[i].y.." "..currentScan[i].z.." "..n.." "..nAtScan)
  517. turtleRefillThing()
  518. keepScanning2 = nav(currentScan[i].x,0,currentScan[i].z)
  519. break
  520. end
  521. end
  522. end
  523. if not keepScanning2 then
  524. keepScanning = true
  525. end
  526. until keepScanning
  527. end
  528. if needsSpins(currentScan,nAtScan,n) then
  529. for i = 1,4 do
  530. mineOre()
  531. if i < 4 then
  532. turtle.turnRight()
  533. end
  534. end
  535. end
  536. local hasBlock, block = turtle.inspectDown()
  537. if block.name == "minecraft:bedrock" then
  538. print("Hit bottom, returning.")
  539. for i = 1,n do
  540. turtleRefillThing()
  541. rUp()
  542. end
  543. if scanner then
  544. setDir(firstDirection)
  545. else
  546. if n == 1 then
  547. turtle.turnRight()
  548. elseif n == 2 then
  549. turtle.turnLeft()
  550. turtle.turnLeft()
  551. elseif n == 3 then
  552. turtle.turnLeft()
  553. end
  554. end
  555. turtle.select(hasChest and 2 or 1)
  556. turtle.placeDown()
  557. done = true
  558. print("Done.")
  559. else
  560. n = n + 1
  561. turtleRefillThing()
  562. rDown()
  563. end
  564. end
  565. end
  566.  
  567. function scan()
  568. turtle.select(hasChest and 2 or 1)
  569. if scanner then
  570. local items = {}
  571. local n = 0
  572. local currentScan = {}
  573. repeat
  574. if (n % maxScan) == 0 then
  575. currentScan = scanner.scan()
  576. for i = 1, #currentScan do
  577. if check(currentScan[i]) then
  578. if items[currentScan[i].name] == nil then
  579. items[currentScan[i].name] = 1
  580. else
  581. items[currentScan[i].name] = items[currentScan[i].name] + 1
  582. end
  583. end
  584. end
  585. end
  586. n = n + 1
  587. until not rDown()
  588. for i = 1, n - 1 do
  589. rUp()
  590. end
  591. turtle.placeDown()
  592. for i, v in pairs(items) do
  593. print("Found "..v.." of "..i)
  594. os.pullEvent("key")
  595. end
  596. else
  597. print("Scanner not found.")
  598. end
  599. end
  600.  
  601. if scanning then scan() else mineLoop() end
  602. chestDump()
Add Comment
Please, Sign In to add comment