Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --delai entre chaque vidage de coffre
- local stepDelay = 3
- --channel de reception d'ordre de minage et channel de reponse
- local minChannel = 10
- local minRespChannel = 11
- --ouverture du modem / reception des ordres
- local modem = peripheral.wrap("right")
- modem.open(minChannel)
- function reportCommander(valid)
- if (valid) then
- print("report OK to Commander")
- modem.transmit(minRespChannel,minChannel,"mining OK")
- else
- print("report KO to Commander")
- modem.transmit(minRespChannel,minChannel,"mining KO")
- end
- end
- function cleanInv()
- print("cleaning inventory...")
- local nbItems = 0
- for i=1,16 do
- turtle.select(i)
- nbItems = nbItems + turtle.getItemCount(i)
- turtle.dropUp()
- end
- return nbItems
- end
- function storeMiner()
- print("storing Miner")
- turtle.select(1)
- turtle.dig()
- end
- function placeMiner()
- print("place Miner")
- turtle.select(1)
- turtle.place()
- sleep(stepDelay)
- end
- function initMining()
- print("[initMining]")
- placeMiner()
- local hasFinishedMining = false
- local hasMined = false
- while not hasFinishedMining do
- if ( cleanInv() > 0 ) then
- --continue mining if there was stuff mined in the last stepDelay
- hasMined = true
- sleep(stepDelay)
- else
- if ( hasMined ) then
- --if no stuff was mined in the last stepDelay and stuff already has been mined before,
- -- then signal end of mining
- hasFinishedMining = true
- end
- end
- end
- storeMiner()
- reportCommander(true)
- end
- function getMessage()
- print("waiting for message...")
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if ( message == "initMining!" ) then
- initMining()
- end
- end
- while true do
- getMessage()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement