Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CLIENT_PORT = 10
- local SERVER_PORT = 0
- local modem = peripheral.wrap("right")
- modem.open(CLIENT_PORT)
- --name startup on the floppy disk--
- function dig()
- --dig until there is not a block above it--
- --for gravity blocks--
- while turtle.detect() do
- l, data = turtle.inspect()
- l = nil
- if data.name ~= "computercraft:turtle_advanced" and data.name ~= "computercraft:disk_drive" then
- turtle.dig()
- end
- end
- end
- function digUp()
- while turtle.detectUp() do
- l, data = turtle.inspectUp()
- l = nil
- if data.name ~= "computercraft:turtle_advanced" and data.name ~= "computercraft:disk_drive" then
- turtle.digUp()
- end
- end
- end
- function digDown()
- while turtle.detectDown() do
- l, data = turtle.inspectDown()
- l = nil
- if data.name ~= "computercraft:turtle_advanced" and data.name ~= "computercraft:disk_drive" then
- turtle.digDown()
- end
- end
- end
- function move(n)
- for m = 1, n do
- dig()
- turtle.forward()
- checkFuel()
- end
- end
- function moveUp(n)
- for m = 1, n do
- digUp()
- turtle.up()
- checkFuel()
- end
- end
- function moveDown(n)
- for m = 1, n do
- digDown()
- turtle.down()
- checkFuel()
- end
- end
- function getItemIndex(itemName)
- --loops thru all slot and checks if there is the chosen item--
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item ~= nil then
- if item.name == itemName then
- return slot
- end
- end
- end
- end
- function checkFuel()
- if turtle.getFuelLevel() < 100 then
- --make your own fuel up code as it depends on the mods you have--
- end
- return true
- end
- --Ifound this code on the computercraft forums--
- function getOrientation()
- checkFuel()
- local 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
- local loc2 = vector.new(gps.locate(2, false))
- turtle.back()
- local heading = loc2 - loc1
- return ((heading.x + math.abs(heading.x) * 2) + (heading.z + math.abs(heading.z) * 3))
- end
- function turnToFaceHeading(heading, destinationHeading)
- if (heading > destinationHeading) then
- dis = heading - destinationHeading
- for t = 1, dis do
- turtle.turnRight()
- end
- elseif (heading < destinationHeading) then
- dis = destinationHeading - heading
- for t = 1, dis do
- turtle.turnLeft()
- end
- end
- end
- function moveTo(x, y, z, heading, final)
- curtX, curtY, curtZ = gps.locate()
- cortX = math.floor(curtX)
- cyrty = math.floor(curtY)
- curtZ = math.floor(curtZ)
- xDif = x - curtX
- yDif = y - curtY
- zDif = z - curtZ
- if (final) then
- if yDif < 0 then
- yDif = curtY - y
- moveDown(yDif)
- elseif yDif > 0 then
- moveUp(yDif)
- end
- end
- --turn to x heading--
- if xDif < 0 then
- turnToFaceHeading(1, heading)
- heading = 1
- xDif = curtX - x
- elseif xDif > 0 then
- turnToFaceHeading(3, heading)
- heading = 3
- end
- --move to x cords
- move(xDif)
- --turn to z heading--
- if zDif < 0 then
- turnToFaceHeading(2, heading)
- heading = 2
- zDif = curtZ - z
- elseif zDif > 0 then
- turnToFaceHeading(4, heading)
- heading = 4
- end
- --move to z cords--
- if (final) then
- zDif = zDif - 1
- end
- move(zDif)
- --move up of down to y cords--
- if final == false then
- if yDif < 0 then
- yDif = curtY - y
- moveDown(yDif)
- elseif yDif > 0 then
- moveUp(yDif)
- end
- end
- return heading
- end
- --starting code--
- modem.transmit(SERVER_PORT, CLIENT_PORT, "CLIENT_DEPLOYED")
- event, side, senderChannel, replyChannel, msg, distance = os.pullEvent("modem_message")
- checkFuel()
- write("Deploying to ")
- write(msg[1])
- write(" ")
- write(msg[2])
- write(" ")
- print(msg[3])
- finalHeading = moveTo(msg[1], msg[2], msg[3], getOrientation(), false)
- --turn west--
- turnToFaceHeading(1, finalHeading)
- --main code--
- keepItems = {
- "minecraft:gold_ore",
- "minecraft:iron_ore",
- "minecraft:coal",
- "minecraft:nether_gold_ore",
- "minecraft:oak_log",
- "minecraft:oak_sapling",
- "minecraft:spruce_log",
- "minecraft:spruce_sapling",
- "minecraft:birch_log",
- "minecraft:birch_sapling",
- "minecraft:jungle_log",
- "minecraft:jungle_sapling",
- "minecraft:acacia_log",
- "minecraft:acacia_sapling",
- "minecraft:dark_oak_log",
- "minecraft:dark_oak_sapling",
- "minecraft:crimson_stem",
- "minecraft:warped_stem",
- "minecraft:diamond",
- "minecraft:lapis_lazuli",
- "minecraft:redstone",
- "minecraft:emerald",
- "minecraft:ancient_debris",
- "minecraft:glowstone_dust",
- "minecraft:apple",
- "computercraft:turtle_advanced"
- }
- function isDrop(item)
- for k, v in pairs(keepItems) do
- if item == keepItems[k] then
- return false
- end
- end
- return true
- end
- function dropItems()
- for d = 1, 16 do
- data = turtle.getItemDetail(d)
- if (data) then
- if (isDrop(data.name)) then
- turtle.select(d)
- turtle.dropDown()
- end
- end
- end
- end
- function storeItems()
- --make your own store code as it depends on the mods you have--
- end
- function mine(xSize, ySize, zSize)
- turn = true
- down = false
- for y = 1, ySize do
- if (down) then
- digDown()
- checkFuel()
- turtle.down()
- turtle.turnLeft()
- turtle.turnLeft()
- storeItems()
- else
- down = true
- end
- trg = false
- for z = 1, zSize do
- if (trg) then
- checkFuel()
- if (turn) then
- turtle.turnRight()
- dig()
- turtle.forward()
- turtle.turnRight()
- turn = false
- else
- turtle.turnLeft()
- dig()
- turtle.forward()
- turtle.turnLeft()
- turn = true
- end
- dropItems()
- else
- trg = true
- end
- for x = 2, xSize do
- dig()
- checkFuel()
- turtle.forward()
- end
- end
- end
- end
- storeItems()
- mine(msg[4], msg[5], msg[6])
- moveTo(msg[7], msg[8], msg[9], getOrientation(), true)
- sleep(10)
- turtle.dig()
- turtle.forward()
- storeItems()
- local timeOut = 60
- for i = 1, timeOut do
- sleep(1)
- print("Waiting for brothers",i.."/"..timeOut)
- end
- turtle.down()
- modem.transmit(SERVER_PORT, CLIENT_PORT, "done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement