Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local menu=0
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("===========================")
- print(" Custom Crafting - by fews ")
- print("===========================")
- print("Select Menu")
- print("1. See Recipe")
- print("2. Craft")
- print("3. Exit")
- io.write("Menu : ") local menu=read()
- if tonumber(menu) == 1 then
- term.clear()
- term.setCursorPos(1,1)
- local title = {}
- if fs.exists("recipe/listrecipe/listrecipe") then
- --get list recipe
- local fileObject = fs.open("recipe/listrecipe/listrecipe","r")
- local index=1;
- while true do
- local a = fileObject.readLine()
- if a == nil then
- break
- else
- title[index] = a
- index = index+1
- end
- end
- print("Available Recipe")
- for i=1,index do
- print(title[i])
- end
- else
- print("No Recipe Available")
- end
- print("Press Enter to continue")
- local a = read()
- elseif tonumber(menu) == 2 then
- term.clear()
- term.setCursorPos(1,1)
- print("What you want to craft : ") local title = read()
- print(fs.exists("recipe/"..title))
- local recipe = {}
- local damage = {}
- local itemneeded = {}
- local temp=0
- --read recipe
- if fs.exists("recipe/"..title) then
- local fileObject = fs.open("recipe/"..title, "r")
- for i=1,9 do
- local n = fileObject.readLine()
- recipe[i] = n
- if temp == 0 and recipe[i] ~="nil" then
- temp = temp + 1
- itemneeded[temp] = {}
- itemneeded[temp][1] = recipe[i]
- itemneeded[temp][2] = 1
- elseif recipe[i] ~="nil" then
- local noted = false
- for j=1 ,temp do
- if itemneeded[j][1] == recipe[i] then
- itemneeded[j][2] = itemneeded[j][2] + 1
- noted = true
- end
- end
- if noted == false then
- temp = temp + 1
- itemneeded[temp] = {}
- itemneeded[temp][1] = recipe[i]
- itemneeded[temp][2] = 1
- end
- end
- end
- for i=1,9 do
- local n = fileObject.readLine()
- damage[i] = n
- end
- print("Total "..title.." you want to craft : ") local total = read()
- for i=1,temp do
- itemneeded[i][2] = itemneeded[i][2] * total
- end
- --take material
- turtle.select(1)
- local totalitem = 0
- while true do
- local materialcomplete = false
- if turtle.suckUp() == true then
- totalitem = totalitem+1
- else
- -- move material needed or not
- for i=1,tonumber(totalitem)%16 do
- local neededitem=false
- turtle.select(i)
- for j=1,9 do
- if turtle.getItemDetail().name == recipe[j] and turtle.getItemDetail().damage == tonumber(damage[j]) then
- neededitem=true
- print("needed")
- for k=1,temp do
- if itemneeded[k][1] ~=nil then
- print("item "..itemneeded[k][1] .." need "..itemneeded[k][2])
- if turtle.getItemDetail().name == itemneeded[k][1] then
- local totalmaterial = tonumber(turtle.getItemCount())
- itemneeded[k][2] = itemneeded[k][2] - totalmaterial
- print("item "..itemneeded[k][1] .." need "..itemneeded[k][2])
- if itemneeded[k][2] <= 0 then
- itemneeded[k][1] = nil
- end
- end
- end
- end
- materialcomplete = true
- for k=1, temp do
- if itemneeded[k][1] ~= nil then
- materialcomplete = false
- end
- end
- turtle.dropDown()
- break
- end
- end
- if neededitem == false then
- turtle.drop()
- end
- end
- break
- end
- -- if 16 slot full in turtle
- if totalitem % 16 == 0 then
- -- move material needed or not
- for i=1,16 do
- local neededitem=false
- turtle.select(i)
- for j=1,9 do
- if turtle.getItemDetail().name == recipe[j] and turtle.getItemDetail().damage == tonumber(damage[j]) then
- neededitem=true
- print("needed")
- for k=1,temp do
- if itemneeded[k][1] ~=nil then
- print("item "..itemneeded[k][1] .." need "..itemneeded[k][2])
- if turtle.getItemDetail().name == itemneeded[k][1] then
- local totalmaterial = tonumber(turtle.getItemCount())
- itemneeded[k][2] = itemneeded[k][2] - totalmaterial
- print("item "..itemneeded[k][1] .." need "..itemneeded[k][2])
- if itemneeded[k][2] <= 0 then
- itemneeded[k][1] = nil
- end
- end
- end
- end
- materialcomplete = true
- for k=1, temp do
- if itemneeded[k][1] ~=nil then
- materialcomplete = false
- end
- end
- turtle.dropDown()
- break
- end
- end
- if neededitem == false then
- turtle.drop()
- end
- end
- turtle.select(1)
- if materialcomplete == true then
- print("Completed Needed Material")
- break
- end
- end
- end
- print("total Item : "..totalitem)
- print("Returning Item to Main Chest")
- --return item to main chest
- redstone.setOutput("right",false)
- sleep(1)
- redstone.setOutput("right",true)
- --take needed item
- for i=1,7 do
- local selected = 1
- if i<=3 then
- selected = i*4
- else
- selected = i+9
- end
- turtle.select(selected)
- if turtle.suckDown() == true then
- else
- break
- end
- end
- --crafting
- local craftable = true;
- for i=1,9 do
- if recipe[i] ~= "nil" then
- local craft = i
- if i>3 and i<=6 then
- craft = craft + 1
- elseif i>6 then
- craft = craft + 2
- end
- local foundItem=false
- for j=1,7 do
- local selected = 1
- if j<=3 then
- selected = j*4
- else
- selected = j+9
- end
- turtle.select(selected)
- if turtle.getItemDetail() ~= nil then
- if turtle.getItemDetail().name == recipe[i] and tonumber(turtle.getItemCount()) >= tonumber(total) and turtle.getItemDetail().damage == tonumber(damage[i]) then
- turtle.transferTo(tonumber(craft),tonumber(total))
- foundItem = true
- break
- end
- end
- if j==7 and foundItem == false then
- print("Item "..recipe[i].." Not Enough")
- end
- end
- if foundItem == false then
- craftable=false;
- break;
- end
- end
- end
- -- move item back to storage
- for i=1,7 do
- local selected = 1
- if i<=3 then
- selected = i*4
- else
- selected = i+9
- end
- turtle.select(selected)
- if turtle.getItemDetail() ~= nil then
- turtle.drop()
- end
- end
- --craft
- if craftable == true then
- turtle.craft()
- else
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- else
- print("Recipe not exists")
- end
- print("Press Enter to continue")
- local a = read()
- elseif tonumber(menu) == 3 then
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement