Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local blackList = {} -- blacklisted items get thrown out with the checkInv function
- local gps = {0, 0, 0, 0} --{X coord, Y coord, Z coord, rotation of turtle} all relative to starting position
- -- Gets all of the items in a table
- local function id()
- local tbl = {}
- for i=1,16 do
- tbl[i] = turtle.getItemDetail(i)
- end
- return tbl
- end
- -- this function will return a table with all of the details in all slots you can get a data of specific slot like this:
- --local slot = someslot
- --local item = itemDetail()
- --print(item[slot])
- local function frwd()
- while not turtle.forward() do
- turtle.dig()
- end
- end
- local function mine() -- Mines in a straight line / above and updates local GPS
- turtle.digUp()
- if gps[4] == 0 then
- gps[3] = gps[3] + 1
- else
- gps[3] = gps[3] - 1
- end
- frwd()
- end
- local function newX() -- changes rows for X coord
- turtle.digUp()
- if gps[4] == 0 then
- turtle.turnRight()
- frwd()
- turtle.turnRight()
- gps[4] = gps[4] + 180
- print("NewX, R: "..gps[4].." (back)")
- elseif gps[4] == 180 then
- turtle.turnLeft()
- frwd()
- turtle.turnLeft()
- gps[4] = 0
- print("NewX, R: "..gps[4].." (front)")
- end
- gps[1] = gps[1] + 1
- print("X: "..gps[1]..", Z: "..gps[3])
- end
- local function screenInv() -- checks inventory for blacklisted items and drops them
- local data = id()
- for i = 1, 16 do
- if data[i] and data[i].name == blacklist then
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- local function resetPos() -- goes back to starting position. Does not change GPS
- for i = 1, gps[2] do
- while not turtle.down() do
- turtle.digDown()
- end
- end
- if gps[4] == 0 then
- for i = 1, gps[3] do
- turtle.back()
- end
- turtle.turnLeft()
- for i = 1, gps[1] do
- frwd()
- end
- turtle.turnRight()
- elseif gps[4] == 180 then
- for i = 1, gps[3] do
- frwd()
- end
- turtle.turnRight()
- for i = 1, gps[1] do
- frwd()
- end
- turtle.turnRight()
- else
- print("Error: rotation = "..gps[4])
- end
- end
- local function newY() -- goes up 2 blocks and changes rotation / Y value
- resetPos()
- gps[2] = gps[2] + 2
- for h = 1, gps[2] do
- turtle.digUp()
- turtle.up()
- end
- -- turtle.turnLeft()
- -- turtle.turnLeft()
- -- gps[4] = gps[4] + 180
- if gps[4] >= 360 then
- gps[4] = gps[4] - 360
- end
- gps[1] = 0
- gps[3] = 0
- gps[4] = 0
- print("NewY, R: "..gps[4].." Y: "..gps[2])
- end
- local function resume() -- goes back to position before calling resetPos() function to resume mining
- if gps[4] == 0 then
- for i = 1, gps[3] do
- frwd()
- end
- turtle.turnRight()
- for i = 1, gps[1] do
- frwd()
- end
- turtle.turnLeft()
- elseif gps[4] == 180 then
- for i = 1, gps[3] do
- frwd()
- end
- turtle.turnRight()
- for i = 1, gps[1] do
- frwd()
- end
- turtle.turnRight()
- else
- print("Error: rotation = "..gps[4])
- end
- for i = 1, gps[2] do
- turtle.up()
- end
- end
- local function dump() --dumps inv
- for i = 2, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- local function invFull() -- if the inventory is full (if there is a block is slot 16), go dump the inventory in the dump chest except for slot 1 which has fuel, then return to the previous position to work again
- turtle.select(16)
- local stack = turtle.getItemCount()
- print("Count in 16: "..stack)
- if stack ~= 0 then
- print("Dumping inventory..")
- resetPos()
- dump()
- print("resuming")
- resume()
- end
- turtle.select(1)
- end
- local function refuel() -- checks if fuel is below 5000. True = goes to slot 1 and refuels. If no fuel, spits out an error and goes to get more
- if turtle.getFuelLevel() < 5000 then
- turtle.select(1)
- turtle.refuel(10)
- end
- end
- --Main functions:
- -- mine
- -- invFull
- -- screenInv
- -- newX
- -- newY
- -- refuel
- --Sub functions
- -- resume
- -- resetPos
- --Main code:
- for y = 1, tArgs[2] / 2 do
- refuel()
- for x = 1, tArgs[1] do
- for u = 1, tArgs[3] do
- mine()
- end
- --screenInv()
- newX()
- invFull()
- end
- if y ~= tArgs[2] / 2 then
- newY()
- end
- end
- resetPos()
- dump()
Add Comment
Please, Sign In to add comment