Created
August 19, 2012 07:15
-
-
Save larzconwell/3393152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- For use with the ComputerCraft Minecraft mod. http://computercraft.info/ | |
-- | |
-- To use, just get a mining turtle then create a script | |
-- do: edit miner | |
-- then write this script(I know, tedious). | |
-- Once finished just do `miner` to start finding diamonds! | |
-- Keeps track of up and down movements | |
downCounter = 0 | |
upCounter = 0 | |
maxLevelSearch = 15 | |
-- Return true if there's a bedrock block under us | |
atBedrock = function(slot) | |
local bedrockItem = turtle.select(slot) | |
if bedrockItem then | |
if turtle.detectDown() then | |
return turtle.compareDown() | |
end | |
end | |
return false | |
end | |
-- Move down, with room for people to walk | |
moveDown = function() | |
turtle.digDown() | |
if turtle.down() then | |
downCounter = downCounter + 1 | |
end | |
turtle.dig() | |
turtle.forward() | |
turtle.dig() | |
end | |
-- Move up in the same fashion built from move down | |
moveUp = function() | |
-- We may need to dig also | |
turtle.back() | |
if turtle.up() then | |
upCounter = upCounter + 1 | |
end | |
end | |
clearInventory = function(count) | |
for i = 1, count do | |
turtle.select(i) | |
turtle.drop() | |
end | |
return true | |
end | |
search = function(width, depth) | |
-- Most bugs have been fixed, but some things are | |
-- still random. Rogue turtles happen a lot so be ready to lose it. | |
-- Counters | |
local movementsCounter = 0 | |
local widthCounter = 0 | |
local searchLevelCounter = 0 | |
-- Dig and move half of the width | |
moveHalfWidth = function() | |
repeat | |
turtle.dig() | |
turtle.forward() | |
movementsCounter = movementsCounter + 1 | |
until movementsCounter >= width/2 | |
movementsCounter = 0 | |
end | |
-- Move to right side from middle, and go up one level | |
nextLevel = function() | |
turtle.turnRight() | |
moveHalfWidth() | |
turtle.digUp() | |
turtle.up() | |
turtle.turnLeft() | |
end | |
-- Moves to the middle from the far left, created by the width level loop | |
moveToMiddleFromLeft = function() | |
turtle.turnRight() | |
moveHalfWidth() | |
-- Do an extra move since the main | |
-- width level loop ends up ready for the next forward depth dig | |
turtle.dig() | |
turtle.forward() | |
turtle.dig() | |
turtle.forward() | |
turtle.turnLeft() | |
end | |
-- Dig forward a depth minus the single block depth used to | |
-- track across width | |
digDepthLevel = function() | |
repeat | |
turtle.dig() | |
turtle.forward() | |
movementsCounter = movementsCounter + 1 | |
until movementsCounter >= depth - 1 | |
movementsCounter = 0 | |
end | |
-- Rotates the turtle to dig depth levels | |
rotate = function(side) | |
if side == "left" then | |
turn = turtle.turnLeft | |
else | |
turn = turtle.turnRight | |
end | |
turn() | |
turtle.dig() | |
turtle.forward() | |
turn() | |
end | |
-- Move to right side to start searching | |
turtle.turnRight() | |
moveHalfWidth() | |
turtle.turnLeft() | |
repeat -- Start level count loop | |
repeat -- Start width level loop | |
-- Dig one depth level forward | |
digDepthLevel() | |
widthCounter = widthCounter + 1 | |
-- Turn around to do reverse width level | |
rotate("left") | |
-- Dig one level reverse | |
digDepthLevel() | |
widthCounter = widthCounter + 1 | |
-- Turn around to do forward width level | |
rotate("right") | |
until widthCounter >= width + 1 | |
-- Move back to middle space | |
moveToMiddleFromLeft() | |
-- If we havent reached max level yet go up to next level | |
searchLevelCounter = searchLevelCounter + 1 | |
if searchLevelCounter < maxLevelSearch then | |
widthCounter = 0 -- Reset | |
nextLevel() | |
end | |
until searchLevelCounter >= maxLevelSearch -- End level count loop | |
return true | |
end | |
init = function() | |
repeat | |
moveDown() | |
until atBedrock(1) | |
print("We're at bedrock. It is " .. downCounter .. " blocks down.") | |
repeat | |
-- Move up 4 levels, to keep away from bedrock holes | |
moveUp() | |
until upCounter >= 4 | |
downCounter = downCounter - 4 | |
upCounter = 0 -- Reset | |
print("Clearing inventory to start searching.") | |
clearInventory(9) -- 9 is the inv cap for -1.33 and 16 is +1.33 | |
print("Now searching.") | |
search(15, 15) | |
-- Do something cool here to get rid of cobblestone and other | |
-- useless blocks, only return with good shit. | |
print("Going back up to surface, " .. downCounter .. " blocks up.") | |
repeat | |
-- This is hard as fuck to figure out, for some reason it's incredibly random | |
moveUp() | |
until upCounter >= downCounter - 1 | |
end | |
init() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment