Advertisement
Wihad

CC Miner

Jun 25th, 2019 (edited)
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.47 KB | None | 0 0
  1. local currPos=-2
  2. local tunnel=2
  3. local lavaRefuel=1
  4. local tblWallBlocks={"minecraft:cobblestone", "minecraft:stone", "minecraft:dirt", "minecraft:netherrack", "minecraft:basalt", "minecraft:blackstone", "extcaves:lavastone", "astralsorcery:blockcustomore", "create:weathered_limestone", "quark:deepslate", "quark:cobbled_deepslate", "minecraft:deepslate", "minecraft:cobbled_deepslate", "minecraft:tuff", "byg:soapstone", "byg:scoria_stone", "byg:scoria_cobblestone"}
  5. local tblPlaceBlocks={"minecraft:cobblestone", "minecraft:dirt", "minecraft:netherrack", "extcaves:lavastone", "minecraft:basalt", "minecraft:blackstone", "create:weathered_limestone", "quark:deepslate", "quark:cobbled_deepslate", "minecraft:deepslate", "minecraft:cobbled_deepslate", "minecraft:tuff", "byg:soapstone", "byg:scoria_stone", "byg:scoria_cobblestone"}
  6. local tblRareBlocks={"minecraft:diamond_ore","minecraft:gold_ore","minecraft:iron_ore","minecraft:deepslate_diamond_ore","minecraft:deepslate_gold_ore","minecraft:deepslate_iron_ore","minecraft:ancient_debris","minecraft:nether_quartz_ore","rftoolsbase:dimensionalshard_nether","tconstruct:cobalt_ore"}
  7.  
  8. function inTable(tbl, item)
  9.     for i, v in ipairs(tbl) do
  10.         if v == item then
  11.             return true
  12.         end
  13.     end
  14.     return false
  15. end
  16.  
  17. function moveForw()
  18.     local try=1
  19.     while not turtle.forward() do
  20.         prntMiningScreen("I can't go forward .. try:"..try)
  21.         sleep(1)
  22.         try=try+1
  23.     end
  24. end
  25.  
  26. function moveBack()
  27.     local try=1
  28.     while not turtle.back() do
  29.         prntMiningScreen("I can't go back .. try:"..try)
  30.         sleep(1)
  31.         try=try+1
  32.     end
  33. end
  34.  
  35. function moveUp()
  36.     local try=1
  37.     while not turtle.up() do
  38.         prntMiningScreen("I can't go up .. try:"..try)
  39.         sleep(1)
  40.         try=try+1
  41.     end
  42. end
  43.  
  44. function moveDown()
  45.     local try=1
  46.     while not turtle.down() do
  47.         prntMiningScreen("I can't go down .. try:"..try)
  48.         sleep(1)
  49.         try=try+1
  50.     end
  51. end
  52.  
  53. function turnL()
  54.     turtle.turnLeft()
  55. end
  56. function turnR()
  57.     turtle.turnRight()
  58. end
  59. function turn2()
  60.     turnR()
  61.     turnR()
  62. end
  63.  
  64. function checkWallStone(ws)
  65.     local success, data
  66.     if ws=="forw" then
  67.         success, data = turtle.inspect()
  68.     elseif ws=="up" then
  69.         success, data = turtle.inspectUp()
  70.     elseif ws=="down" then
  71.         success, data = turtle.inspectDown()
  72.     end
  73.     if success then
  74.         if lavaRefuel==1 then
  75.             if data.name=="minecraft:lava" then
  76.                 refuelLava(ws)
  77.             end
  78.         end
  79.         if (inTable(tblWallBlocks, data.name)) then
  80.             return("wallBlocks")
  81.         elseif (inTable(tblRareBlocks, data.name)) then
  82.             return("rareBlocks")
  83.         else
  84.             return(0)
  85.         end
  86.     end
  87. end
  88.  
  89. function digForw(ws)
  90.     if ws~="wallBlocks" then
  91.         while turtle.detect() do
  92.             turtle.dig()
  93.       end
  94.     end
  95. end
  96.  
  97. function digDown(ws)
  98.     if ws~="wallBlocks" then
  99.         turtle.digDown()
  100.     end
  101. end
  102.  
  103. function digUp(ws)
  104.     if ws~="wallBlocks" then
  105.         while turtle.detectUp() do
  106.             turtle.digUp()
  107.         end
  108.     end
  109. end
  110.  
  111. function placeForw(ws)
  112.     if not turtle.detect() then
  113.         A=placeStone()
  114.         if A==1 then
  115.             if ws~="rareBlocks" then
  116.                 local try=1
  117.                 while not turtle.place() do
  118.                     prntMiningScreen("I can't place forw. a block !..Try: "..try)
  119.                     try=try+1
  120.                     sleep(1)
  121.                 end
  122.             end
  123.         end
  124.     end
  125. end
  126.  
  127. function placeUp(ws)
  128.     if not turtle.detectUp() then
  129.         A=placeStone()
  130.         if A==1 then
  131.             if ws~="rareBlocks" then
  132.                 local try=1
  133.                 while not turtle.placeUp() do
  134.                     prntMiningScreen("I can't place up. a block !..Try: "..try)
  135.                     try=try+1
  136.                     sleep(1)
  137.                 end
  138.             end
  139.         end
  140.     end
  141. end
  142.  
  143. function placeDown(ws)
  144.     if not turtle.detectDown() then
  145.         A=placeStone()
  146.         if A==1 then
  147.             if ws~="rareBlocks" then
  148.                 local try=1
  149.                 while not turtle.placeDown() do
  150.                     prntMiningScreen("I can't place down. a block !..Try: "..try)
  151.                     try=try+1
  152.                     sleep(1)
  153.                 end
  154.             end
  155.         end
  156.     end
  157. end
  158.  
  159. function placeStone()
  160.     for A=1,16 do
  161.         local item=turtle.getItemDetail(A)
  162.         if item then
  163.             if (inTable(tblPlaceBlocks, item.name)) then
  164.                 turtle.select(A)
  165.                 return(1)
  166.             end
  167.         end
  168.         if A==16 then
  169.             return(0)
  170.         end
  171.     end
  172. end
  173.  
  174. function setChest()
  175.     turnL()
  176.     moveForw()
  177.     moveDown()
  178.     moveDown()
  179.     turnL()
  180.     setChest2()
  181.     turnL()
  182.     setChest2()
  183.     moveUp()
  184.     moveUp()
  185.     moveForw()
  186.     turnL()
  187.     setTorch()
  188. end
  189.  
  190. function setChest2()
  191.     for A=1,16 do
  192.         local item=turtle.getItemDetail(A)
  193.         if item then
  194.             if (item.name=="minecraft:chest") then
  195.                 turtle.select(A)
  196.                 if turtle.detect() then turtle.dig() end
  197.                 turtle.place()
  198.                 break
  199.             end
  200.         end
  201.     end
  202. end
  203.  
  204. function goToPos()
  205.     for A=1, currPos do
  206.         moveForw()
  207.     end
  208.     turnR()
  209.     moveForw()
  210.     turnL()
  211.     moveUp()
  212.     moveUp()
  213. end
  214.  
  215. function gotoChest()
  216.     moveDown()
  217.     moveDown()
  218.     turnL()
  219.     moveForw()
  220.     turnL()
  221.     for A=1,currPos do
  222.         moveForw()
  223.     end
  224. end
  225.  
  226. function invFull()
  227.     local full=0
  228.     local blocks=0
  229.     for A=1,16 do
  230.         if turtle.getItemCount(A)>0 then
  231.             full=full+1
  232.             local item=turtle.getItemDetail(A)
  233.             if (inTable(tblPlaceBlocks, item.name)) then
  234.                 blocks=blocks+turtle.getItemCount(A)
  235.             end
  236.         end
  237.     end
  238.     if full>14 or blocks<12 then
  239.         gotoChest()
  240.         emptyInv()
  241.         goToPos()
  242.     end
  243. end
  244.  
  245. function emptyInv()
  246.     turnL()
  247.     for A=1,16 do
  248.         local item=turtle.getItemDetail(A)
  249.         if item then
  250.             if (inTable(tblPlaceBlocks, item.name)) then
  251.                 turtle.select(A)
  252.                 turtle.drop()
  253.             end
  254.         end
  255.     end
  256.     turnR()
  257.     for A=1,16 do
  258.         local item=turtle.getItemDetail(A)
  259.         if item then
  260.             if (item.name~="minecraft:coal") and (item.name~="minecraft:torch") and (item.name~="minecraft:bucket") and (item.name~="tconstruct:stone_torch") then
  261.                 turtle.select(A)
  262.                 turtle.drop()
  263.             elseif item.name=="minecraft:coal" then
  264.                 if turtle.getFuelLevel()<1000 then
  265.                     turtle.select(A)
  266.                     turtle.refuel(20)
  267.                 end
  268.             end
  269.         end
  270.     end
  271.     local try=1
  272.     while turtle.getFuelLevel()<1000 do
  273.         if turtle.refuel(20) then break end
  274.         prntMiningScreen("I need coal. please put some coal in the selected slot..! try: "..try)
  275.         try=try+1
  276.         sleep(2)
  277.     end
  278.     turnL()
  279.     turtle.suck()
  280.     local slot=0
  281.     while true do
  282.         slot=slot+1
  283.         local item=turtle.getItemDetail(slot)
  284.         if item then
  285.             if (inTable(tblPlaceBlocks, item.name)) then
  286.                 break
  287.             end
  288.         end
  289.         if slot==16 then
  290.             prntMiningScreen("I need some cobblestone, dirt, or netherrack...! try: "..try)
  291.             try=try+1
  292.             slot=0
  293.             sleep(2)
  294.         end
  295.     end
  296.     turnL()
  297. end
  298.  
  299. function buildTunnel()
  300.     local ws=0
  301.     digForw(0)
  302.     moveForw()
  303.     turnL()
  304.     ws=checkWallStone("up")
  305.     digUp(ws)
  306.     placeUp(ws)
  307.     if tunnel==1 then
  308.         digForw(0)
  309.         moveForw()
  310.         placeDown(0)
  311.         digDown(0)
  312.         ws=checkWallStone("up")
  313.         digUp(ws)
  314.         placeUp(ws)
  315.     end
  316.     digForw(0)
  317.     moveForw()
  318.     ws=checkWallStone("up")
  319.     digUp(ws)
  320.     placeUp(ws)
  321.     ws=checkWallStone("forw")
  322.     digForw(ws)
  323.     placeForw(ws)
  324.     digDown(0)
  325.     moveDown()
  326.     ws=checkWallStone("forw")
  327.     digForw(ws)
  328.     placeForw(ws)
  329.     digDown(0)
  330.     moveDown()
  331.     ws=checkWallStone("forw")
  332.     digForw(ws)
  333.     placeForw(ws)
  334.     ws=checkWallStone("down")
  335.     digDown(ws)
  336.     placeDown(ws)
  337.     turn2()
  338.     if tunnel==1 then
  339.         digForw(0)
  340.         moveForw()
  341.         ws=checkWallStone("down")
  342.         digDown(ws)
  343.         placeDown(ws)
  344.     end
  345.     digForw(0)
  346.     moveForw()
  347.     ws=checkWallStone("down")
  348.     digDown(ws)
  349.     placeDown(ws)
  350.     ws=checkWallStone("forw")
  351.     digForw(ws)
  352.     placeForw(ws)
  353.     digUp(0)
  354.     moveUp()
  355.     ws=checkWallStone("forw")
  356.     digForw(ws)
  357.     placeForw(ws)
  358.     digUp(0)
  359.     moveUp()
  360.     ws=checkWallStone("forw")
  361.     digForw(ws)
  362.     placeForw(ws)
  363.     turnL()
  364.     currPos=currPos+1
  365. end
  366.  
  367. function setTorch()
  368.     turnL()
  369.     if tunnel==1 then moveForw() end
  370.     for A=1,16 do
  371.         local item=turtle.getItemDetail(A)
  372.         if item then
  373.             if (item.name=="minecraft:torch") or (item.name=="tconstruct:stone_torch") then
  374.                 turtle.select(A)
  375.                 if turtle.detect() then turtle.dig() end
  376.                 turtle.place()
  377.                 break
  378.             end
  379.         end
  380.     end
  381.     if tunnel==1 then moveBack() end
  382.     turnR()
  383. end
  384.  
  385. function refuel()
  386.     if turtle.getFuelLevel()<500 then
  387.         for A=1, 16 do
  388.             local item=turtle.getItemDetail(A)
  389.             if item then
  390.                 if item.name=="minecraft:coal" then
  391.                     turtle.select(A)
  392.                     turtle.refuel(10)
  393.                     if turtle.getFuelLevel()>500 then break
  394.                     end
  395.                 end
  396.             end
  397.             if A==16 then
  398.                 gotoChest()
  399.                 emptyInv()
  400.                 goToPos()
  401.             end
  402.         end
  403.     end
  404. end
  405.  
  406. function refuelLava(ws)
  407.     for A=1, 16 do
  408.         local item=turtle.getItemDetail(A)
  409.         if item then
  410.             if item.name=="minecraft:bucket" then
  411.                 turtle.select(A)
  412.                 if ws=="forw" then
  413.                     turtle.place()
  414.                 elseif ws=="up" then
  415.                     turtle.placeUp()
  416.                 elseif ws=="down" then
  417.                     turtle.placeDown()
  418.                 end
  419.                 turtle.refuel()
  420.                 break
  421.             end
  422.         end
  423.     end
  424.     prntMiningScreen(0)
  425. end
  426.  
  427. function prntScreen()
  428.     term.clear()
  429.     term.setCursorPos(1,1)
  430.     print("Choose your options")
  431.     print("")
  432.     print("1: main tunnel, 3 m wide  ")
  433.     print("2: sec. tunnel, 2 m wide  ")
  434.     if tunnel==1 then
  435.         term.setCursorPos(26,3)
  436.     elseif tunnel==2 then
  437.         term.setCursorPos(26,4)
  438.     end
  439.     term.write("<<<<")
  440.     term.setCursorPos(1,6)
  441.     print("required materials: 8 torches, 2 chests and some fillblocks (e.g. cobblestone)")
  442.     local lr="active)"
  443.     if lavaRefuel==0 then
  444.         lr="inactive)"
  445.     end
  446.     term.setCursorPos(1,10)
  447.     print("r: to toggle lava refuel from world, a bucket will be needed ("..lr)
  448.     term.setCursorPos(1,13)
  449.     term.write("Enter: to start")
  450. end
  451.  
  452. function prntMiningScreen(msg)
  453.     term.clear()
  454.     term.setCursorPos(13,2)
  455.     print("WIMOS MINER")
  456.     term.setCursorPos(29,4)
  457.     term.write("Fuel: " .. turtle.getFuelLevel())
  458.     if msg~=0 then
  459.         term.setCursorPos(1,10)
  460.         print(msg)    
  461.     end
  462. end
  463.  
  464. function main()
  465.     prntScreen()
  466.     while true do
  467.         local check,key=os.pullEvent("key")
  468.         if check then
  469.             if key >= 320 and key <= 329 then key = key - 272 end       -- numpads
  470.             if key==keys.enter then
  471.                 prntMiningScreen(0)
  472.                 break
  473.             elseif key==keys.w or key == 265 or key == 49 then
  474.                 tunnel=1
  475.                 prntScreen()
  476.             elseif key==keys.s or key == 264 or key == 50 then
  477.                 tunnel=2
  478.                 prntScreen()
  479.             elseif key==keys.r then
  480.                 lavaRefuel=(lavaRefuel-1)*(-1)
  481.                 prntScreen()
  482.             end
  483.         end
  484.     end
  485. end
  486.  
  487. main()
  488. digUp(0)
  489. moveUp()
  490. digUp(0)
  491. moveUp()
  492. buildTunnel()
  493. buildTunnel()
  494. setChest()
  495. for A=1,7 do
  496.     for B=1,(5+(tunnel-1)*2) do
  497.         buildTunnel()
  498.         refuel()
  499.         invFull()
  500.     end
  501.     setTorch()
  502. end
  503. for A=0,2 do buildTunnel() end
  504. gotoChest()
  505. emptyInv()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement