Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[===============CONFIGURATION VARIABLES=======]]--
- --define void trash can for mod
- trashcan = "cyclic:trash"
- --define chest for storage
- chest = "minecraft:chest"
- --Low fuel level
- lowFuel = 500
- --Length of edge of square to dig (in blocks)
- edgeLength = 4
- --[[==============================================]]--
- --[[===============MACHINE STATE==================]]--
- --count the number of times the turtle has turned right (used to help turtle face forward
- turnCount = 0
- --count position in column
- columnPosition = 0
- --number of columns the turtle has dug
- columnCount = 0
- --count the the number layers down the turtle has dug
- depthCounter = 0
- --has the turtle hit bedrock?
- foundBedrock = false
- --[[==============================================]]--
- term.clear()
- function printVariables()
- print("Turn count: "..turnCount)
- print("Column count: "..columnCount)
- print("Column position: "..columnPosition)
- print("Layer: "..depthCounter)
- end
- function faceForward()
- for i = 1, 4 - turnCount do
- turtle.turnRight()
- end
- turnCount = 0
- end
- function buildJunkTable() --add all items in turtle's inventory to junk table
- junk_table = {}
- local index = 1
- local data = {}
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- junk_table[index] = turtle.getItemDetail().name
- index = index + 1
- end
- end
- turtle.select(1)
- for i,v in ipairs(junk_table) do
- print (v)
- end
- end
- function confirmReadiness() --look for chest and trashcan
- local chestFound = blockExsists(chest)
- faceForward()
- local trashcanFound = blockExsists(trashcan)
- faceForward()
- if (chestFound and not trashcanFound) then
- print ("Chest found but not trash can, place down trashcan from cyclic mod adjacent to the turtle!")
- return false
- else if (not chestFound and trashcanFound) then
- print("No chest found but trashcan found! Place standard minecraft chest adjacent to turtle")
- return false
- else if (not chestFound and not trashcanFound) then
- print ("Place standard minecraft chest and cyclic mod trashcan adjacent to turtle")
- return false
- else
- print("Chest AND Trashcan found! Ready!")
- return true
- end
- end
- end
- end
- function blockExsists(blockType) --find chest for depositing inventory
- local success, data = turtle.inspect()
- for i = 1, 4 do
- turnCount = i
- success, data = turtle.inspect()
- if (data.name == blockType and i == 0) then
- print("Please do not place chest or trashcan directly in front of turtle!")
- return false
- elseif data.name == blockType then
- return true
- else
- turtle.turnRight()
- end
- end
- return false
- end
- function deposit()
- removeJunk()
- if blockExsists(chest) then
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- else
- print("Chest missing!")
- end
- faceForward()
- end
- function removeJunk()
- if blockExsists(trashcan) then
- for i = 1, 16 do
- turtle.select(i)
- for index, value in pairs(junk_table) do --This whole loop
- if turtle.getItemCount(i) > 0 then --itterates through
- if value == turtle.getItemDetail(i).name then --the values in the junk table
- turtle.drop() --compares them to the item names
- end --in the turtle's inventory and
- else --deletes them if they match
- break
- end
- end
- end
- turtle.select(1)
- else
- print("Trashcan missing!")
- end
- faceForward()
- end
- function digColumn()
- print("Column position BEFORE digging: "..columnPosition)
- for i = columnPosition, edgeLength - 1 do
- columnPostion = i
- if bedrockCheck() then
- print ("Bedrock reached! Returning home!")
- goHome()
- return
- end
- if not turtle.forward() then
- turtle.dig()
- turtle.forward()
- end
- end
- --columnCount = columnCount + 1
- print("Column position AFTER digging: "..columnPosition)
- end
- function orient()
- if columnCount % 2 == 0 then
- turnCount = turnCount + 1
- turtle.turnRight()
- if turtle.detect() then
- turtle.dig()
- turtle.forward()
- turnCount = turnCount + 1
- turtle.turnRight()
- else
- turtle.forward()
- turnCount = turnCount + 1
- turtle.turnRight()
- end
- else
- turnCount = turnCount - 1
- turtle.turnLeft()
- if turtle.detect() then
- turtle.dig()
- turtle.forward()
- turnCount = turnCount - 1
- turtle.turnLeft()
- else
- turtle.forward()
- turnCount = turnCount - 1
- turtle.turnLeft()
- end
- end
- columnCount = columnCount + 1
- end
- function isInvetoryFull()
- for i = 1,16 do
- if turtle.getItemCount(i) == 0 then
- return false
- end
- end
- return true
- end
- function digLayer()
- print("Column count BEFORE digging: "..columnCount)
- for i = columnCount, (edgeLength - 2) do
- digColumn()
- orient()
- print("Column count AFTER digging: "..columnCount)
- end
- digColumn()
- --columnCount = columnCount + 1
- print("Column count AFTER digging: "..columnCount)
- --print ("entering last column orientation")
- --printVariables()
- if columnCount % 2 == 0 then
- turtle.turnRight()
- turnCount = turnCount + 1
- else
- turtle.turnLeft()
- turtle.turnLeft()
- turnCount = turnCount - 2
- for i = 1, edgeLength do
- turtle.forward()
- end
- turtle.forward()
- turtle.turnRight()
- end
- print ("entering movement phase")
- --columnCount = columnCount + 1
- for i = 1, edgeLength do
- turtle.forward()
- end
- turtle.turnRight()
- turnCount = 0
- columnCount = 0
- columnPostion = 0
- --print ("Depth count:" .. depthCounter)
- --
- end
- function goHome()
- local oldTurnCount = turnCount
- for i = 1,depthCounter do
- turtle.up()
- end
- faceForward()
- turtle.turnLeft()
- turnCount = turnCount + 3
- for i=1,columnCount do
- turle.forward()
- end
- turtle.turnLeft()
- turnCount = turnCount - 1
- for i=1,columnPostion do
- turtle.forward()
- end
- faceForward()
- turnCount = oldTurnCount
- end
- function goBack()
- for i = 1, depthCounter do -- return to original layer
- turtle.down()
- end
- --turtle.turnRight()
- --turnCount = turnCount + 1
- if columnCount % 2 ~= 0 then --return to original position if turtle was on an
- for i = 1, columnPosition - 1 do --odd column when it had to return home
- turtle.forward()
- end
- turtle.turnRight()
- turnCount = turnCount + 1
- for i = 1, columnPosition do
- turtle.forward()
- end
- turtle.turnRight()
- turnCount = turnCount + 1
- else --return to original position if turtle was on an
- turtle.turnRight() --even column when it had to return home
- turnCount = turnCount + 1
- for i = 1, columnCount - 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- turnCount = turnCount - 1
- end
- end
- function bedrockCheck()
- local success, front = turtle.inspect()
- local success, below = turtle.inspectDown()
- if (success and front.name == "minecraft:bedrock") then
- foundBedrock = true
- return true
- elseif (success and below.name == "minecraft:bedrock") then
- foundBedrock = true
- return true
- else
- return false
- end
- end
- --[[print("Current fuel level: "..turtle.getFuelLevel().."/"..turtle.getFuelLimit())
- if turtle.getFuelLevel() <= lowFuel then
- print("Please add more fuel")
- end]]--
- if confirmReadiness() then
- buildJunkTable()
- deposit()
- faceForward()
- else
- return
- end
- --print("Variables BEFORE digging:")
- --printVariables()
- digLayer()
- turtle.digDown()
- depthCounter = depthCounter + 1
- turtle.down()
- digLayer()
- goHome()
- goBack()
- --print("Variables AFTER digging:")
- --printVariables()
- --digLayer()
- --[[
- repeat
- digLayer()
- if not turtle.down() then
- turtle.digDown()
- turtle.down()
- end
- depthCounter = depthCounter + 1
- until isInvetoryFull() == true or depthCounter < 4
- goHome()
- deposit()
- goBack()
- --]]
Advertisement
Add Comment
Please, Sign In to add comment