Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- interface in the front in blocking mode
- inventory that goes to injectors on the bottom
- inventory that goes to crafting core on the top
- program recipes and done
- (you dont have to use the dummy item)
- --]]
- local dummy = "minecraft:cobblestone"
- local recipes = {
- -- draconic
- -- awakend draconium
- {
- ingredients = {
- {"draconicevolution:draconic_core", 6}, {"draconicevolution:draconium_block", 4}, {"draconicevolution:dragon_heart", 1}
- },
- core = {"draconicevolution:draconium_block", 4},
- result = {"draconicevolution:draconic_block", 4}
- },
- -- awakend core
- {
- ingredients = {
- {"minecraft:nether_star", 1}, {"draconicevolution:wyvern_core", 4}, {"draconicevolution:draconic_ingot", 5}
- },
- core = {"minecraft:nether_star", 1},
- result = {"draconicevolution:awakened_core", 1}
- },
- -- chaotic core
- {
- ingredients = {
- {"draconicevolution:chaos_shard", 1}, {"draconicevolution:awakened_core", 4}, {"draconicevolution:draconic_ingot", 4}
- },
- core = {"draconicevolution:chaos_shard", 1},
- result = {"draconicevolution:chaotic_core", 1}
- },
- -- projecte
- -- collectors
- {
- ingredients = {
- {"minecraft:glass", 1}, {"minecraft:diamond_block", 1}, {"minecraft:glowstone", 6}, {"minecraft:furnace", 1}
- },
- core = {"minecraft:furnace", 1},
- result = {"projecte:collector_mk1", 1}
- },
- {
- ingredients = {
- {"projecte:item.pe_matter", 1}, {"minecraft:glowstone", 7}, {"projecte:collector_mk1", 1}
- },
- core = {"projecte:collector_mk1", 1},
- result = {"projecte:collector_mk2", 1}
- },
- {
- ingredients = {
- {"projecte:item.pe_matter", 1}, {"minecraft:glowstone", 7}, {"projecte:collector_mk2", 1}
- },
- core = {"projecte:collector_mk2", 1},
- result = {"projecte:collector_mk3", 1}
- },
- -- relayes
- {
- ingredients = {
- {"minecraft:glass", 1}, {"minecraft:diamond_block", 1}, {"minecraft:obsidian", 6}, {"minecraft:furnace", 1}
- },
- core = {"minecraft:furnace", 1},
- result = {"projecte:relay_mk1", 1}
- },
- {
- ingredients = {
- {"projecte:item.pe_matter", 1}, {"minecraft:obsidian", 7}, {"projecte:relay_mk1", 1}
- },
- core = {"projecte:relay_mk1", 1},
- result = {"projecte:relay_mk2", 1}
- },
- {
- ingredients = {
- {"projecte:item.pe_matter", 1}, {"minecraft:obsidian", 7}, {"projecte:relay_mk2", 1}
- },
- core = {"projecte:relay_mk2", 1},
- result = {"projecte:relay_mk3", 1}
- },
- -- energy condenser
- {
- ingredients = {
- {"projecte:item.pe_matter", 4}, {"projecte:item.pe_matter", 4}, {"ironchest:iron_chest", 1}, {"ironchest:iron_chest", 1}, {"projecte:alchemical_chest", 1}
- },
- core = {"projecte:alchemical_chest", 1},
- result = {"projecte:condenser_mk1", 1}
- }
- }
- -----------------------------------------
- -- sort recipes
- for i = 1, #recipes do
- table.sort(recipes[i]["ingredients"], function (a, b)
- return a[1] < b[1]
- end)
- end
- -- check if inventory is the same as recipe ingredients
- local function is_equal (a, b)
- if #a ~= #b then
- return false
- end
- for i = 1, #a do
- if a[i][1] ~= b[i][1] or a[i][2] ~= b[i][2] then
- return false
- end
- end
- return true
- end
- -- run all the time
- while true do
- local using_dummy = false
- -- get items in inventory without dummy
- local inv = {}
- for i=1,16 do
- local slot = turtle.getItemDetail(i)
- if not slot then
- break
- end
- if slot.name ~= dummy then
- table.insert(inv, {slot.name, slot.count})
- else
- using_dummy = true
- end
- end
- if #inv > 0 then
- -- sort inventory for checking
- table.sort(inv, function (a, b)
- return a[1] < b[1]
- end)
- local to_craft = {}
- -- check for valid recipe
- for i = 1, #recipes do
- if is_equal(recipes[i]["ingredients"], inv) then
- to_craft = recipes[i]
- break
- end
- end
- if to_craft["ingredients"] then
- print("Crafting: " .. to_craft["result"][2] .. " x " .. to_craft["result"][1])
- -- send items to inventories
- print("Sending items to inventories")
- for i=1,16 do
- local slot = turtle.getItemDetail(i)
- if not slot then
- break
- end
- if slot.name ~= dummy then
- turtle.select(i)
- if slot.name == to_craft["core"][1] then
- turtle.dropUp(to_craft["core"][2])
- turtle.dropDown()
- else
- turtle.dropDown()
- end
- end
- end
- -- wait for output
- print("Waiting for output")
- local done_crafting = false
- while not done_crafting do
- for i=1,16 do
- local slot = turtle.getItemDetail(i)
- if not slot then
- break
- end
- if slot.name == to_craft["result"][1] and slot.count >= to_craft["result"][2] then
- done_crafting = true
- print("Sending output to inventory")
- turtle.select(i)
- turtle.drop(to_craft["result"][2])
- break
- end
- end
- sleep(0.1)
- end
- -- remove dummy item (in blocking mode there should be only dummy item left)
- if using_dummy then
- print("Removing dummy item")
- for i=1,16 do
- local slot = turtle.getItemDetail(i)
- if slot then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- print("Finished crafting\n\n")
- else
- print("Recipe not found")
- end
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement