Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- TODO: Implement mineSpiral() and mineExcavate()
- -- TIP: Place Repeater to the left of the turtle, when spiral mining for it to be safe
- -- General config
- local mode = "spiral" -- Has to be either "spiral" or "excavate"
- local modemPos = "right" -- Has to be configured
- -- 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 = 10 -- Max spiral side length
- local safeRadius = 5 -- Spiral side length on start
- local height = 5 -- Multiplied by two -> number of spirals in total
- -- Wireless transmission config
- local posChannel = 12
- local oreStatChannel = 14
- local replyChannel = 0
- -- ===================================
- -- ===================================
- -- 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
- local minedOres = 0
- local warnedPosChannel = false
- local warnedOreStatChannel = false
- -- Wireless networking methods
- local modem = peripheral.wrap(modemPos)
- modem.open(replyChannel)
- function transmitPos()
- if modem.isOpen(posChannel) then
- modem.transmit(posChannel, replyChannel, vector.new(posX, posY, posZ))
- elseif warnedPosChannel == false then
- print("[Warning] posChannel couldn't be opened, check config")
- warnedPosChannel = true
- end
- end
- function transmitOreStat()
- if modem.isOpen(oreStatChannel) then
- modem.transmit(oreStatChannel, replyChannel, minedOres)
- elseif warnedOreStatChannel == false then
- print("[Warning] oreStatChannel couldn't be opened, check config")
- warnedOreStatChannel = true
- end
- end
- -- Statistics methods
- function increaseOreStat()
- minedOres = minedOres + 1
- transmitOreStat()
- end
- -- 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
- transmitPos()
- end
- function moveDown()
- turtle.down()
- posY = posY - 1
- transmitPos()
- 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
- transmitPos()
- 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
- transmitPos()
- 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
- function turnAround()
- turnLeft()
- turnLeft()
- end
- -- Mining methods
- function mineVein()
- if isOreUp() then
- increaseOreStat()
- forceUp()
- mineVein()
- moveDown()
- end
- if isOreDown() then
- increaseOreStat()
- forceDown()
- mineVein()
- moveUp()
- end
- for i=0, 3 do
- if isOre() then
- increaseOreStat()
- forceForward()
- mineVein()
- moveBack()
- end
- turnRight()
- end
- end
- local s = safeRadius + 2;
- function mineSpiralForward()
- while s < radius do
- for i=0, s do
- mineVein()
- forceForward()
- end
- turnLeft()
- for i=0, s do
- mineVein()
- forceForward()
- end
- turnLeft()
- s = s + 3;
- end
- end
- function mineSpiralBackward()
- turnAround()
- while s > (safeRadius + 2) do
- for i=0, s do
- mineVein()
- forceForward()
- end
- turnLeft()
- for i=0, s do
- mineVein()
- forceForward()
- end
- turnLeft()
- s = s - 3;
- end
- turnAround()
- end
- function mineSpiral()
- local h = 0;
- while h < (height * 2) do
- mineSpiralForward()
- forceUp()
- h = h + 1;
- mineSpiralBackward()
- forceUp()
- h = h + 1;
- end
- print("[Note] Done mining! Now coming home...")
- while h > 0 do
- forceDown()
- h = h - 1;
- end
- end
- function mineExcavate()
- -- TODO: To be implemented
- end
- -- Position retrieval methods
- function getPosVector()
- return tostring(vector.new(posX, posY, posZ))
- end
- function getDistanceToStart()
- return tostring(math.sqrt(math.pow(posX, 2) + math.pow(posY, 2) + math.pow(posZ, 2)))
- 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
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement