Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function chestView(cpId, side)
- fini = false
- if side == nil then
- if not turtle.detectDown() then
- side = 6
- elseif not turtle.detectUp() then
- side = 5
- else
- rednet.send(cpId, "imp")
- return nil
- end
- end
- print(side)
- turtle.select(15)
- if side == 1 then
- turtle.place()
- elseif side == 2 then
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- elseif side == 3 then
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- turtle.turnLeft()
- elseif side == 4 then
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- elseif side == 5 then
- turtle.placeUp()
- else
- turtle.placeDown()
- end
- while not fini do
- turtle.suck()
- if (turtle.getItemCount() == 0) then
- fini = true
- else
- rednet.send(cpId, turtle.getItemDetail().name)
- rednet.send(cpId, turtle.getItemCount())
- if side == 1 then
- turtle.drop()
- elseif side == 2 then
- turtle.turnRight()
- turtle.drop()
- turtle.turnLeft()
- elseif side == 3 then
- turtle.turnRight()
- turtle.turnRight()
- turtle.drop()
- turtle.turnLeft()
- turtle.turnLeft()
- elseif side == 4 then
- turtle.turnLeft()
- turtle.drop()
- turtle.turnRight()
- elseif side == 5 then
- turtle.dropUp()
- else
- turtle.dropDown()
- end
- end
- end
- fini = false
- while not fini do
- if side == 1 then
- turtle.suck()
- elseif side == 2 then
- turtle.turnRight()
- turtle.suck()
- turtle.turnLeft()
- elseif side == 3 then
- turtle.turnRight()
- turtle.turnRight()
- turtle.suck()
- turtle.turnLeft()
- turtle.turnLeft()
- elseif side == 4 then
- turtle.turnLeft()
- turtle.suck()
- turtle.turnRight()
- elseif side == 5 then
- turtle.suckUp()
- else
- turtle.suckDown()
- end
- if (turtle.getItemCount() == 0) then
- fini = true
- else
- turtle.drop()
- end
- end
- if side == 1 then
- turtle.dig()
- elseif side == 2 then
- turtle.turnRight()
- turtle.dig()
- turtle.turnLeft()
- elseif side == 3 then
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnLeft()
- elseif side == 4 then
- turtle.turnLeft()
- turtle.dig()
- turtle.turnRight()
- elseif side == 5 then
- turtle.digUp()
- else
- turtle.digDown()
- end
- end
- local function main()
- rednet.open("left")
- t = turtle
- lastMove = 0
- -- last move:
- -- 0 : nil
- -- 1 : front
- -- 2 : right
- -- 3 : back
- -- 4 : left
- -- 5 : up
- -- 6 : down
- while true do
- cpt, msg, ptc = rednet.receive()
- print("test")
- if (t.getFuelLevel() < 50) then
- t.select(16)
- t.refuel()
- end
- if (msg == 44) then
- t.forward()
- lastMove = 3
- elseif (msg == 31) then
- t.back()
- lastMove = 1
- elseif (msg == 16) then
- t.turnLeft()
- if (lastMove >= 1 and lastMove <= 4) then
- lastMove = ((lastMove - 1) + 1) % 4 + 1
- end
- elseif (msg == 32) then
- t.turnRight()
- if (lastMove >= 1 and lastMove <= 4) then
- lastMove = ((lastMove - 1) - 1) % 4 + 1
- end
- elseif (msg == 30) then
- t.up()
- lastMove = 6
- elseif (msg == 18) then
- t.down()
- lastMove = 5
- elseif (msg >= 2 and msg <= 11) then
- t.select(msg-1)
- t.place()
- elseif (msg == 33) then
- t.dig()
- elseif (msg == 34) then
- t.digDown()
- elseif (msg == 20) then
- t.digUp()
- elseif (msg == 45) then
- t.attack()
- elseif (msg == 71) then
- rednet.send(cpt, "chest")
- chestView(cpt, lastMove)
- rednet.send(cpt, "fini")
- elseif (msg == 72) then
- redstone.setOutput("front", true)
- rednet.send(cpt, yes)
- else
- rednet.send(cpt, "no")
- end
- rednet.send(cpt, t.getFuelLevel())
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement