Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x, y, z
- local x2, y2, z2
- local rX, rY, rZ
- local xLength, yLength, zLength
- local xRotate, zRotate
- local starting = true
- local label
- local id, message
- local masterID
- local lavaChest = '59d0f619003749793f5cdf5b9159cbed' --frequency 30
- local returnChest = '2cec817d32c1f213778416e4aa71ed14' --frequency 50
- function findItem(type, tag)
- for i=1, 16 do
- local details = turtle.getItemDetail(i)
- if type == 'nbt' then
- if details ~= nil then
- if details.nbt == tag then
- return i
- end
- end
- elseif type == 'name' then
- if details ~= nil then
- if details.name == tag then
- return i
- end
- end
- end
- end
- end
- function fuelCheck()
- local fuel = turtle.getFuelLevel()
- if fuel <= 0 then
- dig('up')
- turtle.select(findItem('nbt', lavaChest))
- turtle.placeUp()
- turtle.suckUp()
- turtle.refuel()
- turtle.select(findItem('name', 'minecraft:bucket'))
- turtle.dropUp()
- dig('up')
- end
- end
- function dig(dir)
- local cantMv, block
- if dir == 'forward' then
- cantMv, block = turtle.inspect()
- elseif dir == 'down' then
- cantMv, block = turtle.inspectDown()
- elseif dir == 'up' then
- cantMv, block = turtle.inspectUp()
- end
- if cantMv == true then
- if block.name ~= 'computercraft:turtle_advanced' then
- if dir == 'forward' then
- turtle.dig()
- elseif dir == 'down' then
- turtle.digDown()
- elseif dir == 'up' then
- turtle.digUp()
- end
- else
- while block.name == 'computercraft:turtle_advanced' do
- if dir == 'forward' then
- cantMv, block = turtle.inspect()
- elseif dir == 'down' then
- cantMv, block = turtle.inspectDown()
- elseif dir == 'up' then
- cantMv, block = turtle.inspectUp()
- end
- sleep(1)
- end
- end
- end
- end
- function mvFor()
- dig('forward')
- fuelCheck()
- turtle.forward()
- end
- function mvDown()
- dig('down')
- fuelCheck()
- turtle.down()
- end
- function mvUp()
- dig('up')
- fuelCheck()
- turtle.up()
- end
- function turnAround()
- turtle.turnRight()
- turtle.turnRight()
- end
- function getHeading()
- local x,y,z = gps.locate()
- mvFor()
- local x2,y2,z2 = gps.locate()
- if x ~= x2 then
- x = x2 - x
- if x == 1 then
- return 1
- elseif x == -1 then
- return 2
- end
- end
- if z ~= z2 then
- z = z2 - z
- if z == 1 then
- return 3
- elseif z == -1 then
- return 4
- end
- end
- -- x = 1
- -- -x = 2
- -- z = 3
- -- -z = 4
- end
- function orient(axis, charge)
- local heading = getHeading()
- if axis == 'x' then
- if charge == 'pos' then
- if heading == 2 then
- turnAround()
- elseif heading == 3 then
- turtle.turnLeft()
- elseif heading == 4 then
- turtle.turnRight()
- end
- else
- if heading == 1 then
- turnAround()
- elseif heading == 3 then
- turtle.turnRight()
- elseif heading == 4 then
- turtle.turnLeft()
- end
- end
- end
- if axis == 'z' then
- if charge == 'pos' then
- if heading == 1 then
- turtle.turnRight()
- elseif heading == 2 then
- turtle.turnLeft()
- elseif heading == 4 then
- turnAround()
- end
- else
- if heading == 1 then
- turtle.turnLeft()
- elseif heading == 2 then
- turtle.turnRight()
- elseif heading == 3 then
- turnAround()
- end
- end
- end
- while y3 ~= 0 do
- if y3 >= 1 then
- mvUp()
- y3 = y3 - 1
- else
- mvDown()
- y3 = y3 + 1
- end
- end
- end
- function moveTo(x2,y2,z2)
- local heading = getHeading()
- local x,y,z = gps.locate()
- local x3,y3,z3
- x3 = x2 - x
- y3 = y2 - y
- z3 = z2 - z
- print(x,y,z)
- print(x2,y2,z2)
- print(x3,y3,z3)
- while x3 ~= 0 do
- if x3 >= 1 then
- if heading == 1 then
- mvFor()
- x3 = x3 - 1
- elseif heading == 2 then
- turnAround()
- heading = 1
- elseif heading == 3 then
- turtle.turnLeft()
- heading = 1
- elseif heading == 4 then
- turtle.turnRight()
- heading = 1
- end
- else
- if heading == 1 then
- turnAround()
- heading = 2
- elseif heading == 2 then
- mvFor()
- x3 = x3 + 1
- elseif heading == 3 then
- turtle.turnRight()
- heading = 2
- elseif heading == 4 then
- turtle.turnLeft()
- heading = 2
- end
- end
- end
- while z3 ~= 0 do
- if z3 >= 1 then
- if heading == 1 then
- turtle.turnRight()
- heading = 3
- elseif heading == 2 then
- turtle.turnLeft()
- heading = 3
- elseif heading == 3 then
- mvFor()
- z3 = z3 - 1
- elseif heading == 4 then
- turnAround()
- heading = 3
- end
- else
- if heading == 1 then
- turtle.turnLeft()
- heading = 4
- elseif heading == 2 then
- turtle.turnRight()
- heading = 4
- elseif heading == 3 then
- turnAround()
- heading = 4
- elseif heading == 4 then
- mvFor()
- z3 = z3 + 1
- end
- end
- end
- while y3 ~= 0 do
- if y3 >= 1 then
- mvUp()
- y3 = y3 - 1
- else
- mvDown()
- y3 = y3 + 1
- end
- end
- end
- function receiveFromMaster(ID)
- while id ~= ID do
- id, message = rednet.receive()
- end
- return message
- end
- function emptyInv()
- local empty
- local count = 0
- for i=1, 16 do
- if turtle.getItemCount(i) >= 1 then
- count = count + 1
- end
- end
- if count == 16 then empty = true end
- if empty == true then
- local details = turtle.getItemDetail(i)
- dig('up')
- turtle.select(findItem('nbt', returnChest))
- turtle.placeUp()
- for i=1, 16 do
- if details.nbt ~= lavaChest or details.nbt ~= returnChest then
- turtle.dropUp()
- end
- end
- dig('up')
- end
- end
- masterID = peripheral.call("back","getID")
- peripheral.find("modem", rednet.open)
- id, label = receiveFromMaster(masterID)
- os.setComputerLabel("lil guy ", tostring(label))
- turtle.turnRight()
- turtle.suck(1)
- turtle.turnLeft()
- mvFor()
- turtle.turnLeft()
- turtle.suck(1)
- rednet.send(masterID, 'ready')
- rX = receiveFromMaster(masterID)
- rY = receiveFromMaster(masterID)
- rZ = receiveFromMaster(masterID)
- rX = tonumber(rX)
- rY = tonumber(rY)
- rZ = tonumber(rZ)
- x2 = receiveFromMaster(masterID)
- y2 = receiveFromMaster(masterID)
- z2 = receiveFromMaster(masterID)
- x2 = tonumber(x2)
- y2 = tonumber(y2)
- z2 = tonumber(z2)
- xLength = receiveFromMaster(masterID)
- yLength = receiveFromMaster(masterID)
- zLength = receiveFromMaster(masterID)
- xLength = tonumber(xLength)
- yLength = tonumber(yLength)
- zLength = tonumber(zLength)
- mvUp()
- mvUp()
- rednet.send(masterID,'next')
- moveTo(x2,y2,z2)
- if xLength >= 1 then
- xRotate = 'pos'
- else
- xRotate = 'neg'
- xLength = xLength * -1
- end
- if zLength >= 1 then
- zRotate = 'pos'
- else
- zRotate = 'neg'
- zLength = zLength * -1
- end
- if yLength >= 1 then
- yLength = yLength - y2
- else
- yLength = yLength + (y2 - 1) * -1
- end
- while yLength ~= 0 do
- if yLength >= 1 then
- local currentX, currentZ = xLength, zLength
- while currentZ ~= 0 do
- mvUp()
- orient('x',xRotate)
- mvBck()
- mvDown()
- while currentX ~= 0 do
- mvFor()
- currentX = currentX - 1
- end
- currentX = xLength
- if xRotate == 'pos' then
- xRotate = 'neg'
- else
- xRotate = 'pos'
- end
- mvUp()
- orient('z',zRotate)
- mvBck()
- mvDown()
- mvFor()
- currentZ = currentZ - 1
- if zRotate == 'pos' then
- zRotate = 'neg'
- else
- zRotate = 'pos'
- end
- end
- mvUp()
- yLength = yLength + 1
- end
- if yLength <= -1 then
- local currentX, currentZ = xLength, zLength
- while currentZ ~= 0 do
- mvUp()
- orient('x',xRotate)
- mvBck()
- mvDown()
- while currentX ~= 0 do
- mvFor()
- emptyInv()
- currentX = currentX - 1
- end
- currentX = xLength
- if xRotate == 'pos' then
- xRotate = 'neg'
- else
- xRotate = 'pos'
- end
- mvUp()
- orient('z',zRotate)
- mvBck()
- mvDown()
- mvFor()
- currentZ = currentZ - 1
- if zRotate == 'pos' then
- zRotate = 'neg'
- else
- zRotate = 'pos'
- end
- end
- mvDown()
- yLength = yLength - 1
- end
- moveTo(rX,rY,rZ)
- rednet.send(masterID,'done')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement