Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local slotCoalChest = 16
- local modem = peripheral.wrap("right")
- local idChannel = 10
- local idRespChannel = 11
- local cmdChannel = 12
- local cmdRespChannel = 13
- local myID = os.getComputerID()
- local myLabel = os.getComputerLabel()
- local myType = "chunkLoader"
- modem.open(idChannel)
- modem.open(cmdChannel)
- function placeChest(chestType)
- if chestType == "coal" then
- print(" [INV] Providing Coal chest.")
- slot = slotCoalChest
- else
- return false
- end
- if ( turtle.detect() ) then
- turtle.dig()
- end
- turtle.select(slot)
- return turtle.place()
- end
- function storeChest()
- if chestType == "coal" then
- print(" [INV] Storing Coal chest.")
- slot = slotCoalChest
- else
- return false
- end
- turtle.select(1)
- return turtle.transferTo(slot)
- end
- function refuel()
- local lastLevel = turtle.getFuelLevel()
- if ( lastLevel < 1000 ) then
- print(" [FUEL] ALERT low level : Refuel turtle with 1 stack of coal")
- if ( placeChest("coal") ) then
- turtle.select(1)
- --Wait for a full stack and refuel
- while ( turtle.getItemCount(1) < 64 ) do
- turtle.suck()
- end
- turtle.refuel(64)
- turtle.dig()
- storeChest("sort")
- print(" [FUEL] Level "..lastLevel.." -> "..turtle.getFuelLevel())
- end
- end
- end
- function move(mode)
- if ( mode == 1 ) then
- turtle.select(1)
- turtle.turnRight()
- refuel()
- --get spot loader behind
- turtle.forward()
- turtle.turnLeft()
- turtle.dig()
- --go forward and place the spot loader
- turtle.turnLeft()
- turtle.forward()
- while ( turtle.detect() ) do
- turtle.dig()
- sleep(2)
- end
- turtle.forward()
- turtle.turnRight()
- while ( turtle.detect() ) do
- turtle.dig()
- sleep(2)
- end
- turtle.place()
- return true
- elseif ( mode == 2 ) then
- if( move1() ) then
- sleep(2)
- return move1()
- end
- end
- return false
- end
- while true do
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- local op=textutils.unserialize(message)
- if (op.name == "ID" ) then
- local rep={name="ID", ID=myID, label=myLabel, wType=myType}
- modem.transmit(idRespChannel,idChannel,textutils.serialize(rep))
- elseif (op.name == "mine" ) then
- if ( move(op.mode) ) then
- local rep={name="waiting", ID=myID, label=myLabel, wType=myType}
- modem.transmit(cmdRespChannel,cmdChannel,textutils.serialize(rep))
- end
- else
- print("LE MONSIEUR EST UN BOULET")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement