Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Title: Advanced Wireless Mining Turtle (TurtleSide)
- Description: Mines a shaft and places ladders.
- Excavates a 3 wide and 16 high passage for mining.
- It knows the pattern to expose all blocks in a chunk.
- and is able to make a walk way for accessing each tunnel.
- It will hopefully do this while taking commands from
- a computer with a wireless modem.
- Author: margeobur (some code is based on default programs
- for things like digging the mineshaft) ]]
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print("Usage: TurtleMining <Monitor Computer's ID> ")
- return
- end
- local monitorID = tonumber( tArgs[1] )
- if monitorID < 0 then
- print("Error: Cannot have negative ID")
- end
- -- ***********************Functions**********************************
- --*******************Monitor Communication*****************
- local function receive()
- while true do
- local sender, message, distance = rednet.receive()
- if sender ~= monitorID then
- rednet.send(sender, "You are not my monitor!")
- end
- if message == "CheckStatus" then
- local Status = getStatus()
- local sStatus = textutils.serialze(Status)
- rednet.send(monitorID, sStatus)
- elseif message == "StopMining" then
- command = 2
- break
- else
- rednet.send(monitorID, "Unknown command")
- end
- end
- return
- end
- local function getStatus()
- local x, y, z = gps.locate(4)
- if not x then
- x, y, z = "Could not locate", "Could not locate", "Could not locate"
- end
- local fuel = turtle.getFuelLevel()
- local inv_room = 0
- for i = 4, 9 do
- inv_room = inv_room + turtle.getItemSpace(i)
- end
- local tStatus = readonlytable { fuel, blocks_mined, stage, inv_room, x, y, z }
- return tStatus
- end
- --*********Digging Mineshaft/Making Mine Room*************
- local function collect()
- blocks_mined = blocks_mined + 1
- for n=1,9 do
- if turtle.getItemCount(n) == 0 then
- return true
- end
- end
- print( "No empty slots left." )
- return false
- end
- local function tryForwards()
- while not turtle.forward() do
- if turtle.dig() then
- if not collect() then
- return false
- end
- else
- -- give sand a chance to fall
- sleep(0.8)
- if turtle.dig() then
- if not collect() then
- return false
- end
- else
- return false
- end
- end
- end
- xPos = xPos + xDir
- zPos = zPos + zDir
- return true
- end
- local function tryDown()
- if not turtle.down() then
- if turtle.digDown() then
- if not collect() then
- return false
- end
- end
- if not turtle.down() then
- return false
- end
- end
- depth = depth - 1
- return true
- end
- local function turnLeft()
- turtle.turnLeft()
- xDir, zDir = -zDir, xDir
- end
- local function turnRight()
- turtle.turnRight()
- xDir, zDir = zDir, -xDir
- end
- local function placeLadders()
- print("place de laddars")
- end
- local function DigShaft()
- stop = false
- depth = 0
- blocks_mined = 0
- xPos,zPos = 0,0
- xDir,zDir = 0,1
- alternate = 0
- stage = "Digging Shaft"
- print("Digging de shaft...")
- while not stop do
- for n = 1,3 do
- for m = 1,2 do
- if not tryForwards() then
- stop = true
- break
- end
- end
- if stop then
- break
- end
- if n < 3 then
- if math.fmod(n + alternate,2) == 0 then
- turnLeft()
- if not tryForwards() then
- stop = true
- break
- end
- turnLeft()
- else
- turnRight()
- if not tryForwards() then
- stop = true
- break
- end
- turnRight()
- end
- end
- end
- if stop then
- break
- end
- if alternate == 0 then
- turnLeft()
- else
- turnRight()
- end
- alternate = 1 - alternate
- if not tryDown() then
- stop = true
- break
- end
- if command == 2 then
- print("Master has told us to stop. Stopping...")
- stop = true
- break
- end
- end
- return
- end
- --*********************Driver Program:*******************************
- print("Welcome to margeobur's Advanced Turtle ")
- print("mining program (turtleside interface) ")
- print()
- rednet.open("right")
- command = 0
- parallel.waitForAll (DigShaft, receive)
Advertisement
Add Comment
Please, Sign In to add comment