Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TEST_MODE = true
- STRIP_SIZE = (TEST_MODE and 2 or 10) * 16 -- 10 chunks
- MOVE_LOOKUP = {
- turtle.up,
- function()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- end,
- turtle.forward,
- turtle.back,
- function()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- end,
- turtle.down
- }
- TURTLE_STATUS = {
- mining = true,
- current_ore = nil,
- in_vein = false,
- pos = {x = 0, y = 0, z = 0},
- }
- local function shouldMine(s)
- return s ~= "minecraft:stone" and
- s ~= "minecraft:dirt" and
- s ~= "minecraft:wall_torch" and
- s ~= "minecraft:torch" and
- s ~= "minecraft:andesite" and
- s ~= "minecraft:diorite" and
- s ~= "minecraft:granite" and
- s ~= "minecraft:gravel" and
- s ~= "minecraft:deepslate" and
- s ~= "promenade:asphalt" and
- s ~= "twigs:rhyolite"
- end
- --[[ to grab block name
- local _, d = turtle.inspect()
- local name = d.name
- ]]
- local function moveDir(dir)
- MOVE_LOOKUP[dir]()
- end
- local function lookDir(dir, wasBack)
- if dir == 2 then
- turtle.turnRight()
- elseif dir == 4 or wasBack then
- turtle.turnRight()
- turtle.turnRight()
- elseif dir == 5 then
- turtle.turnLeft()
- end
- end
- local function mineDir(dir)
- if dir == 1 then
- turtle.digUp()
- moveDir(1)
- elseif dir == 2 then
- turtle.turnRight()
- turtle.dig()
- turtle.turnLeft()
- moveDir(2)
- elseif dir == 3 then
- turtle.dig()
- moveDir(3)
- elseif dir == 4 then
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnLeft()
- moveDir(4)
- elseif dir == 5 then
- turtle.turnLeft()
- turtle.dig()
- turtle.turnRight()
- moveDir(5)
- else
- turtle.digDown()
- moveDir(6)
- end
- end
- -- {up, right, front, back, left, down}
- local function touchingOres()
- local ores = {}
- -- up
- local p, d = turtle.inspectUp()
- table.insert(ores, p and d.name or "")
- p, d = turtle.inspect()
- table.insert(ores, 3, p and d.name or "")
- turtle.turnRight()
- p, d = turtle.inspect()
- table.insert(ores, p and d.name or "")
- turtle.turnRight()
- p, d = turtle.inspect()
- table.insert(ores, 4, p and d.name or "")
- turtle.turnRight()
- p, d = turtle.inspect()
- table.insert(ores, 5, p and d.name or "")
- turtle.turnRight()
- p, d = turtle.inspectDown()
- table.insert(ores, p and d.name or "")
- return ores
- end
- local function vein()
- local ores = touchingOres()
- for i, ore in ipairs(ores) do
- if shouldMine(ore) and ore ~= "" then
- print("Mining: " .. ore)
- mineDir(i)
- vein()
- moveDir(7 - i)
- end
- end
- end
- local function returnToInit(dist)
- turtle.turnRight()
- turtle.turnRight()
- print("rotated")
- for _ = 1, dist do
- turtle.forward()
- end
- print("rotated back")
- turtle.turnRight()
- turtle.turnRight()
- end
- local function carveStrip()
- for _ = 1, STRIP_SIZE do
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- end
- returnToInit(STRIP_SIZE)
- end
- local function isFull()
- for i = 16, 1, -1 do
- turtle.select(i)
- if turtle.getItemCount() == 0 then return false end
- end
- return true
- end
- local function checkToVein()
- local ores = touchingOres()
- for i, ore in ipairs(ores) do
- if shouldMine(ore) and ore ~= "" then
- lookDir(i)
- vein()
- if (i ~= 1) then lookDir(7 - i, i == 4) end
- end
- end
- end
- local function mineLoop()
- carveStrip()
- local loc = 0
- while loc <= STRIP_SIZE do
- if (loc % 10 == 0 and isFull()) then
- print("breaking")
- break
- end
- turtle.forward()
- print("Checking for ore at loc = " .. loc)
- checkToVein()
- turtle.down()
- checkToVein()
- turtle.up()
- print("Found all ore at loc = " .. loc .. ", moving...")
- loc = loc + 1
- end
- returnToInit(loc)
- end
- mineLoop()
- -- local function listen()
- -- while true do
- -- local _, msg = rednet.receive("minectrl")
- -- if msg == "stop" then
- -- break
- -- end
- -- end
- -- end
- local function main()
- -- parallel.waitForAny(main, listen)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement