Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Utility functions --
- function sign(x)
- if x > 0 then
- return 1
- elseif x < 0 then
- return -1
- else
- return 0
- end
- end
- function containsValue (tab, val)
- for index, value in ipairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- -- Safe Movement Methods --
- function forward()
- while t.detect() do t.dig() end
- while not t.forward() do t.attack() end
- if w == 0 then
- x = x + 1 -- 0 is +x (east)
- elseif w == 1 then
- z = z + 1 -- 1 is +z (south)
- elseif w == 2 then
- x = x - 1 -- 2 is -x (west)
- elseif w == 3 then
- z = z - 1 -- 3 is -z (north)
- end
- end
- function back()
- while not t.back() do t.attack() end
- if w == 0 then
- x = x - 1 -- 0 is +x (east)
- elseif w == 1 then
- z = z - 1 -- 1 is +z (south)
- elseif w == 2 then
- x = x + 1 -- 2 is -x (west)
- elseif w == 3 then
- z = z + 1 -- 3 is -z (north)
- end
- end
- function up()
- while t.detectUp() do t.digUp() end
- z = z + 1
- while not t.up() do t.attackUp() end
- updateSave()
- end
- function down()
- while t.detectDown() do t.digDown() end
- z = z - 1
- while not t.down() do t.attackDown() end
- updateSave()
- end
- function turnLeft()
- t.turnLeft()
- w = (w-1) % 4
- end
- function turnRight()
- t.turnRight()
- w = (w+1) % 4
- end
- function turnTo(a)
- if a == (w-1) % 4 then
- turnLeft()
- else
- while w ~= a do
- turnRight()
- end
- end
- end
- function goTo(a, b, c)
- -- Y
- while y < b do up() end
- while y > b do down() end
- -- X
- if a > x then
- turnTo(0)
- while a > x do forward() end
- elseif a < x then
- turnTo(2)
- while a < x do forward() end
- end
- -- Z
- if c > z then
- turnTo(1)
- while c > z do forward() end
- elseif c < z then
- turnTo(3)
- while c < z do forward() end
- end
- end
- function selfOrient()
- a, c, b = gps.locate()
- forward()
- x, y, z = gps.locate()
- a = x - a
- b = z - b
- print(a,b)
- if a == 1 then
- w = 0 -- 0 is +x (east)
- elseif b == 1 then
- w = 1 -- 1 is +z (south)
- elseif a == -1 then
- w = 2 -- 2 is -x (west)
- else
- w = 3 -- 3 is -z (north)
- end
- back()
- x, y, z = gps.locate()
- print(string.format("Location:%s, %s, %s, %s", x, y, z, w))
- end
- -- Inventory Functions
- function findInInven(ID)
- data = t.getItemDetail()
- if data then
- if data.name == ID then
- return true
- end
- end
- for i = 1,16 do
- t.select(i)
- data = t.getItemDetail()
- if data then
- if data.name == ID then
- return true
- end
- end
- end
- return false
- end
- function checkFuel()
- if t.getFuelLevel() < 200 * 2.5 then
- findInInven("minecraft:coal")
- end
- end
- -- Mining Operation Functions --
- function branch(s)
- for i = 1,s do -- Go down along the bottom, placing floor blocks as needed
- forward()
- checkSurround()
- if not t.detectDown() then
- if findInInven("minecraft:cobblestone") then
- t.placeDown()
- end
- if findInInven("minecraft:stone") then
- t.placeDown()
- end
- end
- end
- up(); turnLeft(); turnLeft() -- Turn around at the end
- for i = s,2,-1 do -- Come back along the top, placing torches every 10 blocks
- if i%10 == 0 then
- if findInInven("minecraft:torch") then
- t.placeDown()
- end
- end
- forward()
- checkSurround()
- end
- down(); forward();
- end
- function checkSurround() -- This is recursive and will recursivly mine any ore veins that it detects
- for i = 1,4 do
- checkForward()
- turnLeft()
- end
- checkUp()
- checkDown()
- end
- function checkUp()
- success, data = t.inspectUp()
- if success and not containsValue(unwantedBlocks, data.name) then
- s = string.format("%s:%s:%s", x, y+1, z)
- table.insert(flaggedBlocks, s)
- up()
- checkSurround()
- down()
- end
- end
- function checkDown()
- success, data = t.inspectDown()
- if success and not containsValue(unwantedBlocks, data.name) then
- s = string.format("%s:%s:%s", x, y-1, z)
- table.insert(flaggedBlocks, s)
- down()
- checkSurround()
- up()
- end
- end
- function checkForward()
- success, data = t.inspect()
- if success and not containsValue(unwantedBlocks, data.name) then
- if w == 0 then
- s = string.format("%s:%s:%s", x+1, y, z) -- 0 is +x (east)
- elseif w == 1 then
- s = string.format("%s:%s:%s", x, y, z+1) -- 1 is +z (south)
- elseif w == 2 then
- s = string.format("%s:%s:%s", x-1, y, z) -- 2 is -x (west)
- elseif w == 3 then
- s = string.format("%s:%s:%s", x, y, z-1) -- 3 is -z (north)
- end
- table.insert(flaggedBlocks, s)
- forward()
- checkSurround()
- back()
- end
- end
- -- Savefile Funcitons --
- function updateSave()
- end
- -- Main Loop
- t = turtle
- unwantedBlocks = {"minecraft:dirt", "minecraft:grass" , "minecraft:stone", "minecraft:cobblestone", "minecraft:sand", "minecraft:gravel", "minecraft:mossy_cobblestone", "minecraft:bedrock", "minecraft:netherrack", "minecraft:soul_sand", "minecraft:torch"}
- fuels = {"minecraft:coal", "minecraft:coal_block", "minecraft:lava_bucket"}
- flaggedBlocks = {}
- x, y, z, w = 0, 0, 0, 0
- selfOrient()
- home = {x, y, z}
- homeDirection = w
- completeBranches = 0
- while true do
- for i = 1,3 do
- forward()
- while t.detectUp() do t.digUp() end
- if not t.detectDown() then
- if findInInven("minecraft:cobblestone") then
- t.placeDown()
- end
- if findInInven("minecraft:stone") then
- t.placeDown()
- end
- end
- end
- turnLeft()
- branch(10)
- completeBranches = completeBranches + 1
- branch(10)
- completeBranches = completeBranches + 1
- turnRight()
- end
Add Comment
Please, Sign In to add comment