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
- columnPostion = 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 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 = chestExsists()
- faceForward()
- local trashcanFound = trashcanExsists()
- 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 chestExsists() --find chest for depositing inventory
- local success, data = turtle.inspect()
- for i = 0, 3 do
- turnCount = i
- success, data = turtle.inspect()
- if (data.name == chest and i == 0) then
- print("Please do not place chest directly in front of turtle!")
- return false
- elseif data.name == chest then
- return true
- else
- turtle.turnRight()
- end
- end
- return false
- end
- function trashcanExsists() --find trashcan for garbage
- local success, data = turtle.inspect()
- for i = 0, 3 do
- turnCount = i
- success, data = turtle.inspect()
- if (data.name == trashcan and i == 0) then
- print("Please do not place trashcan directly in front of turtle!")
- return false
- elseif data.name == trashcan then
- return true
- else
- turtle.turnRight()
- end
- end
- return false
- end
- function deposit()
- if chestExsists() then
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- else
- print("Chest missing!")
- end
- end
- function removeJunk()
- if trashcanExsists() 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!")
- return
- end
- end
- function digColumn()
- for columnPostion, edgeLength - 1 do
- if not turtle.forward() then
- turtle.dig()
- turtle.forward()
- end
- end
- 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()
- for columnCount, (edgeLength - 1) do
- digColumn()
- orient()
- end
- digColumn()
- turtle.turnRight()
- for i = 1, edgeLength do
- turtle.forward()
- end
- turtle.turnRight()
- turnCount = 0
- columnCount = 0
- columnPostion = 0
- print ("Depth cout:" .. 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
- turnCount = oldTurnCount
- 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
- repeat
- digLayer()
- if not turtle.down() then
- turtle.digDown()
- turtle.down()
- end
- depthCounter = depthCounter + 1
- until isInvetoryFull() == true
- goHome()
Advertisement
Add Comment
Please, Sign In to add comment