Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mode = "spiral" -- Has to be either "spiral" or "excavate"
- -- Excavate config (starts at the bottom left corner of designated area)
- local depth = 100
- local height = 3;
- local width = 20;
- -- Spiral mining config
- local radius = 30
- -- ===================================
- -- Mapping turtle position along a new x, y, z coordinate system (turtle starts at 0, 0, 0 facing positive x)
- local posX = 0
- local posY = 0
- local posZ = 0
- local facing = 0; -- 0: positive x / 1: positive z / 2: negative x / 3: negative z
- -- Ore inspection methods
- function isOreUp()
- local success, block = turtle.inspectUp()
- if success then
- if string.match(block.name, "ore") or string.match(block.name, "Ore") then
- return true
- end
- end
- end
- function isOreDown()
- local success, block = turtle.inspectDown()
- if success then
- if string.match(block.name, "ore") or string.match(block.name, "Ore") then
- return true
- end
- end
- end
- function isOre()
- local success, block = turtle.inspect()
- if success then
- if string.match(block.name, "ore") or string.match(block.name, "Ore") then
- return true
- end
- end
- end
- -- Movement/mining methods
- function forceUp()
- turtle.digUp()
- moveUp()
- end
- function forceForward()
- turtle.dig()
- moveForward()
- end
- function forceDown()
- turtle.digDown()
- moveDown()
- end
- function moveUp()
- turtle.up()
- posY = posY + 1
- end
- function moveDown()
- turtle.down()
- posY = posY - 1
- end
- function moveForward()
- turtle.forward()
- if facing == 0 then
- posX = posX + 1
- elseif facing == 1 then
- posZ = posZ + 1
- elseif facing == 2 then
- posX = posX - 1
- elseif facing == 3 then
- posZ = posZ - 1
- end
- end
- function moveBack()
- turtle.back()
- if facing == 0 then
- posX = posX - 1
- elseif facing == 1 then
- posZ = posZ - 1
- elseif facing == 2 then
- posX = posX + 1
- elseif facing == 3 then
- posZ = posZ + 1
- end
- end
- function turnRight()
- turtle.turnRight()
- if facing < 3 then
- facing = facing + 1
- else
- facing = 0
- end
- end
- function turnLeft()
- turtle.turnLeft()
- if facing > 0 then
- facing = facing - 1
- else
- facing = 3
- end
- end
- -- Mining methods
- function mineVein()
- if isOreUp() then
- forceUp()
- mineVein()
- turtle.down()
- end
- if isOreDown() then
- forceDown()
- mineVein()
- turtle.up()
- end
- for i=0, 3 do
- if isOre() then
- forceForward()
- mineVein()
- turtle.back()
- end
- turtle.turnRight()
- end
- end
- function mineSpiral()
- end
- -- Position retrieval methods
- function getDistanceToStart()
- return tostring(vector.new(posX, posY, posZ) - vector.new(0, 0, 0))
- end
- -- Main method
- function main()
- print("==== Fredriks Miner v1.0 ====")
- print()
- if mode == "spiral" then
- mineSpiral()
- elseif mode == "excavate" then
- mineExcavate()
- else
- print("[Error] Please set mode to either 'spiral' or 'excavate'")
- end
- end
- print(getDistanceToStart())
- moveForward()
- print(getDistanceToStart())
- moveForward()
- print(getDistanceToStart())
- turnRight()
- print(getDistanceToStart())
- moveForward()
- print(getDistanceToStart())
- moveForward()
- print(getDistanceToStart())
- moveForward()
- print(getDistanceToStart())
- moveUp()
- getDistanceToStart()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement