Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local a=16;local b=0;local c=420;local d=peripheral.wrap("left")d.open(b)function split(e,f)if f==nil then f="%s"end;local g={}for h in string.gmatch(e,"([^"..f.."]+)")do table.insert(g,h)end;return g end;function parseParams(data)coords={}params=split(data," ")coords[1]=vector.new(params[1],params[2],params[3])coords[2]=vector.new(params[4],params[5],params[6])coords[3]=vector.new(params[7],params[8],params[9])return coords end;function checkFuel()turtle.select(1)if turtle.getFuelLevel()<50 then print("Attempting Refuel...")for i=1,a,1 do turtle.select(i)if turtle.refuel()then return true end end;return false else return true end end;function getOrientation()loc1=vector.new(gps.locate(2,false))if not turtle.forward()then for j=1,6 do if not turtle.forward()then turtle.dig()else break end end end;loc2=vector.new(gps.locate(2,false))heading=loc2-loc1;turtle.down()turtle.down()return heading.x+math.abs(heading.x)*2+heading.z+math.abs(heading.z)*3 end;function turnToFaceHeading(heading,k)if heading>k then for g=1,math.abs(k-heading),1 do turtle.turnLeft()end elseif heading<k then for g=1,math.abs(k-heading),1 do turtle.turnRight()end end end;function setHeadingZ(l,heading)local k=heading;if l<0 then k=2 elseif l>0 then k=4 end;turnToFaceHeading(heading,k)return k end;function setHeadingX(m,heading)local k=heading;if m<0 then k=1 elseif m>0 then k=3 end;turnToFaceHeading(heading,k)return k end;function digAndMove(n)for o=1,n,1 do while turtle.detect()do turtle.dig()end;turtle.forward()checkFuel()end end;function digAndMoveDown(n)for p=1,n,1 do print(p)while turtle.detectDown()do turtle.digDown()end;turtle.down()checkFuel()end end;function digAndMoveUp(n)for p=1,n,1 do while turtle.detectUp()do turtle.digUp()end;turtle.up()checkFuel()end end;function moveTo(coords,heading)local q,r,s=gps.locate()local m,t,l=coords.x-q,coords.y-r,coords.z-s;print(string.format("Distances from start: %d %d %d",m,t,l))heading=setHeadingX(m,heading)digAndMove(math.abs(m))heading=setHeadingZ(l,heading)digAndMove(math.abs(l))if t<0 then digAndMoveDown(math.abs(t))elseif t>0 then digAndMoveUp(math.abs(t))end;return heading end;function calculateFuel(u,v,w)local q,r,s=gps.locate()local m,t,l=u.x-q,u.y-r,u.z-s;local x=v.x+v.y+v.z;local y=(math.abs(m)+math.abs(t)+math.abs(l))*2;local z=x+y;print(string.format("total steps: %d",z))if w=="minecraft:coal"then z=z/80 elseif w=="minecraft:coal_block"then z=z/800 elseif w=="minecraft:charcoal"then z=z/80 else print("INVALID FUEL SOURCE")os.exit(1)end;return math.floor(z)+5 end;d.transmit(c,b,"CLIENT_DEPLOYED")event,side,senderChannel,replyChannel,msg,distance=os.pullEvent("modem_message")data=parseParams(msg)local A=calculateFuel(data[1],data[2],"minecraft:coal")turtle.suckDown(A*2)checkFuel()print(string.format("Extracting %d fuel...",A))turtle.turnRight(1)turtle.suck(1)turtle.turnLeft(1)local B=data[1]local C=moveTo(B,getOrientation())local D=2;turnToFaceHeading(C,D)C=D;DROPPED_ITEMS={"minecraft:stone","minecraft:dirt","minecraft:basalt","minecraft:granite","minecraft:cobblestone","minecraft:sand","minecraft:gravel","minecraft:redstone","minecraft:flint","railcraft:ore_metal","extrautils2:ingredients","minecraft:dye","thaumcraft:nugget","thaumcraft:crystal_essence","thermalfoundation:material","projectred-core:resource_item","thaumcraft:ore_cinnabar","deepresonance:resonating_ore","forestry:apatite","biomesoplenty:loamy_dirt","chisel:marble","chisel:limestone"}function dropItems()print("Purging Inventory...")for i=1,a,1 do local E=turtle.getItemDetail(i)if E~=nil then for F=1,#DROPPED_ITEMS,1 do if E["name"]==DROPPED_ITEMS[F]then print("Dropping - "..E["name"])turtle.select(i)turtle.dropDown()end end end end end;function getEnderIndex()for i=1,a,1 do local E=turtle.getItemDetail(i)if E~=nil then if E["name"]=="enderstorage:ender_storage"then return i end end end;return nil end;function manageInventory()dropItems()index=getEnderIndex()if index~=nil then turtle.select(index)turtle.digUp()turtle.placeUp()end;for i=1,a,1 do local E=turtle.getItemDetail(i)if E~=nil then if E["name"]~="minecraft:coal_block"and E["name"]~="minecraft:coal"and E["name"]~="minecraft:charcoal"then turtle.select(i)turtle.dropUp()end end end;turtle.digUp()end;function detectAndDig()while turtle.detect()do turtle.dig()turtle.digUp()turtle.digDown()end end;function forward()detectAndDig()turtle.forward()end;function leftTurn()turtle.turnLeft()detectAndDig()turtle.forward()turtle.turnLeft()end;function rightTurn()turtle.turnRight()detectAndDig()turtle.forward()turtle.turnRight()end;function dropTier(heading)turtle.turnRight()turtle.turnRight()turtle.digDown()turtle.down()turtle.digDown()turtle.down()turtle.digDown()turtle.down()return flipDirection(heading)end;function flipDirection(heading)return(heading+1)%4+1 end;function turnAround(G,heading)if G%2==1 then if heading==2 or heading==3 then rightTurn()elseif heading==1 or heading==4 then leftTurn()end else if heading==2 or heading==3 then leftTurn()elseif heading==1 or heading==4 then rightTurn()end end;return flipDirection(heading)end;function startQuary(H,I,J,heading)for G=1,I,1 do for K=1,H,1 do for L=1,J-1,1 do if not checkFuel()then print("Turtle is out of fuel, Powering Down...")return end;forward()end;if K~=H then heading=turnAround(G,heading)end;manageInventory()end;if G~=I then heading=dropTier(heading)end end;return heading end;local M=data[2]finishedHeading=startQuary(M.x,M.y,M.z,C)function returnTo(coords,heading)local q,r,s=gps.locate()local m,t,l=coords.x-q,coords.y-r,coords.z-s;print(string.format("Distances from end: %d %d %d",m,t,l))if t<0 then digAndMoveDown(math.abs(t))elseif t>0 then digAndMoveUp(math.abs(t))end;heading=setHeadingX(m,heading)digAndMove(math.abs(m))heading=setHeadingZ(l,heading)digAndMove(math.abs(l))return heading end;endCoords=data[3]returnTo(endCoords,finishedHeading)local N=90;for O=1,N,1 do os.sleep(1)print(string.format("Waiting for brothers %d/%d",O,N))end;d.transmit(c,b,"cum")
Add Comment
Please, Sign In to add comment