Advertisement
Niseg

mining well tube release ver (used by StrayMav)

Jun 13th, 2013
1,327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.63 KB | None | 0 0
  1. local miningwell=1
  2. local chest=2
  3. local conduit=3
  4. local chargestation=4
  5. local args={...}
  6. local slp = 10
  7. local lx=30
  8. local ly=30
  9. local slot=2
  10. local pipeItems=false
  11. local ftbl= {
  12.                 {tpd,   mdd,    turtle.digDown, turtle.detectDown,  turtle.compareDown  },
  13.                 {tpf,       mfd,    turtle.dig  ,   turtle.detect   ,   turtle.compare      },
  14.                 {tpu,   mud,        turtle.digUp,   turtle.detectUp,    turtle.compareUp    }
  15.                
  16.             }
  17. local hasChargeStation=false;
  18. local cf=turtle.getFuelLevel()
  19.  
  20. local function selt(sl)
  21. slot=sl
  22. turtle.select(sl)
  23. end
  24.  
  25. local function digAndThrow(dir)
  26.     if dir== nil  then dir=0 end
  27.     local dir2=dir+2
  28.     local full=false;
  29.     local orgslot=slot
  30. for i=1,16 do
  31.     if turtle.getItemCount(i)==0 then
  32.     selt(i)
  33.     break
  34.     end if(i==16) then
  35.         --print("failed to place block - not critical")
  36. --      return false
  37.         full = true
  38.     end
  39.    
  40. end
  41.     -- if all slots are
  42.     if not ftbl[dir2][3]() then selt(orgslot);return false end
  43.     if not full then
  44.     turtle.drop()
  45.     selt(orgslot)
  46.     end
  47.     return true
  48. end
  49.  
  50. local function mfd()
  51. while not turtle.forward() do
  52. if turtle.getFuelLevel()==0 then return false end
  53. digAndThrow(0)
  54. end
  55. end
  56. local function mbd()
  57.  
  58. while not turtle.back() do
  59. if turtle.getFuelLevel()==0 then return false end
  60. turtle.turnLeft()
  61. turtle.turnLeft()
  62. digAndThrow(0)
  63. turtle.turnLeft()
  64. turtle.turnLeft()
  65. end
  66. return true
  67. end
  68.  
  69. local function mdd()
  70. while not turtle.down() do
  71. if turtle.getFuelLevel()==0 then return false end
  72. digAndThrow(-1)
  73. end
  74. end
  75. local function mud()
  76. while not turtle.up() do
  77. if turtle.getFuelLevel()==0 then return false end
  78. digAndThrow(1)
  79. end
  80. end
  81.  
  82. local function tpf()
  83. while not turtle.place() do digAndThrow(0) end
  84. end
  85.  
  86. local function tpu()
  87. while not turtle.placeUp() do digAndThrow(1) end
  88. return true
  89. end
  90.  
  91. local function tpd()
  92. while not turtle.placeDown() do digAndThrow(-1) end
  93. return true
  94. end
  95.  
  96. local function lookForMore(slotn)
  97. selt(slotn)
  98. --print("entry slotn= "..slotn)
  99. for i=1,16 do
  100.  
  101. if i~=slotn and turtle.compareTo(i) then
  102.         --print ("found more in slot "..i.."with "..turtle.getItemCount(i).." items")
  103.         --print("got space for "..turtle.getItemSpace(slotn).." more")
  104.         selt(i)
  105.         turtle.transferTo(slotn,math.min(turtle.getItemCount(i),turtle.getItemSpace(slotn)))
  106.     --  print("slotn="..slotn)
  107.         selt(slotn)
  108.     return true
  109. end
  110. end
  111. return false
  112.  
  113. end
  114. print("Niseg's Mining well script")
  115. if args[1] ~= nil then slp = tonumber(args[1]) end
  116. if args[2] ~= nil then lx = tonumber(args[2]) end
  117. if args[3] ~= nil then ly = tonumber(args[3]) end
  118. if args[4] ~=nil then pipeItems=true end
  119.  
  120. local wellcount=turtle.getItemCount(miningwell)
  121. if wellcount>=3 then wellcount =3 else wellcount =1 end
  122. --if not pipeItems then wellcount=1 end
  123. if turtle.getItemCount(chargestation)>0 then
  124. print("checking if I have a charge station")
  125. if not mbd() then print("no fuel");error() end
  126. selt(chargestation)
  127.  
  128. tpf(); sleep(5);
  129.  
  130. if(turtle.getFuelLevel()>cf) then hasChargeStation = true end
  131. turtle.dig()
  132. mfd()
  133. end
  134.  
  135. for j=1,ly do
  136.         print("starting row " ..j)         
  137.         local nf=6*lx +wellcount+3;
  138.         cf=turtle.getFuelLevel()
  139.         print("fuel is at "..cf.. " / "..nf)
  140.         while nf>cf do
  141.             if hasChargeStation  then
  142.             mbd()
  143.             selt(chargestation)
  144.             tpf()
  145.             while nf>cf do cf=turtle.getFuelLevel(); sleep(10) end
  146.             turtle.dig()
  147.             mfd()
  148.             else
  149.             print(" I need more fuel")
  150.             for k=1,4 do turtle.turnLeft() end
  151.             shell.run("refuel all")
  152.             sleep(5);
  153.            
  154.             end        
  155.             cf=turtle.getFuelLevel()
  156.         end
  157.         if(pipeItems) then
  158.             selt(chest); tpd()
  159.             mbd();selt(conduit); tpf()
  160.         end
  161.               --  slot=0
  162.                 for i=1,lx do
  163.        
  164.                     if wellcount==1 then --                 single well
  165.                                              
  166.                         selt(miningwell)
  167.                         tpd()
  168.                         mbd()
  169.                         if not pipeItems  then
  170.                             selt(chest)
  171.                             tpd()
  172.                         end
  173.                         if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then break end
  174.                             selt(conduit)
  175.                             tpf()
  176.                         sleep(slp) --don't remember how long
  177.                         if not pipeItems then
  178.                             selt(chest)
  179.                             turtle.digDown()
  180.                         end
  181.                         mdd()
  182.                         selt(miningwell)
  183.                    
  184.                         turtle.dig()
  185.                         if pipeItems and i<lx then
  186.                             if turtle.getItemCount(chest)==1 and not lookForMore(chest) then mud();break end
  187.                    
  188.                             selt(chest)
  189.                             tpf()
  190.                         end
  191.                         mud()
  192.                     else
  193.                             if i==1 then
  194.                             --mbd()
  195.                             mdd()
  196.                             end
  197.                             selt(miningwell)
  198.                             for k=1,3 do
  199.                             turtle.turnLeft()
  200.                             tpf()
  201.                             end
  202.                             mud()
  203.                             if pipeItems and turtle.getItemCount(chest)==1 and not lookForMore(chest) then print("not enough pipes");error() end
  204.                             selt(chest)
  205.                             tpd()
  206.                             for k=1,3 do
  207.                            
  208.                             if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then print("not enough energy pipes");error() end
  209.                             selt(conduit)
  210.                             tpf()
  211.                             turtle.turnRight()
  212.                             end
  213.                             mud()
  214.                             if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then print("not enough energy pipes");error() end
  215.                             selt(conduit)
  216.                             tpd()
  217.                             sleep(slp) --don't remember how long
  218.                            
  219.                             -- time to clean up
  220.                        
  221.                             turtle.digDown()
  222.                             mdd()
  223.                            
  224.                             for k=1,3 do
  225.                             turtle.turnLeft()
  226.                             turtle.dig()
  227.                             end
  228.                             selt(chest)
  229.                             turtle.digDown()
  230.                             mdd()
  231.                             selt(miningwell)
  232.                             for k=1,3 do
  233.                             turtle.dig()
  234.                             turtle.turnRight()
  235.                             end
  236.                             --turtle.turnRight()
  237.                             selt(conduit)-- she'll be right
  238.                             tpu()
  239.                             mbd()
  240.                             if pipeItems then
  241.                             selt(chest)
  242.                             tpf()
  243.                             end
  244.                             if i==lx then mud() end
  245.                            
  246.                     end
  247.                        
  248.                    
  249.                     end
  250.            
  251.  
  252.                  selt(conduit)
  253.                 --- retract the conduits
  254.                 while turtle.detect() do
  255.                 turtle.dig();
  256.                 mfd();
  257.                     if pipeItems and turtle.detect()then
  258.                                     selt(chest)
  259.                                     turtle.digDown()
  260.                                     selt(conduit)
  261.                     end
  262.                 end
  263.  
  264. turtle.turnLeft()
  265. for k=1,wellcount do
  266. mbd()
  267. --tpd()
  268. while redstone.getInput("top") do
  269. selt(conduit)
  270. sleep(1)
  271. turtle.suckUp()
  272. while turtle.detectUp() do sleep(0.5) end
  273.  
  274. end
  275.  
  276. if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then break end
  277. if not turtle.compareUp() then tpu() end
  278.  
  279. if pipeItems then
  280. if turtle.getItemCount(chest)==1 and not lookForMore(chest) then break end
  281. selt(chest)
  282. tpd()
  283. selt(conduit)
  284. end
  285. end
  286. turtle.turnRight()
  287. mbd()
  288. if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then break end
  289. tpf()
  290. --[[if pipeItems then
  291. selt(chest)
  292. tpd()
  293. selt(conduit)
  294. end
  295. --]]
  296. --[[
  297. mbd()
  298. tpf()
  299. if pipeItems then
  300. selt(chest)
  301. tpd()
  302. selt(conduit)
  303. end
  304. --]]
  305.  
  306. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement