Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --cA or chest array is a 2d array of strings
- --it correlates to the chests behind the turtle
- --simply add a space and the items name
- --and that item will go in that chest
- --You can also add search terms
- --for finding a specific chest
- --To add more chests:
- --simply add a new array and chests
- --just makes sure they're the same length!
- --Also move the lava to next to the end chest
- local cA = {}
- cA[1] = {}
- cA[2] = {}
- cA[1] = {"cobblestone","dirt","ingot","stone","seed","wood log plank stick"}
- cA[2] = {"ore","beef pork wheat slice fish chicken egg cake","bone flesh gun string","coal","diamond emerald lapis", "junk gravel"}
- --The functions below are vital to the
- --programs function. do not alter them
- --unless you know what youre doing
- function GO(x)
- checkFuel()
- for i=1,x do
- turtle.forward()
- end
- end
- function checkFuel()
- if turtle.getFuelLevel() < 30 then
- turtle.select(16)
- turtle.refuel(3)
- turtle.select(1)
- end
- end
- function TURN(x)
- if x == 3 then
- turtle.turnRight()
- else
- for i=1,x do
- turtle.turnLeft()
- end
- end
- end
- function PLACE(str)
- superBreak = false
- x = 0
- y = 0
- for i=1, #cA,1 do
- for j=1, #cA[1],1 do
- for w in string.gmatch(cA[i][j], "([^".."%s".."]+)") do
- if string.find(str, w) then
- superBreak = true
- x = j
- y = i
- break
- end
- if superBreak then
- break
- end
- end
- if superBreak then
- break
- end
- end
- if superBreak then
- break
- end
- end
- if x == 0 or y == 0 then
- x = #cA[1]
- y = #cA
- end
- TURN(2)
- GO((2*(y-1))+1)
- TURN(1)
- GO((2*(x-1))+1)
- if not turtle.dropDown(64) then
- turtle.dropUp(64)
- end
- TURN(2)
- GO((2*(x-1))+1)
- TURN(3)
- GO((2*(y-1))+1)
- end
- function sortJunk()
- while turtle.suckDown(64) do
- cBlock = turtle.getItemDetail(1)
- PLACE(cBlock.name)
- end
- end
- function getStuff(str, stacks)
- superBreak = false
- x = 0
- y = 0
- for i=1, #cA,1 do
- for j=1, #cA[1],1 do
- for w in string.gmatch(cA[i][j], "([^".."%s".."]+)") do
- if string.find(w, str) then
- superBreak = true
- x = j
- y = i
- break
- end
- end
- end
- if superBreak then
- break
- end
- end
- if x == 0 or y == 0 then
- print("Item not found... \n did you mean junk? \n")
- return
- end
- TURN(2)
- GO((2*(y-1))+1)
- TURN(1)
- GO((2*(x-1))+1)
- if not turtle.suckUp(64) then
- for i=1, stacks, 1 do
- turtle.suckDown(64)
- end
- else
- for i=1, stacks-1, 1 do
- turtle.suckUp(64)
- end
- end
- TURN(2)
- GO((2*(x-1))+1)
- TURN(3)
- GO((2*(y-1))+1)
- for i=1, stacks, 1 do
- turtle.select(i)
- turtle.dropDown(64)
- end
- turtle.select(1)
- end
- function JUNK(stacks)
- for i=1, stacks,1 do
- turtle.suckDown(64)
- end
- TURN(2)
- GO((2* #cA)-1)
- turtle.down()
- for i=1, stacks,1 do
- turtle.select(i)
- turtle.dropDown(64)
- end
- turtle.select(1)
- turtle.up()
- TURN(2)
- GO((2*#cA)-1)
- end
- --Main program logic
- while true do
- print("What would you like to do? \n")
- print("sort? get? trash? \n")
- t = tostring(read())
- if t == "sort" then
- print("Right on it!")
- sortJunk()
- elseif t == "get" then
- print("What would you like? \n")
- b = tostring(read())
- print("and how many stacks? \n")
- s = tonumber(read())
- getStuff(b,s)
- elseif t == "junk" or t == "trash" then
- print("How many stacks? \n")
- s = tonumber(read())
- JUNK(s)
- else
- print("Unsupported Function")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement