Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Minecraft - Turtle - Drill down to bedrock and return to surface
- local protocol = "ZigMiningTurtles"
- -- Check block in front of us against black list of blocks we don't want (dirt, stone)
- function blockValuable(name)
- if name == "minecraft:dirt" then return false
- elseif name == "minecraft:stone" then return false
- elseif name == "minecraft:cobblestone" then return false
- elseif name == "minecraft:gravel" then return false
- elseif name == "minecraft:sand" then return false
- elseif name == "chisel:diorite" then return false
- elseif name == "chisel:andesite" then return false
- elseif name == "chisel:limestone" then return false
- elseif name == "chisel:granite" then return false
- end
- return true
- end
- -- mine block in front of us if it is valuable
- function mineValuableBlock()
- local success, data = turtle.inspect()
- if success then
- if blockValuable(data.name) then
- turtle.dig()
- end
- end
- end
- -- Digs down until we reach bed rock
- function drillDown()
- local depth = 0
- turtle.digDown()
- while turtle.down() do
- depth = depth + 1
- mineValuableBlock()
- turtle.turnRight()
- mineValuableBlock()
- turtle.turnRight()
- mineValuableBlock()
- turtle.turnRight()
- mineValuableBlock()
- turtle.turnRight() -- wasted movement (already checked ore), but this keeps our orientation the same
- turtle.digDown()
- end
- print("drilled down " .. depth .. " blocks")
- -- Sends the turtle back to (1 block below) the start
- for index = 2,depth do
- turtle.up()
- end --for
- -- place "cap" on top of drilled hole using slot
- turtle.select(1)
- turtle.placeDown()
- -- go to original position (above ground level)
- turtle.up()
- end
- -- Assumes there is an Ender chest in slot 2, which we place in front of us and then dump all of our inventory in it
- -- picking up the chest after we are done
- function dumpInventoryInChest()
- print("Dumping inventory into Ender Chest (slot 2)")
- turtle.select(2)
- turtle.place() -- assumes the block in front of us is ok
- turtle.select(1)
- turtle.drop()
- for slot=3, 16 do
- turtle.select(slot)
- turtle.drop()
- end
- turtle.select(2)
- turtle.dig()
- end
- -- Move forward 5 blocks, which efficiently covers a space in drill holes without checking any blocks twice
- function moveToNextDrillLocation()
- print("Moving to next drill location (5 blocks forward)")
- -- try to move forward, there may be something in front of us however, so dig it out
- local i = 0
- while i<5 do
- turtle.dig()
- local success = turtle.forward()
- if success then
- i = i + 1
- turtle.digUp() -- make high enough for players to pass
- else
- turtle.dig()
- end
- end
- end
- function controlServerOnline()
- rednet.open("right")
- local serverID = rednet.lookup(protocol)
- if serverID then
- local msg = serverID, os.getComputerLabel() .. " reporting in at " .. textutils.formatTime(os.time(), false) .. " FL: " .. turtle.getFuelLevel()
- rednet.send(msg, protocol)
- print(msg)
- return true
- else
- print("Failed to find Turtle Mining Server, shutting down.")
- return false
- end
- end
- -- Main script
- while true do
- if not controlServerOnline() then
- return
- end
- if turtle.getFuelLevel() < 2800 then
- print("Fuel level must be at least 2800 (drill down 65 blocks and return)")
- return
- end
- print("Drilling down to bedrock.. ")
- drillDown()
- dumpInventoryInChest()
- moveToNextDrillLocation()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement