Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not turtle then
- printError("Requires a Turtle")
- return
- end
- local function unpackString(s)
- local t = {}
- for i = 1,string.len(s) do
- if string.sub(s, i, i) == "0" then
- table.insert(t," ")
- else table.insert(t,"X") end
- end
- return t
- end
- local function printRecipe(r)
- local fmt = "%s%s%s"
- for y = 1,3 do
- local i = (y-1)*3
- print(fmt:format(r[i+1],r[i+2],r[i+3]))
- end
- end
- local tmp = ""
- local strpat = "^[10][10][10][10][10][10][10][10][10]$"
- local args = {...}
- if #args > 1 then
- printError("Maximum of 1 argument")
- return
- elseif #args == 1 then
- if args[1]:match(strpat) == nil then
- printError("First argument, if supplied, must be a 9-length string of 1s and 0s.")
- return
- end
- tmp = args[1]
- else
- tmp = tostring(settings.get("crafty.recipe",0))
- if tmp:match(strpat) == nil then
- print("Set a recipe using 'set crafty.recipe 111101111'")
- print("Recipe string must be exactly 9 0s or 1s, where 0 represents empty and 1 represents item.")
- print("Default recipe is '111111111'")
- tmp = "111111111"
- end
- end
- shape = unpackString(tmp)
- print("Running crafty mode. Recipe:")
- printRecipe(shape)
- local outputIndex = 16
- local slots = {1,2,3,5,6,7,9,10,11}
- local function nextIndex()
- for i = 1, 9 do
- local s = slots[i]
- if shape[i] == "X" then
- if turtle.getItemCount(s) == 0 then
- turtle.select(s)
- return s
- end
- end
- end
- return -1
- end
- while true do
- if nextIndex() == -1 then
- turtle.select(outputIndex)
- turtle.craft()
- turtle.dropUp()
- else
- turtle.suck(1)
- end
- end
Add Comment
Please, Sign In to add comment