Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ###########################
- -- auto_craft <recipe_number>
- -- version 0.3
- -- http://hevohevo.hatena.com/
- -- ###########################
- -- Turtle position (Side view)
- -- T: crafty turtle, M: chest for materials, P: chest for products
- -- M
- -- T
- -- P
- -- ##########################
- -- config
- MATERIAL_SLOT = 1
- PRODUCT_SLOT = 4
- N_DEFAULT_RECIPE = 1
- -- RECIPE[<number>] = table: <numbers of slots>
- RECIPE = {}
- RECIPE[1] = {1} -- 1x1
- RECIPE[2] = {1,2,5,6} -- 2x2
- RECIPE[3] = {1,2,3,5,6,7,9,10,11} -- 3x3
- RECIPE[4] = {1,2,3,5,7,9,10,11} -- 3x3donut
- -- ##########################
- -- functions
- function dropItems(begin_slot, end_slot)
- print('drop items: slots ',begin_slot,'-',end_slot)
- for i=begin_slot, end_slot do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.select(1)
- end
- function getMaterials()
- turtle.select(MATERIAL_SLOT)
- if turtle.getItemCount(MATERIAL_SLOT) ==0 and turtle.suckUp() then
- print(' Success: suckUp items')
- return true
- else
- print(' Failed: suckUp items')
- return false
- end
- end
- -- distMaterials({1,2,5,6}) -- 2x2
- -- distMaterials({1,2,3,5,7,9,10,11}) -- 3x3donut
- function distMaterials(slots)
- local nTotal = turtle.getItemCount(MATERIAL_SLOT)
- local n = nTotal/(#slots)
- turtle.select(MATERIAL_SLOT)
- for i,v in pairs(slots) do
- turtle.transferTo(v,n)
- end
- end
- function auto_craft()
- while turtle.getItemCount(MATERIAL_SLOT) >0 do
- if turtle.craft(0) == false then break end
- turtle.select(PRODUCT_SLOT)
- turtle.craft()
- turtle.dropDown()
- sleep(0.1)
- end
- end
- -- ###########################
- -- main
- args = {...}
- if args[1] and RECIPE[tonumber(args[1])] then
- slots_pattern = RECIPE[tonumber(args[1])]
- print('Recipe No.',args[1])
- else
- slots_pattern = RECIPE[N_DEFAULT_RECIPE]
- print("Use Default Recipe.")
- end
- dropItems(1,16)
- while getMaterials() do
- distMaterials(slots_pattern)
- auto_craft()
- dropItems(1,4)
- sleep(1)
- end
- dropItems(1,16)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement