Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Beginning variables
- currpos = 0
- dir = "forward"
- found = nil
- crafted3 = "derp"
- --end
- function turnaround()
- turtle.turnRight()
- turtle.turnRight()
- end
- function forward()
- if dir == "right" then
- turtle.turnLeft()
- elseif dir == "left" then
- turtle.turnRight()
- elseif dir == "backward" then
- foodstuffs.turnaround()
- end
- end
- function backward()
- if dir == "right" then
- turtle.turnRight()
- elseif dir == "left" then
- turtle.turnLeft()
- elseif dir == "forward" then
- foodstuffs.turnaround()
- end
- end
- function right()
- if dir == "left" then
- foodstuffs.turnaround()
- elseif dir == "forward" then
- turtle.turnRight()
- elseif dir == "backward" then
- turtle.turnLeft()
- end
- end
- function left()
- if dir == "right" then
- foodstuffs.turnaround()
- elseif dir == "forward" then
- turtle.turnLeft()
- elseif dir == "backward" then
- turtle.turnRight()
- end
- end
- function sReturn()
- if pos ~= 0 then
- foodstuffs.backward()
- dir = "backward"
- for i = 1,currpos do
- turtle.forward()
- end
- currpos = 0
- foodstuffs.turnaround()
- dir = "forward"
- end
- end
- function checkFuel()
- refueled = false
- am = 0
- level = turtle.getFuelLevel()
- if 500 >= level then
- term.clear()
- term.write("Refuelling...")
- for i = 1,16 do
- foodstuffs.getFood("Sugar", 1)
- end
- foodstuffs.sReturn()
- sleep(1)
- turtle.back()
- turtle.turnRight()
- turtle.up()
- turtle.forward()
- turtle.select(1)
- turtle.dropDown()
- turtle.back()
- turtle.down()
- turtle.down()
- turtle.forward()
- term.write()("Cooking...")
- while refueled == false do
- turtle.select(1)
- if turtle.getItemCount() == 16 then
- sleep(0.5)
- refueled = true
- end
- end
- turtle.refuel()
- turtle.back()
- turtle.turnLeft()
- turtle.up()
- turtle.forward()
- end
- end
- function getTool( sTool , sSlot )
- handle = assert(fs.open("tools", "r"), "Couldn't load tools")
- input = handle.readAll()
- handle.close()
- tdest = textutils.unserialize(input)
- for k,v in pairs(tdest) do
- if v.name == sTool then
- found = k
- end
- end
- destpos = tdest[found].pos
- movement = destpos - currpos
- if movement >= 0 then
- foodstuffs.forward()
- dir = "forward"
- for i = 1,movement do
- turtle.forward()
- currpos = currpos + 1
- end
- elseif 0 >= movement then
- newmov = movement * -1
- foodstuffs.backward()
- dir = "backward"
- for i = 1,newmov do
- turtle.forward()
- currpos = currpos - 1
- end
- end
- turtle.select( sSlot )
- turtle.suckUp()
- found = nil
- end
- function repTool( sTool , sSlot )
- handle = assert(fs.open("tools", "r"), "Couldn't load tools")
- input = handle.readAll()
- handle.close()
- rdest = textutils.unserialize(input)
- for k,v in pairs(rdest) do
- if v.name == sTool then
- found = k
- end
- end
- destpos = rdest[found].pos
- movement = destpos - currpos
- if movement >= 0 then
- foodstuffs.forward()
- dir = "forward"
- for i = 1,movement do
- turtle.forward()
- currpos = currpos + 1
- end
- elseif 0 >= movement then
- newmov = movement * -1
- foodstuffs.backward()
- dir = "backward"
- for i = 1,newmov do
- turtle.forward()
- currpos = currpos - 1
- end
- end
- turtle.select( sSlot )
- turtle.dropUp()
- found = nil
- end
- function getFood( sFood , sSlot )
- handle = assert(fs.open("foods", "r"), "Couldn't load food list")
- input = handle.readAll()
- handle.close()
- fdest = textutils.unserialize(input)
- for k,v in pairs(fdest) do
- if v.name == sFood then
- found = k
- end
- end
- destpos = fdest[found].pos
- movement = destpos - currpos
- if movement >= 0 then
- foodstuffs.forward()
- dir = "forward"
- for i = 1,movement do
- turtle.forward()
- currpos = currpos + 1
- end
- elseif 0 >= movement then
- newmov = movement * -1
- foodstuffs.backward()
- dir = "backward"
- for i = 1,newmov do
- turtle.forward()
- currpos = currpos - 1
- end
- end
- destdir = fdest[found].dir
- if destdir == "right" then
- foodstuffs.right()
- turtle.select( sSlot )
- turtle.suck(1)
- dir = "right"
- elseif destdir == "left" then
- foodstuffs.left()
- turtle.select( sSlot )
- turtle.suck(1)
- dir = "left"
- elseif destdir == "down" then
- turtle.select( sSlot )
- turtle.suckDown(1)
- end
- found = nil
- end
- function purge()
- foodstuffs.sReturn()
- for i = 1,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- function craft( sFood , sNum)
- for i = 1 , sNum do
- foodstuffs.checkFuel()
- noncon = {}
- recipet = {}
- craftables = {}
- smeltables = {}
- handle = assert(fs.open("recipes", "r"), "Couldn't load recipes")
- output = handle.readAll()
- cdest = textutils.unserialize(output)
- handle.close()
- for k,v in pairs(cdest) do
- if v[1].name == sFood then
- found = k
- end
- end
- recipet = cdest[found]
- print(recipet[1].name)
- for k,v in pairs(recipet) do
- if k ~= 1 then
- if v.type == "craftable" then
- table.insert(craftables, { name = v.name })
- end
- end
- end
- for k,v in pairs(craftables) do
- foodstuffs.craft2( v.name )
- end
- for k,v in pairs(recipet) do
- if k ~= 1 then
- if v.type == "smeltable" then
- table.insert(smeltables, { name = v.name })
- end
- end
- end
- for k,v in pairs(smeltables) do
- foodstuffs.craft2( v.name )
- end
- for i = 1,9 do
- selected = i + 1
- if i == 4 then
- selSlot = 5
- elseif i == 5 then
- selSlot = 6
- elseif i == 6 then
- selSlot =7
- elseif i == 7 then
- selSlot = 9
- elseif i == 8 then
- selSlot = 10
- elseif i == 9 then
- selSlot = 11
- else
- selSlot = i
- end
- if recipet[selected].type == "food" then
- foodstuffs.getFood(recipet[selected].name, selSlot)
- elseif recipet[selected].type == "tool" then
- print(recipet[selected].name)
- foodstuffs.getTool(recipet[selected].name, selSlot)
- table.insert(noncon, { slot = selSlot, name = recipet[selected].name })
- elseif recipet[selected].type == "craftable" then
- foodstuffs.sReturn()
- turtle.turnLeft()
- dir = "left"
- turtle.select(selSlot)
- turtle.suck()
- turtle.turnRight()
- dir = "forward"
- elseif recipet[selected].type == "smeltable" then
- foodstuffs.sReturn()
- turtle.turnLeft()
- dir = "left"
- turtle.select(selSlot)
- turtle.suck()
- turtle.turnRight()
- dir = "forward"
- end
- end
- foodstuffs.sReturn()
- if recipet[1].type == "smeltable" then
- turtle.back()
- turtle.turnRight()
- turtle.up()
- turtle.forward()
- turtle.select(1)
- turtle.dropDown()
- turtle.back()
- turtle.down()
- turtle.down()
- turtle.forward()
- sleep(2.5)
- turtle.suckUp()
- turtle.back()
- turtle.turnLeft()
- turtle.up()
- turtle.forward()
- turtle.dropUp()
- else
- turtle.select(4)
- turtle.craft()
- turtle.dropUp()
- for k,v in pairs(noncon) do
- repTool(v.name, v.slot)
- end
- sReturn()
- end
- foodstuffs.purge()
- end
- end
- function craft2( sFood2 )
- noncon2 = {}
- recipet2 = {}
- craftables2 = {}
- handle2 = assert(fs.open("recipes", "r"), "Couldn't load recipes")
- output2 = handle.readAll()
- cdest2 = textutils.unserialize(output)
- handle.close()
- for k,v in pairs(cdest2) do
- if v[1].name == sFood2 then
- found2 = k
- end
- end
- recipet2 = cdest2[found2]
- print(recipet2[1].name)
- for k,v in pairs(recipet2) do
- if k ~= 1 then
- if v.type == "craftable" then
- table.insert(craftables2, { name = v.name })
- end
- end
- end
- for k,v in pairs(craftables2) do
- foodstuffs.craft3( v.name )
- end
- for i = 1,9 do
- selected2 = i + 1
- if i == 4 then
- selSlot2 = 5
- elseif i == 5 then
- selSlot2 = 6
- elseif i == 6 then
- selSlot2 =7
- elseif i == 7 then
- selSlot2 = 9
- elseif i == 8 then
- selSlot2 = 10
- elseif i == 9 then
- selSlot2 = 11
- else
- selSlot2 = i
- end
- if recipet2[selected2].type == "food" then
- foodstuffs.getFood(recipet2[selected2].name, selSlot2)
- elseif recipet2[selected2].type == "tool" then
- print(recipet2[selected2].name)
- foodstuffs.getTool(recipet2[selected2].name, selSlot2)
- table.insert(noncon2, { slot = selSlot2, name = recipet2[selected2].name })
- elseif recipet2[selected2].type == "craftable" then
- foodstuffs.sReturn()
- turtle.turnRight()
- dir = "right"
- turtle.select(selSlot2)
- turtle.suck()
- turtle.turnLeft()
- dir = "forward"
- elseif recipet2[selected2].type == "smeltable" then
- foodstuffs.sReturn()
- turtle.turnLeft()
- dir = "left"
- turtle.select(selSlot2)
- turtle.suck()
- turtle.turnRight()
- dir = "forward"
- end
- end
- foodstuffs.sReturn()
- if recipet2[1].type == "smeltable" then
- turtle.back()
- turtle.turnRight()
- turtle.up()
- turtle.forward()
- turtle.select(1)
- turtle.dropDown()
- turtle.back()
- turtle.down()
- turtle.down()
- turtle.forward()
- sleep(2.5)
- turtle.suckUp()
- turtle.back()
- turtle.turnLeft()
- turtle.up()
- turtle.forward()
- turtle.turnLeft()
- turtle.drop()
- turtle.turnRight()
- else
- turtle.select(4)
- turtle.craft()
- turtle.turnLeft()
- dir = "left"
- turtle.drop()
- turtle.turnRight()
- dir = "forward"
- for k,v in pairs(noncon2) do
- repTool(v.name, v.slot)
- end
- end
- foodstuffs.purge()
- end
- function craft3( sFood3 )
- noncon3 = {}
- recipet3 = {}
- handle3 = assert(fs.open("recipes", "r"), "Couldn't load recipes")
- output3 = handle.readAll()
- cdest3 = textutils.unserialize(output)
- handle.close()
- for k,v in pairs(cdest3) do
- if v[1].name == sFood3 then
- found3 = k
- end
- end
- recipet3 = cdest3[found3]
- crafted3 = recipet3[1].name
- print(recipet3[1].name)
- for i = 1,9 do
- selected3 = i + 1
- if i == 4 then
- selSlot3 = 5
- elseif i == 5 then
- selSlot3 = 6
- elseif i == 6 then
- selSlot3 =7
- elseif i == 7 then
- selSlot3 = 9
- elseif i == 8 then
- selSlot3 = 10
- elseif i == 9 then
- selSlot3 = 11
- else
- selSlot3 = i
- end
- if recipet3[selected3].type == "food" then
- foodstuffs.getFood(recipet3[selected3].name, selSlot3)
- elseif recipet3[selected3].type == "tool" then
- print(recipet3[selected3].name)
- foodstuffs.getTool(recipet3[selected3].name, selSlot3)
- table.insert(noncon3, { slot = selSlot3, name = recipet3[selected3].name })
- end
- end
- foodstuffs.sReturn()
- if recipet3[1].type == "smeltable" then
- turtle.back()
- turtle.turnRight()
- turtle.up()
- turtle.forward()
- turtle.select(1)
- turtle.dropDown()
- turtle.back()
- turtle.down()
- turtle.down()
- turtle.forward()
- sleep(2.5)
- turtle.suckUp()
- turtle.back()
- turtle.turnLeft()
- turtle.up()
- turtle.forward()
- turtle.turnRight()
- turtle.drop()
- turtle.turnLeft()
- else
- turtle.select(4)
- turtle.craft()
- turtle.turnRight()
- dir = "right"
- turtle.drop()
- turtle.turnLeft()
- dir = "forward"
- for k,v in pairs(noncon3) do
- repTool(v.name, v.slot)
- end
- end
- foodstuffs.purge()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement