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 second_turtle_id = 12
- 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}
- },
- -- draconic energy relay crystal
- {
- ingredients = {
- {"minecraft:diamond", 4}, {"draconicevolution:wyvern_energy_core", 4}, {"draconicevolution:wyvern_core", 1}, {"draconicevolution:energy_crystal", 4},
- },
- core = {"draconicevolution:energy_crystal", 4},
- result = {"draconicevolution:energy_crystal", 4}
- },
- -- 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}
- }
- }
- -- RF upgrade tier1
- local rf_upgrade_items = {"draconicevolution:draconium_capacitor"}
- for k, v in pairs(rf_upgrade_items) do
- table.insert(recipes,
- {
- ingredients = {
- {"minecraft:golden_apple", 2}, {"minecraft:diamond", 2}, {"minecraft:ender_eye", 2},{"draconicevolution:draconic_core", 1}, {v, 1}
- },
- core = {v, 1},
- result = {v, 1},
- second_turtle = { name = "draconicevolution:tool_upgrade", damage = 0 }
- }
- )
- end
- -----------------------------------------
- -- open rednet
- rednet.open("left")
- -- 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])
- local turtle_error = false
- -- send command to 2nd turtle
- if to_craft.second_turtle then
- print("Sending item info to 2nd turtle")
- rednet.send(second_turtle_id, to_craft.second_turtle)
- local waiting_for_response = true
- while waiting_for_response do
- local id, msg = rednet.receive()
- if id == second_turtle_id then
- if msg == "DONE" then
- print("Second turtle procesed info successfully")
- else
- print("Message from 2nd turtle: " .. msg)
- turtle_error = true
- end
- break
- end
- end
- end
- if not turtle_error then
- -- 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
- -- send command to 2nd turtle
- if to_craft.second_turtle then
- print("Sending retrieve command to 2nd turtle")
- rednet.send(second_turtle_id, "RETRIEVE")
- local waiting_for_response = true
- while waiting_for_response do
- local id, msg = rednet.receive()
- if id == second_turtle_id then
- if msg == "DONE" then
- print("Second turtle procesed command successfully")
- else
- print("Message from 2nd turtle: " .. msg)
- end
- break
- end
- end
- 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")
- end
- else
- print("Recipe not found")
- end
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment