Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- turtle.refuel()
- blocksToIgnore = {"minecraft:air", "minecraft:dirt", "minecraft:grass", "minecraft:cobblestone", "minecraft:gravel", "minecraft:stone"} -- do not mine these blocks
- blocksToDrop = {"minecraft:dirt", "minecraft:grass", "minecraft:cobblestone", "minecraft:gravel", "minecraft:stone", "minecraft:quarry"} -- add shitty marble
- logOutputFileName = string.format("quarry_log_%s.txt", os.time())
- currentX = 0
- currentY = 0
- currentZ = 0
- currentOrientation = 0
- stringCurrentCordinates = string.format("X: %i, Y: %i, Z: %i, D: %i", currentX, currentY, currentZ, currentOrientation)
- savedX = 0
- savedY = 0
- savedZ = 0
- savedOrientation = 0
- diameter = args[1] - 1
- initialDepth = args[2]
- print([[
- (( /|_/|
- \\.._.' , ,\
- /\ | '.__ v /
- (_ . / "
- ) _)._ _ /
- '.\ \|( / ( mrf
- '' ''\\ \\
- ===== NICECAT QUARRY =====
- ]])
- function putMessage(message, level)
- -- prints message with level and time to stdout and write to logOutputFile
- -- ### add rednet/modem api messaging
- -- edit when fancy logging
- if level == "trace" then
- level = "TRACE"
- elseif level == "info" then
- level = "INFO"
- elseif level == "warning" then
- level = "WARNING"
- elseif level == "error" then
- level = "ERROR"
- elseif level == "fatal" then
- level = "FATAL"
- end
- local formattedMessage = string.format("[%s] [%s] %s", os.time(), level, message)
- print(formattedMessage)
- end
- function checkIfBedrockInFront()
- local forwardBlockSuccess, forwardBlockData = turtle.inspect()
- if forwardBlockData.name == "minecraft:bedrock" then
- foundBedrock = true
- checkIfTurtleShouldReturn()
- end
- end
- function checkIfBedrockBelow()
- local downBlockSuccess, downBlockData = turtle.inspectDown()
- if downBlockData.name == "minecraft:bedrock" then
- foundBedrock = true
- checkIfTurtleShouldReturn()
- end
- end
- function updateOrientation(direction)
- if direction == "left" then
- currentOrientation = currentOrientation - 1
- elseif direction == "right" then
- currentOrientation = currentOrientation + 1
- end
- if currentOrientation == 4 then
- currentOrientation = 0
- elseif currentOrientation == -1 then
- currentOrientation = 3
- else
- putMessage(string.format("Updated orientation [%s] was not in 0-3 range", currentOrientation), "error")
- end
- end
- function turnRight(times)
- -- turn right [times] times
- if type(times) == "nil" then
- times = 1
- end
- for i=1,times do
- turtle.turnRight()
- updateOrientation("right")
- end
- end
- function turnLeft(times)
- -- turn left [times] times
- if type(times) == "nil" then
- times = 1
- end
- for i=1,times do
- turtle.turnLeft()
- updateOrientation("left")
- end
- end
- function forward()
- checkIfBedrockInFront()
- while not turtle.forward() do
- turtle.dig()
- end
- putMessage(string.format("FW L-> X: %i, Y: %i, Z: %i, D: %i", currentX, currentY, currentZ, currentOrientation), "trace")
- end
- function moveForward(blocks)
- -- move one block forward and break blocks that are in the way
- if type(blocks) == "nil" then
- blocks = 1
- end
- for i=1,blocks do
- forward()
- currentZ = currentZ + 1
- end
- end
- function moveRight(blocks, rotateFlag)
- -- move [blocks] right and break blocks that are in the way
- if type(blocks) == "nil" then
- blocks = 1
- end
- if rotateFlag ~= "noRotate" then
- turnRight()
- end
- for i=1,blocks do
- forward()
- currentX = currentX + 1
- end
- if rotateFlag ~= "noRotate" then
- turnLeft()
- end
- end
- function moveRightNoRotate(blocks)
- -- move [blocks] right and do not rotate (only change coords and call forward())
- moveRight(blocks, "noRotate")
- end
- function moveLeft(blocks, rotateFlag)
- -- move [blocks] left and break blocks that are in the way
- if type(blocks) == "nil" then
- blocks = 1
- end
- if rotateFlag ~= "noRotate" then
- turnLeft()
- end
- for i=1,blocks do
- forward()
- currentX = currentX - 1
- end
- if rotateFlag ~= "noRotate" then
- turnRight()
- end
- end
- function moveLeftNoRotate(blocks)
- moveLeft(blocks, "noRotate")
- end
- function moveBack(blocks)
- -- move [blocks] backwards and break blocks that are in the way
- if type(blocks) == "nil" then
- blocks = 1
- end
- if blocks > 0 then -- stops crazy spinning when x = 0
- turnLeft(2)
- end
- for i=1,blocks do
- forward()
- currentZ = currentZ -1
- end
- if blocks > 0 then
- turnRight(2)
- end
- end
- function moveUp(blocks)
- -- move [blocks] up and break blocks that are in the way
- if type(blocks) == "nil" then
- blocks = 1
- end
- for i=1,blocks do
- while not turtle.up() do
- turtle.digUp()
- end
- currentY = currentY - 1
- end
- end
- function moveDown(blocks)
- -- move [blocks] down and break blocks that are in the way
- if type(blocks) == "nil" then
- blocks = 1
- end
- for i=1,blocks do
- checkIfBedrockBelow()
- while not turtle.down() do
- turtle.digDown()
- end
- currentY = currentY + 1
- end
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- function dig()
- while turtle.detect() do
- turtle.digUp()
- end
- end
- function inventoryFull()
- if turtle.getItemCount(16) > 0 then
- return true
- end
- return false
- end
- function depositItems()
- putMessage("Depositing items in left chest", "info")
- dropShitItems()
- turnLeft()
- for slot=1,16 do
- turtle.select(slot)
- turtle.drop()
- end
- turnRight()
- turtle.select(1)
- end
- function saveMiningPosition()
- savedZ = currentZ
- savedY = currentY
- savedX = currentX
- savedOrientation = currentOrientation
- end
- function returnToStart()
- -- moves turtle to the start position
- turnLeft(currentOrientation)
- moveBack(currentZ)
- moveLeft(currentX)
- moveUp(currentY)
- if currentZ == 0 and savedY == 0 and savedX == 0 and savedOrientation == 0 then
- putMessage("nice turtle has reached start location", "info")
- return true
- else
- putMessage("FUCK! turtle was not reach start !!! !111", "fatal")
- return false
- end
- end
- function returnToSavedPosition()
- moveDown(savedY)
- moveRight(savedX)
- moveForward(savedZ)
- turnRight(savedOrientation)
- end
- function hasEnoughFuel()
- -- checks to see if turtle is below fuel limit (fuel to return + 10)
- local fuelNeededToReturn = currentX + currentY + currentZ
- fuelNeededToReturn = fuelNeededToReturn + 10
- if fuelNeededToReturn > turtle.getFuelLevel() then
- putMessage(string.format("Fuel needed to return [%s] is greater than current fuel level [%s]", fuelNeededToReturn, turtle.getFuelLevel()), "warning")
- return false
- else
- return true
- end
- end
- function refuelFromChest()
- putMessage(string.format("Nice turtle is refuel from chesticle, we are %s fuel", turtle.getFuelLevel()), "info")
- turnRight()
- while turtle.suck(16) and turtle.getFuelLevel() < 10000 do
- refuelFromInventory()
- end
- turnLeft()
- end
- function refuelFromInventory()
- for slot=1,16 do
- turtle.select(slot)
- turtle.refuel()
- end
- end
- function checkIfTurtleShouldReturn()
- -- checks inventory space, if full then return turtle to start,
- if not hasEnoughFuel() then
- refuelFromInventory()
- end
- if inventoryFull() then
- refuelFromInventory() -- see if can free up space by using mined coal
- dropShitItems()
- end
- if not hasEnoughFuel() or inventoryFull() or foundBedrock then
- saveMiningPosition()
- returnToStart() -- recover from return to start failure
- depositItems()
- refuelFromChest()
- if not foundBedrock then
- returnToSavedPosition()
- else
- putMessage("Found bedrock, quitting", "info")
- exit()
- end
- end
- end
- function dropShitItems()
- --
- putMessage("Looking for shitty items", "trace")
- for slot=1,16 do
- local slotBlockData = turtle.getItemDetail(slot)
- if slotBlockData ~= nil then
- for key, block in pairs(blocksToDrop) do
- if block == slotBlockData.name then
- putMessage(string.format("Found shitty item (%s), nofear I drop him", block), "info")
- turtle.select(slot)
- turtle.drop()
- end
- end
- end
- end
- turtle.select(1)
- end
- function detectAndDig()
- local upBlockSuccess, upBlockData = turtle.inspectUp()
- local downBlockSuccess, downBlockData = turtle.inspectDown()
- local mineUp = true
- local mineDown = true
- for key, value in pairs(blocksToIgnore) do
- if value == upBlockData.name then
- mineUp = false
- end
- if value == downBlockData.name then
- mineDown = false
- end
- end
- if mineDown then
- turtle.digDown()
- end
- if mineUp then
- turtle.digUp()
- end
- end
- for y=1,100 do
- if currentY > 0 then
- moveDown(3)
- else
- if initialDepth == nil then
- moveDown(2)
- else
- moveDown(initialDepth)
- end
- end
- for z=1,diameter+1 do
- if currentX > 0 then
- xDirection = "left"
- turnLeft()
- else
- xDirection = "right"
- turnRight()
- end
- for x=1,diameter do
- detectAndDig()
- if xDirection == "left" then -- changed this from z to currentX
- moveLeftNoRotate()
- else
- moveRightNoRotate()
- end
- checkIfTurtleShouldReturn()
- putMessage(string.format("iter z=%s, y=%s, x=%s", z, y, x), "trace")
- putMessage(string.format("OUT L -> X: %i, Y: %i, Z: %i, D: %i", currentX, currentY, currentZ, currentOrientation), "trace")
- putMessage(string.format("Fuel: %s", turtle.getFuelLevel()), "trace")
- end
- if xDirection == "left" then
- turnRight()
- else
- turnLeft()
- end
- detectAndDig()
- if currentZ ~= diameter then
- moveForward()
- end
- dropShitItems()
- --moveBack(currentZ)
- end
- moveLeft(currentX)
- moveBack(currentZ)
- --[[
- if currentX == 0 then
- turnRight(2)
- else
- turnLeft(2)
- end
- --]]
- end
- -- messed up with 10: check even numbers
- print("HE IS COMPLETE")
Add Comment
Please, Sign In to add comment