Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local xPos = 0
- local yPos = 0
- local zPos = 0
- local xSize = 0
- local ySize = 0
- local zSize = 0
- local direction = 0
- local status = "Let's goooooooooooooo"
- local fuelTypes = {'minecraft:coal', 'minecraft:charcoal', 'minicoal2:minicoal', 'minicoal2:minicharcoal'}
- local finished = false
- local inventorySlot = 1
- --[[ local rednetOutputChannel = 1
- local rednetInputChannel = 2
- local modem = peripheral.find("modem")
- modem.open(rednetOutputChannel) ]]
- --[[ function rednetOut(message)
- modem.transmit(1, 2, message)
- end ]]
- --[[ function outputData()
- rednetOut({
- "X position: " .. xPos,
- "Y position: " .. yPos,
- "Z position: " .. zPos,
- "Direction : " .. math.fmod(direction, 4),
- "",
- "Fuel level: " .. turtle.getFuelLevel(),
- "",
- "Status : " .. status
- })
- end ]]
- function mine()
- if turtle.detect() then
- turtle.dig()
- turtle.forward()
- else
- turtle.forward()
- end
- end
- function turn(side)
- if side == "right" then
- turtle.turnRight()
- direction = direction + 1
- elseif side == "left" then
- turtle.turnLeft()
- direction = direction - 1
- else
- error("turn() function called incorrectly. parameter: " .. side .. " needs to be either left or right")
- end
- end
- function enoughFuel(distance)
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel > distance then
- return true
- else
- return false
- end
- end
- function refuel(amount)
- local item = turtle.getItemDetail(16)
- for i=1,table.getn(fuelTypes) do
- if item.name == fuelTypes[i] then
- if item.count > amount then
- turtle.refuel(amount)
- status = "Refuelled. " .. item.count - amount .. " " .. item.name .. " left."
- print("Refuelled. "..item.count - amount.." "..item.name.." left.")
- else
- status = "ERROR: only " .. item.count .. " " .. item.name .. " left. Can't refuel " .. amount .. " items."
- print("ERROR: only "..item.count.." "..item.name.." left. Can't refuel "..amount.." items.")
- end
- end
- end
- end
- function faceDirection(dir)
- while direction > dir do
- turn("left")
- end
- while direction < dir do
- turn("right")
- end
- end
- function faceDirectionZero()
- while direction > 0 do
- turn("left")
- end
- while direction < 0 do
- turn("right")
- end
- end
- function returnToBase()
- print("Returning to base")
- while zPos > 0 do
- turtle.up()
- zPos = zPos - 1
- end
- faceDirectionZero()
- if yPos > 0 then
- turn("right")
- while yPos > 0 do
- turtle.forward()
- yPos = yPos - 1
- end
- if xPos > 0 then
- turn("right")
- while xPos > 0 do
- turtle.forward()
- xPos = xPos - 1
- end
- end
- else
- if xPos > 0 then
- turn("right")
- turn("right")
- while xPos > 0 do
- turtle.forward()
- xPos = xPos - 1
- end
- end
- end
- turtle.forward()
- faceDirectionZero()
- end
- function moveToPos(x, y, z, dir)
- print("Moving to pos: ["..x..", "..y..", "..z.."]"..".")
- faceDirectionZero()
- while xPos < x do
- turtle.forward()
- xPos = xPos + 1
- end
- if yPos < y then
- turn("left")
- while yPos < y do
- turtle.forward()
- yPos = yPos + 1
- end
- end
- while zPos < z do
- turtle.down()
- zPos = zPos + 1
- end
- faceDirection(dir)
- end
- function bankItems()
- local success, data = turtle.inspectDown()
- if success and data == 'minecraft:chest' then
- for i=1,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- function miningAction()
- local layer = math.fmod(zPos, 2)
- local row = math.fmod(xPos, 2)
- local column = math.fmod(yPos, 2)
- if zPos >= zSize - 1 and ySize <= 0 and xSize <= 0 then
- status = "Finished " .. xSize .. "x" .. ySize .. "x" .. zSize .. " cube. Returning to base..."
- returnToBase()
- finished = true
- return
- end
- if yPos >= ySize - 1 and xPos <= 0 and layer == 0 then
- turtle.digDown()
- turtle.down()
- turn("left")
- turn("left")
- zPos = zPos + 1
- elseif yPos <= 0 and xPos <= 0 and layer == 1 then
- turtle.digDown()
- turtle.down()
- turn("right")
- turn("right")
- zPos = zPos + 1
- elseif xPos >= xSize - 1 and column == 1 and layer == 1 then
- turn("right")
- mine()
- turn("right")
- yPos = yPos - 1
- elseif xPos <= 0 and column == 0 and layer == 1 then
- turn("left")
- mine()
- turn("left")
- yPos = yPos - 1
- elseif xPos >= xSize - 1 and column == 0 and layer == 0 then
- turn("left")
- mine()
- turn("left")
- yPos = yPos + 1
- elseif xPos <= 0 and column == 1 and layer == 0 then
- turn("right")
- mine()
- turn("right")
- yPos = yPos + 1
- else
- mine()
- if column == 0 then
- if layer == 0 then
- xPos = xPos + 1
- elseif layer == 1 then
- xPos = xPos - 1
- end
- elseif column == 1 then
- if layer == 0 then
- xPos = xPos - 1
- elseif layer == 1 then
- xPos = xPos + 1
- end
- end
- end
- end
- textutils.slowPrint("Starting mining program (Mart)")
- --print("\nMake sure to meet the following requirements: ")
- --print(" - Put down a fuel chest, with the turtle on top of it")
- --print(" - Put down another chest two blocks to the left of the fuel chest")
- --print(" - Make sure the turtle has a littlebit of fuel on slot 16 (bottom right)")
- textutils.slowPrint("\nConfiguring grid size...")
- print("How many blocks should i dig forward?")
- xSize = tonumber(io.read())
- write("\nDigging ")
- write(xSize)
- write(" blocks forward. How many blocks should i dig sideways?\n")
- ySize = tonumber(io.read())
- write("Digging a grid of ")
- write(xSize)
- write("x")
- write(ySize)
- write("\n")
- print("\nHow deep do you want me to dig?")
- zSize = tonumber(io.read())
- write("Ready to dig ")
- write(zSize)
- write(" blocks deep.")
- textutils.slowPrint("\nInitialization complete. Starting program")
- mine()
- turtle.select(inventorySlot)
- while enoughFuel(100) and finished == false do
- if turtle.getItemSpace(16) <= 0 then
- print("Inventory full. Banking items.")
- local mineXPos = xPos
- local mineYPos = yPos
- local mineZPos = zPos
- local mineDirection = direction
- returnToBase()
- bankItems()
- turtle.forward()
- moveToPos(mineXPos, mineYPos, mineZPos, mineDirection)
- print("Resuming mining")
- end
- miningAction()
- --outputData()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement