Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local miningwell=1
- local chest=2
- local conduit=3
- local chargestation=4
- local args={...}
- local slp = 10
- local lx=30
- local ly=30
- local slot=2
- local pipeItems=false
- local ftbl= {
- {tpd, mdd, turtle.digDown, turtle.detectDown, turtle.compareDown },
- {tpf, mfd, turtle.dig , turtle.detect , turtle.compare },
- {tpu, mud, turtle.digUp, turtle.detectUp, turtle.compareUp }
- }
- local hasChargeStation=false;
- local cf=turtle.getFuelLevel()
- local function selt(sl)
- slot=sl
- turtle.select(sl)
- end
- local function digAndThrow(dir)
- if dir== nil then dir=0 end
- local dir2=dir+2
- local full=false;
- local orgslot=slot
- for i=1,16 do
- if turtle.getItemCount(i)==0 then
- selt(i)
- break
- end if(i==16) then
- --print("failed to place block - not critical")
- -- return false
- full = true
- end
- end
- -- if all slots are
- if not ftbl[dir2][3]() then selt(orgslot);return false end
- if not full then
- turtle.drop()
- selt(orgslot)
- end
- return true
- end
- local function mfd()
- while not turtle.forward() do
- if turtle.getFuelLevel()==0 then return false end
- digAndThrow(0)
- end
- end
- local function mbd()
- while not turtle.back() do
- if turtle.getFuelLevel()==0 then return false end
- turtle.turnLeft()
- turtle.turnLeft()
- digAndThrow(0)
- turtle.turnLeft()
- turtle.turnLeft()
- end
- return true
- end
- local function mdd()
- while not turtle.down() do
- if turtle.getFuelLevel()==0 then return false end
- digAndThrow(-1)
- end
- end
- local function mud()
- while not turtle.up() do
- if turtle.getFuelLevel()==0 then return false end
- digAndThrow(1)
- end
- end
- local function tpf()
- while not turtle.place() do digAndThrow(0) end
- end
- local function tpu()
- while not turtle.placeUp() do digAndThrow(1) end
- return true
- end
- local function tpd()
- while not turtle.placeDown() do digAndThrow(-1) end
- return true
- end
- local function lookForMore(slotn)
- selt(slotn)
- --print("entry slotn= "..slotn)
- for i=1,16 do
- if i~=slotn and turtle.compareTo(i) then
- --print ("found more in slot "..i.."with "..turtle.getItemCount(i).." items")
- --print("got space for "..turtle.getItemSpace(slotn).." more")
- selt(i)
- turtle.transferTo(slotn,math.min(turtle.getItemCount(i),turtle.getItemSpace(slotn)))
- -- print("slotn="..slotn)
- selt(slotn)
- return true
- end
- end
- return false
- end
- print("Niseg's Mining well script")
- if args[1] ~= nil then slp = tonumber(args[1]) end
- if args[2] ~= nil then lx = tonumber(args[2]) end
- if args[3] ~= nil then ly = tonumber(args[3]) end
- if args[4] ~=nil then pipeItems=true end
- local wellcount=turtle.getItemCount(miningwell)
- if wellcount>=3 then wellcount =3 else wellcount =1 end
- --if not pipeItems then wellcount=1 end
- if turtle.getItemCount(chargestation)>0 then
- print("checking if I have a charge station")
- if not mbd() then print("no fuel");error() end
- selt(chargestation)
- tpf(); sleep(5);
- if(turtle.getFuelLevel()>cf) then hasChargeStation = true end
- turtle.dig()
- mfd()
- end
- for j=1,ly do
- print("starting row " ..j)
- local nf=6*lx +wellcount+3;
- cf=turtle.getFuelLevel()
- print("fuel is at "..cf.. " / "..nf)
- while nf>cf do
- if hasChargeStation then
- mbd()
- selt(chargestation)
- tpf()
- while nf>cf do cf=turtle.getFuelLevel(); sleep(10) end
- turtle.dig()
- mfd()
- else
- print(" I need more fuel")
- for k=1,4 do turtle.turnLeft() end
- shell.run("refuel all")
- sleep(5);
- end
- cf=turtle.getFuelLevel()
- end
- if(pipeItems) then
- selt(chest); tpd()
- mbd();selt(conduit); tpf()
- end
- -- slot=0
- for i=1,lx do
- if wellcount==1 then -- single well
- selt(miningwell)
- tpd()
- mbd()
- if not pipeItems then
- selt(chest)
- tpd()
- end
- if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then break end
- selt(conduit)
- tpf()
- sleep(slp) --don't remember how long
- if not pipeItems then
- selt(chest)
- turtle.digDown()
- end
- mdd()
- selt(miningwell)
- turtle.dig()
- if pipeItems and i<lx then
- if turtle.getItemCount(chest)==1 and not lookForMore(chest) then mud();break end
- selt(chest)
- tpf()
- end
- mud()
- else
- if i==1 then
- --mbd()
- mdd()
- end
- selt(miningwell)
- for k=1,3 do
- turtle.turnLeft()
- tpf()
- end
- mud()
- if pipeItems and turtle.getItemCount(chest)==1 and not lookForMore(chest) then print("not enough pipes");error() end
- selt(chest)
- tpd()
- for k=1,3 do
- if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then print("not enough energy pipes");error() end
- selt(conduit)
- tpf()
- turtle.turnRight()
- end
- mud()
- if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then print("not enough energy pipes");error() end
- selt(conduit)
- tpd()
- sleep(slp) --don't remember how long
- -- time to clean up
- turtle.digDown()
- mdd()
- for k=1,3 do
- turtle.turnLeft()
- turtle.dig()
- end
- selt(chest)
- turtle.digDown()
- mdd()
- selt(miningwell)
- for k=1,3 do
- turtle.dig()
- turtle.turnRight()
- end
- --turtle.turnRight()
- selt(conduit)-- she'll be right
- tpu()
- mbd()
- if pipeItems then
- selt(chest)
- tpf()
- end
- if i==lx then mud() end
- end
- end
- selt(conduit)
- --- retract the conduits
- while turtle.detect() do
- turtle.dig();
- mfd();
- if pipeItems and turtle.detect()then
- selt(chest)
- turtle.digDown()
- selt(conduit)
- end
- end
- turtle.turnLeft()
- for k=1,wellcount do
- mbd()
- --tpd()
- while redstone.getInput("top") do
- selt(conduit)
- sleep(1)
- turtle.suckUp()
- while turtle.detectUp() do sleep(0.5) end
- end
- if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then break end
- if not turtle.compareUp() then tpu() end
- if pipeItems then
- if turtle.getItemCount(chest)==1 and not lookForMore(chest) then break end
- selt(chest)
- tpd()
- selt(conduit)
- end
- end
- turtle.turnRight()
- mbd()
- if turtle.getItemCount(conduit)==1 and not lookForMore(conduit) then break end
- tpf()
- --[[if pipeItems then
- selt(chest)
- tpd()
- selt(conduit)
- end
- --]]
- --[[
- mbd()
- tpf()
- if pipeItems then
- selt(chest)
- tpd()
- selt(conduit)
- end
- --]]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement