Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Front chest is the chest where turtle retrieves crafting ingredients from.
- -- Top chest is the chest where turtle puts final product.
- -- Bottom chest is the chest where turtle dumps unrelated items.
- local UNMATCHED = -1
- local EMPTY = 0
- local INSUFFICIENT = 1
- local MATCHED = 2
- local string_recipe = {
- {
- name="immersiveengineering:hemp_fiber",
- count=64
- },
- {
- name="immersiveengineering:hemp_fiber",
- count=64
- },
- {
- name="immersiveengineering:hemp_fiber",
- count=64
- },
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- nil,
- }
- function compare_item_detail(src_item_detail, dst_item_detail)
- if dst_item_detail == nil then
- if src_item_detail ~= nil then
- return UNMATCHED
- end
- return MATCHED
- end
- if src_item_detail == nil then
- return EMPTY
- elseif src_item_detail.name == dst_item_detail.name then
- if src_item_detail.count < dst_item_detail.count then
- return INSUFFICIENT
- end
- return MATCHED
- end
- return UNMATCHED
- end
- function do_nothing()
- end
- function dump_unrelated_item(slot)
- turtle.select(slot)
- turtle.dropDown()
- end
- function suck_more_item(slot, count)
- turtle.select(slot)
- turtle.suck(count)
- end
- function is_ready_to_craft(recipe, on_unmatched_func, on_insufficient_func)
- local is_ready = true
- for slot=1,16 do
- turtle.select(slot)
- local item_detail = turtle.getItemDetail()
- local comparison = compare_item_detail(item_detail, recipe[slot])
- if comparison == UNMATCHED then
- is_ready = false
- on_unmatched_func(slot)
- elseif comparison == EMPTY then
- is_ready = false
- local missing_count = recipe[slot].count
- on_insufficient_func(slot, missing_count)
- elseif comparison == INSUFFICIENT then
- is_ready = false
- local missing_count = recipe[slot].count - item_detail.count
- on_insufficient_func(slot, missing_count)
- end
- end
- return is_ready
- end
- function main()
- while true do
- if is_ready_to_craft(string_recipe, dump_unrelated_item, suck_more_item) then
- turtle.craft()
- turtle.dropUp()
- end
- os.sleep(1)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement