Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function forcemove()
- for i=1,16 do
- if turtle.forward() then
- if facing==0 then pos.x = pos.x+1
- elseif facing==2 then pos.x = pos.x-1
- elseif facing==1 then pos.z = pos.z+1
- elseif facing==3 then pos.z = pos.z-1
- end
- return true
- end
- turtle.dig()
- if i>2 then sleep(0.25) end
- end
- return false
- end
- function forcedown()
- for i=1,16 do
- if turtle.down() then
- pos.y = pos.y-1
- return true
- end
- turtle.digDown()
- if i>2 then sleep(0.25) end
- end
- return false
- end
- function trymove()
- repeat
- until turtle.forward()
- if facing==0 then pos.x = pos.x+1
- elseif facing==2 then pos.x = pos.x-1
- elseif facing==1 then pos.z = pos.z+1
- elseif facing==3 then pos.z = pos.z-1
- end
- end
- function tryup()
- repeat
- until turtle.up()
- pos.y = pos.y+1
- end
- function turnTo(face)
- if (facing-face)%4==1 then
- turtle.turnLeft()
- facing = (facing-1)%4
- end
- while facing ~= face%4 do
- turtle.turnRight()
- facing = (facing+1)%4
- end
- end
- function trydown()
- repeat
- until turtle.down()
- pos.y = pos.y-1
- end
- function moveOver()
- while not turtle.forward() do
- tryup()
- end
- if facing==0 then pos.x = pos.x+1
- elseif facing==2 then pos.x = pos.x-1
- elseif facing==1 then pos.z = pos.z+1
- elseif facing==3 then pos.z = pos.z-1
- end
- while not turtle.detectDown() do
- trydown()
- end
- end
- function fuelToGo(x,y,z, hover)
- return math.abs(x-pos.x)+math.abs(z-pos.z)+math.abs(hover-pos.y)+math.abs(hover-y)
- end
- function dropIf(item)
- local data = turtle.getItemDetail()
- if data then
- if data.name == item then
- turtle.drop()
- end
- end
- end
- function dropFiltered()
- local data = turtle.getItemDetail()
- if data and filterTable then
- for i=1,#filterTable do
- if data.name == filterTable[i] then
- turtle.drop()
- end
- end
- end
- end
- function addFilter(item)
- if item=='c' then item='minecraft:cobblestone'
- elseif item=='d' then item='minecraft:dirt' end
- if filterTable then
- table.insert(filterTable,item)
- else
- filterTable = {item}
- end
- end
- function deleteFilters()
- filterTable = nil
- end
- function printFilter()
- if filterTable then
- for i=1,#filterTable do
- print( filterTable[i] )
- end
- else print( 'No item filter' ) end
- end
- function setBase(xx,yy,zz)
- basepos = {x = 0, y = 0, z = 0}
- basepos.x = xx
- basepos.y = yy
- basepos.z = zz
- end
- function setPos(xx,yy,zz,face)
- pos = {x = 0, y = 0, z = 0}
- pos.x = xx
- pos.y = yy
- pos.z = zz
- facing = face
- end
- --facing: 0=+x 1=+z 2=-x 3=-z
- function goPlace(xx,yy,zz,hover)
- turnTo(0)
- local relx = pos.x-xx
- local rely = pos.y-yy
- local relz = pos.z-zz
- while hover>pos.y do
- tryup()
- end
- while hover<pos.y do
- trydown()
- end
- if relz>0 then
- turnTo(3)
- repeat
- trymove()
- until pos.z==zz
- elseif relz<0 then
- turnTo(1)
- repeat
- trymove()
- until pos.z==zz
- end
- turnTo(0)
- if relx>0 then
- turnTo(2)
- repeat
- trymove()
- until pos.x==xx
- elseif relx<0 then
- turnTo(0)
- repeat
- trymove()
- until pos.x==xx
- end
- turnTo(0)
- while 0>pos.y-yy do
- tryup()
- end
- while 0<pos.y-yy do
- trydown()
- end
- end
- function returnPlace(xx,yy,zz,hover)
- goPlace(xx,hover,pos.z,hover)
- goPlace(xx,yy,zz,hover)
- end
- function setBasePos(xx,yy,zz,face)
- setBase(xx,yy,zz)
- setPos(xx,yy,zz,face)
- end
- function returnBase(hover)
- returnPlace(basepos.x,basepos.y,basepos.z,hover)
- end
- function posx()
- return pos.x
- end
- function posy()
- return pos.y
- end
- function posz()
- return pos.x
- end
- function invFull(from)
- local isfull = true
- for i = from, 16 do
- if turtle.getItemCount(i)==0 then
- isfull = false
- end
- end
- return isfull
- end
- function invSelectAny(from)
- local succ = false
- for i = from,16 do
- if turtle.getItemCount(i)>0 then
- turtle.select(i)
- succ = true
- break
- end
- end
- return succ
- end
- function dropAll(from)
- for i = from,16 do
- turtle.select(i)
- dropFiltered()
- turtle.dropDown()
- end
- return not invSelectAny(from)
- end
- function refuelUntil(slot,fuelneed)
- if slot==1 then print("Request ", math.ceil(fuelneed/80)," coal") end
- turtle.select(slot)
- while turtle.getFuelLevel()<fuelneed do
- turtle.refuel(1)
- end
- end
- function digShaftDown(x,y,z, depth)
- refuelUntil(1,fuelToGo(x,y,z,y)*2+depth*2+2)
- trymove()
- goPlace(x,y,z,y)
- for i=1,depth do
- if not forcedown() then break end
- end
- returnPlace(x,y+1,z,y+1)
- returnBase(y+1)
- repeat
- until dropAll(2)
- end
- function digShaftDown2(x,y,z, depth)
- refuelUntil(1,fuelToGo(x,y,z,y)*2+depth*2+2)
- trymove()
- goPlace(x,y,z,y)
- for i=1,depth do
- if not forcedown() then break end
- turtle.dig()
- end
- returnPlace(x,y+1,z,y+1)
- returnBase(y+1)
- repeat
- until dropAll(2)
- end
- function digShaftDown3(x,y,z, depth)
- refuelUntil(1,fuelToGo(x,y,z,y)*2+depth*2+2)
- trymove()
- goPlace(x,y,z,y)
- for i=1,depth do
- if not forcedown() then break end
- turtle.dig()
- end
- turnTo(2)
- for i=1,y-pos.y do
- turtle.dig()
- tryup()
- end
- returnPlace(x,y+1,z,y+1)
- returnBase(y+1)
- repeat
- until dropAll(2)
- end
- --digShafts(1,10,0,1,10, 60)
- function digShafts(x1,x2,y,z1,z2, depth)
- local xm3 = (x2-x1+1)%3
- for z=z1,z2 do
- for x=x1+1,x2-xm3-1,3 do
- digShaftDown3(x,y,z, depth)
- end
- if xm3==2 then
- digShaftDown2(x2-1,y,z, depth)
- elseif xm3==1 then
- digShaftDown(x2,y,z, depth)
- end
- end
- end
- function cover(x1,x2,z1,z2, gapx, gapz)
- refuelUntil(1,fuelToGo(x1,pos.y,z1,pos.y)*2+(x2-x1)*(z2-z1)*3/gapz)
- local maxy = pos.y
- local odd = true
- trymove()
- goPlace(x1,pos.y,z1,pos.y)
- while not turtle.detectDown() do
- trydown()
- end
- for z=z1+gapz,z2,gapz do
- if odd then
- for x=x1,x2,gapx do
- while pos.x<x do
- moveOver()
- maxy = math.max(maxy,pos.y)
- end
- tryup()
- if not invSelectAny(2) then
- returnBase(maxy+1)
- return false
- end
- turtle.placeDown()
- end
- else
- for x=x2,x1,-gapx do
- while pos.x>x do
- moveOver()
- maxy = math.max(maxy, pos.y)
- end
- tryup()
- if not invSelectAny(2) then
- returnBase(maxy+1)
- return false
- end
- turtle.placeDown()
- end
- end
- turnTo(1)
- while pos.z<z do
- moveOver()
- maxy = math.max(maxy, pos.y)
- end
- if odd then turnTo(2)
- else turnTo(0) end
- odd = not odd
- end
- returnBase(maxy+1)
- end
- function digTunnel(x,y,z,dir ,depth)
- refuelUntil(1,fuelToGo(x,y,z,y)*2+depth*2+2)
- trymove()
- goPlace(x,y,z,pos.y)
- turnTo(dir)
- for i=1,depth do
- if not forcemove() then
- refuelUntil(1,fuelToGo(base.x,base.y,base.z,pos.y)+depth*2+2)
- break
- end
- turtle.digUp()
- end
- turnTo(dir+2)
- for i=1,depth do
- turtle.digDown()
- forcemove()
- end
- returnPlace(x,y,z,y)
- returnBase(basepos.y+1)
- repeat
- until dropAll(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement