Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Makes stuff out of whatever's in a chest above a turtle, according to a list of recipes in the "make" table.
- -- Pulls new materials out of a container in front of the turtle and adds them to the chest as it goes.
- -- Doesn't yet account too well for item types that don't stack up to 64 ('cause I'm lazy).
- local sleepSeconds = 60 -- Lower this if you have a super-high ingredient flow.
- local chest = peripheral.wrap("top")
- local slots, items = chest.getInventorySize()
- local make = {
- {
- ["name"] = "Glowstone",
- ["id"] = "minecraft:glowstone:0",
- ["recipe"] = {
- "minecraft:glowstone_dust:0", "minecraft:glowstone_dust:0", nil,
- "minecraft:glowstone_dust:0", "minecraft:glowstone_dust:0"
- }
- },
- {
- ["name"] = "Clay",
- ["id"] = "minecraft:clay:0",
- ["recipe"] = {
- "minecraft:clay_ball:0", "minecraft:clay_ball:0", nil,
- "minecraft:clay_ball:0", "minecraft:clay_ball:0"
- }
- },
- {
- ["name"] = "Block of Quartz",
- ["id"] = "minecraft:quartz_block:0",
- ["recipe"] = {
- "minecraft:quartz:0", "minecraft:quartz:0", nil,
- "minecraft:quartz:0", "minecraft:quartz:0"
- }
- },
- {
- ["name"] = "Yellorium Dust",
- ["id"] = "BigReactors:BRIngot:4",
- ["recipe"] = {
- "ExtraBees:misc:27", "ExtraBees:misc:27", nil,
- "ExtraBees:misc:27", "ExtraBees:misc:27"
- }
- },
- {
- ["name"] = "Ferrous Ingot",
- ["id"] = "ThermalFoundation:material:68",
- ["recipe"] = {
- "ThermalFoundation:material:100", "ThermalFoundation:material:100", "ThermalFoundation:material:100",
- "ThermalFoundation:material:100", "ThermalFoundation:material:100", "ThermalFoundation:material:100",
- "ThermalFoundation:material:100", "ThermalFoundation:material:100", "ThermalFoundation:material:100"
- }
- },
- {
- ["name"] = "Ferrous Block",
- ["id"] = "ThermalFoundation:Storage:4",
- ["recipe"] = {
- "ThermalFoundation:material:68", "ThermalFoundation:material:68", "ThermalFoundation:material:68",
- "ThermalFoundation:material:68", "ThermalFoundation:material:68", "ThermalFoundation:material:68",
- "ThermalFoundation:material:68", "ThermalFoundation:material:68", "ThermalFoundation:material:68"
- }
- },
- {
- ["name"] = "Shiny Ingot",
- ["id"] = "ThermalFoundation:material:69",
- ["recipe"] = {
- "ThermalFoundation:material:101", "ThermalFoundation:material:101", "ThermalFoundation:material:101",
- "ThermalFoundation:material:101", "ThermalFoundation:material:101", "ThermalFoundation:material:101",
- "ThermalFoundation:material:101", "ThermalFoundation:material:101", "ThermalFoundation:material:101"
- }
- },
- {
- ["name"] = "Shiny Block",
- ["id"] = "ThermalFoundation:Storage:5",
- ["recipe"] = {
- "ThermalFoundation:material:69", "ThermalFoundation:material:69", "ThermalFoundation:material:69",
- "ThermalFoundation:material:69", "ThermalFoundation:material:69", "ThermalFoundation:material:69",
- "ThermalFoundation:material:69", "ThermalFoundation:material:69", "ThermalFoundation:material:69"
- }
- },
- {
- ["name"] = "Block of Redstone",
- ["id"] = "minecraft:redstone_block:0",
- ["recipe"] = {
- "minecraft:redstone:0", "minecraft:redstone:0", "minecraft:redstone:0",
- "minecraft:redstone:0", "minecraft:redstone:0", "minecraft:redstone:0",
- "minecraft:redstone:0", "minecraft:redstone:0", "minecraft:redstone:0"
- }
- },
- {
- ["name"] = "Seeds",
- ["id"] = "minecraft:wheat_seeds:0",
- ["output"] = 2,
- ["recipe"] = {
- "minecraft:wheat:0", "minecraft:wheat:0"
- }
- },
- {
- ["name"] = "Gold Ingot",
- ["id"] = "minecraft:gold_ingot:0",
- ["recipe"] = {
- "minecraft:gold_nugget:0", "minecraft:gold_nugget:0", "minecraft:gold_nugget:0",
- "minecraft:gold_nugget:0", "minecraft:gold_nugget:0", "minecraft:gold_nugget:0",
- "minecraft:gold_nugget:0", "minecraft:gold_nugget:0", "minecraft:gold_nugget:0"
- }
- },
- {
- ["name"] = "Block of Gold",
- ["id"] = "minecraft:gold_block:0",
- ["recipe"] = {
- "minecraft:gold_ingot:0", "minecraft:gold_ingot:0", "minecraft:gold_ingot:0",
- "minecraft:gold_ingot:0", "minecraft:gold_ingot:0", "minecraft:gold_ingot:0",
- "minecraft:gold_ingot:0", "minecraft:gold_ingot:0", "minecraft:gold_ingot:0"
- }
- },
- {
- ["name"] = "Diamond",
- ["id"] = "minecraft:diamond:0",
- ["recipe"] = {
- "MagicBees:beeNugget:5", "MagicBees:beeNugget:5", "MagicBees:beeNugget:5",
- "MagicBees:beeNugget:5", "MagicBees:beeNugget:5", "MagicBees:beeNugget:5",
- "MagicBees:beeNugget:5", "MagicBees:beeNugget:5", "MagicBees:beeNugget:5"
- }
- },
- {
- ["name"] = "Block of Diamond",
- ["id"] = "minecraft:diamond_block:0",
- ["recipe"] = {
- "minecraft:diamond:0", "minecraft:diamond:0", "minecraft:diamond:0",
- "minecraft:diamond:0", "minecraft:diamond:0", "minecraft:diamond:0",
- "minecraft:diamond:0", "minecraft:diamond:0", "minecraft:diamond:0"
- }
- },
- {
- ["name"] = "Lapis Lazuli Block",
- ["id"] = "minecraft:lapis_block:0",
- ["recipe"] = {
- "minecraft:dye:4", "minecraft:dye:4", "minecraft:dye:4",
- "minecraft:dye:4", "minecraft:dye:4", "minecraft:dye:4",
- "minecraft:dye:4", "minecraft:dye:4", "minecraft:dye:4"
- }
- },
- {
- ["name"] = "Block of Coal",
- ["id"] = "minecraft:coal_block:0",
- ["recipe"] = {
- "minecraft:coal:0", "minecraft:coal:0", "minecraft:coal:0",
- "minecraft:coal:0", "minecraft:coal:0", "minecraft:coal:0",
- "minecraft:coal:0", "minecraft:coal:0", "minecraft:coal:0"
- }
- },
- {
- ["name"] = "Alveary",
- ["id"] = "Forestry:alveary:0",
- ["recipe"] = {
- "Forestry:craftingMaterial:6", "Forestry:craftingMaterial:6", "Forestry:craftingMaterial:6",
- "Forestry:craftingMaterial:6", "Forestry:impregnatedCasing:0", "Forestry:craftingMaterial:6",
- "Forestry:craftingMaterial:6", "Forestry:craftingMaterial:6", "Forestry:craftingMaterial:6"
- }
- },
- {
- ["name"] = "Oak Wood Planks",
- ["id"] = "minecraft:planks:0",
- ["output"] = 4,
- ["recipe"] = {
- "minecraft:log:0"
- }
- },
- {
- ["name"] = "Dark Oak Wood Planks",
- ["id"] = "minecraft:planks:5",
- ["output"] = 4,
- ["recipe"] = {
- "minecraft:log2:1"
- }
- },
- {
- ["name"] = "Crafting Table",
- ["id"] = "minecraft:crafting_table:0",
- ["recipe"] = {
- "minecraft:planks:0", "minecraft:planks:0", nil,
- "minecraft:planks:0", "minecraft:planks:0"
- }
- },
- {
- ["name"] = "Crafting Table",
- ["id"] = "minecraft:crafting_table:0",
- ["recipe"] = {
- "minecraft:planks:5", "minecraft:planks:5", nil,
- "minecraft:planks:5", "minecraft:planks:5"
- }
- },
- {
- ["name"] = "Compressed Cobblestone",
- ["id"] = "ExtraUtilities:cobblestone_compressed:0",
- ["recipe"] = {
- "minecraft:cobblestone:0", "minecraft:cobblestone:0", "minecraft:cobblestone:0",
- "minecraft:cobblestone:0", "minecraft:cobblestone:0", "minecraft:cobblestone:0",
- "minecraft:cobblestone:0", "minecraft:cobblestone:0", "minecraft:cobblestone:0"
- }
- },
- {
- ["name"] = "Double Compressed Cobblestone",
- ["id"] = "ExtraUtilities:cobblestone_compressed:1",
- ["recipe"] = {
- "ExtraUtilities:cobblestone_compressed:0", "ExtraUtilities:cobblestone_compressed:0", "ExtraUtilities:cobblestone_compressed:0",
- "ExtraUtilities:cobblestone_compressed:0", "ExtraUtilities:cobblestone_compressed:0", "ExtraUtilities:cobblestone_compressed:0",
- "ExtraUtilities:cobblestone_compressed:0", "ExtraUtilities:cobblestone_compressed:0", "ExtraUtilities:cobblestone_compressed:0"
- }
- },
- {
- ["name"] = "Triple Compressed Cobblestone",
- ["id"] = "ExtraUtilities:cobblestone_compressed:2",
- ["recipe"] = {
- "ExtraUtilities:cobblestone_compressed:1", "ExtraUtilities:cobblestone_compressed:1", "ExtraUtilities:cobblestone_compressed:1",
- "ExtraUtilities:cobblestone_compressed:1", "ExtraUtilities:cobblestone_compressed:1", "ExtraUtilities:cobblestone_compressed:1",
- "ExtraUtilities:cobblestone_compressed:1", "ExtraUtilities:cobblestone_compressed:1", "ExtraUtilities:cobblestone_compressed:1"
- }
- },
- {
- ["name"] = "Quadruple Compressed Cobblestone",
- ["id"] = "ExtraUtilities:cobblestone_compressed:3",
- ["recipe"] = {
- "ExtraUtilities:cobblestone_compressed:2", "ExtraUtilities:cobblestone_compressed:2", "ExtraUtilities:cobblestone_compressed:2",
- "ExtraUtilities:cobblestone_compressed:2", "ExtraUtilities:cobblestone_compressed:2", "ExtraUtilities:cobblestone_compressed:2",
- "ExtraUtilities:cobblestone_compressed:2", "ExtraUtilities:cobblestone_compressed:2", "ExtraUtilities:cobblestone_compressed:2"
- }
- },
- {
- ["name"] = "Quintuple Compressed Cobblestone",
- ["id"] = "ExtraUtilities:cobblestone_compressed:4",
- ["recipe"] = {
- "ExtraUtilities:cobblestone_compressed:3", "ExtraUtilities:cobblestone_compressed:3", "ExtraUtilities:cobblestone_compressed:3",
- "ExtraUtilities:cobblestone_compressed:3", "ExtraUtilities:cobblestone_compressed:3", "ExtraUtilities:cobblestone_compressed:3",
- "ExtraUtilities:cobblestone_compressed:3", "ExtraUtilities:cobblestone_compressed:3", "ExtraUtilities:cobblestone_compressed:3"
- }
- },
- {
- ["name"] = "Sextuple Compressed Cobblestone",
- ["id"] = "ExtraUtilities:cobblestone_compressed:5",
- ["recipe"] = {
- "ExtraUtilities:cobblestone_compressed:4", "ExtraUtilities:cobblestone_compressed:4", "ExtraUtilities:cobblestone_compressed:4",
- "ExtraUtilities:cobblestone_compressed:4", "ExtraUtilities:cobblestone_compressed:4", "ExtraUtilities:cobblestone_compressed:4",
- "ExtraUtilities:cobblestone_compressed:4", "ExtraUtilities:cobblestone_compressed:4", "ExtraUtilities:cobblestone_compressed:4"
- }
- },
- {
- ["name"] = "Septuple Compressed Cobblestone",
- ["id"] = "ExtraUtilities:cobblestone_compressed:6",
- ["recipe"] = {
- "ExtraUtilities:cobblestone_compressed:5", "ExtraUtilities:cobblestone_compressed:5", "ExtraUtilities:cobblestone_compressed:5",
- "ExtraUtilities:cobblestone_compressed:5", "ExtraUtilities:cobblestone_compressed:5", "ExtraUtilities:cobblestone_compressed:5",
- "ExtraUtilities:cobblestone_compressed:5", "ExtraUtilities:cobblestone_compressed:5", "ExtraUtilities:cobblestone_compressed:5"
- }
- },
- {
- ["name"] = "Octuple Compressed Cobblestone",
- ["id"] = "ExtraUtilities:cobblestone_compressed:7",
- ["recipe"] = {
- "ExtraUtilities:cobblestone_compressed:6", "ExtraUtilities:cobblestone_compressed:6", "ExtraUtilities:cobblestone_compressed:6",
- "ExtraUtilities:cobblestone_compressed:6", "ExtraUtilities:cobblestone_compressed:6", "ExtraUtilities:cobblestone_compressed:6",
- "ExtraUtilities:cobblestone_compressed:6", "ExtraUtilities:cobblestone_compressed:6", "ExtraUtilities:cobblestone_compressed:6"
- }
- },
- {
- ["name"] = "White Petal Block",
- ["id"] = "Botania:petalBlock:0",
- ["recipe"] = {
- "Botania:petal:0", "Botania:petal:0", "Botania:petal:0",
- "Botania:petal:0", "Botania:petal:0", "Botania:petal:0",
- "Botania:petal:0", "Botania:petal:0", "Botania:petal:0"
- }
- },
- {
- ["name"] = "Orange Petal Block",
- ["id"] = "Botania:petalBlock:1",
- ["recipe"] = {
- "Botania:petal:1", "Botania:petal:1", "Botania:petal:1",
- "Botania:petal:1", "Botania:petal:1", "Botania:petal:1",
- "Botania:petal:1", "Botania:petal:1", "Botania:petal:1"
- }
- },
- {
- ["name"] = "Magenta Petal Block",
- ["id"] = "Botania:petalBlock:2",
- ["recipe"] = {
- "Botania:petal:2", "Botania:petal:2", "Botania:petal:2",
- "Botania:petal:2", "Botania:petal:2", "Botania:petal:2",
- "Botania:petal:2", "Botania:petal:2", "Botania:petal:2"
- }
- },
- {
- ["name"] = "Light Blue Petal Block",
- ["id"] = "Botania:petalBlock:3",
- ["recipe"] = {
- "Botania:petal:3", "Botania:petal:3", "Botania:petal:3",
- "Botania:petal:3", "Botania:petal:3", "Botania:petal:3",
- "Botania:petal:3", "Botania:petal:3", "Botania:petal:3"
- }
- },
- {
- ["name"] = "Yellow Petal Block",
- ["id"] = "Botania:petalBlock:4",
- ["recipe"] = {
- "Botania:petal:4", "Botania:petal:4", "Botania:petal:4",
- "Botania:petal:4", "Botania:petal:4", "Botania:petal:4",
- "Botania:petal:4", "Botania:petal:4", "Botania:petal:4"
- }
- },
- {
- ["name"] = "Lime Petal Block",
- ["id"] = "Botania:petalBlock:5",
- ["recipe"] = {
- "Botania:petal:5", "Botania:petal:5", "Botania:petal:5",
- "Botania:petal:5", "Botania:petal:5", "Botania:petal:5",
- "Botania:petal:5", "Botania:petal:5", "Botania:petal:5"
- }
- },
- {
- ["name"] = "Pink Petal Block",
- ["id"] = "Botania:petalBlock:6",
- ["recipe"] = {
- "Botania:petal:6", "Botania:petal:6", "Botania:petal:6",
- "Botania:petal:6", "Botania:petal:6", "Botania:petal:6",
- "Botania:petal:6", "Botania:petal:6", "Botania:petal:6"
- }
- },
- {
- ["name"] = "Gray Petal Block",
- ["id"] = "Botania:petalBlock:7",
- ["recipe"] = {
- "Botania:petal:7", "Botania:petal:7", "Botania:petal:7",
- "Botania:petal:7", "Botania:petal:7", "Botania:petal:7",
- "Botania:petal:7", "Botania:petal:7", "Botania:petal:7"
- }
- },
- {
- ["name"] = "Light Gray Petal Block",
- ["id"] = "Botania:petalBlock:8",
- ["recipe"] = {
- "Botania:petal:8", "Botania:petal:8", "Botania:petal:8",
- "Botania:petal:8", "Botania:petal:8", "Botania:petal:8",
- "Botania:petal:8", "Botania:petal:8", "Botania:petal:8"
- }
- },
- {
- ["name"] = "Cyan Petal Block",
- ["id"] = "Botania:petalBlock:9",
- ["recipe"] = {
- "Botania:petal:9", "Botania:petal:9", "Botania:petal:9",
- "Botania:petal:9", "Botania:petal:9", "Botania:petal:9",
- "Botania:petal:9", "Botania:petal:9", "Botania:petal:9"
- }
- },
- {
- ["name"] = "Purple Petal Block",
- ["id"] = "Botania:petalBlock:10",
- ["recipe"] = {
- "Botania:petal:10", "Botania:petal:10", "Botania:petal:10",
- "Botania:petal:10", "Botania:petal:10", "Botania:petal:10",
- "Botania:petal:10", "Botania:petal:10", "Botania:petal:10"
- }
- },
- {
- ["name"] = "Blue Petal Block",
- ["id"] = "Botania:petalBlock:11",
- ["recipe"] = {
- "Botania:petal:11", "Botania:petal:11", "Botania:petal:11",
- "Botania:petal:11", "Botania:petal:11", "Botania:petal:11",
- "Botania:petal:11", "Botania:petal:11", "Botania:petal:11"
- }
- },
- {
- ["name"] = "Brown Petal Block",
- ["id"] = "Botania:petalBlock:12",
- ["recipe"] = {
- "Botania:petal:12", "Botania:petal:12", "Botania:petal:12",
- "Botania:petal:12", "Botania:petal:12", "Botania:petal:12",
- "Botania:petal:12", "Botania:petal:12", "Botania:petal:12"
- }
- },
- {
- ["name"] = "Green Petal Block",
- ["id"] = "Botania:petalBlock:13",
- ["recipe"] = {
- "Botania:petal:13", "Botania:petal:13", "Botania:petal:13",
- "Botania:petal:13", "Botania:petal:13", "Botania:petal:13",
- "Botania:petal:13", "Botania:petal:13", "Botania:petal:13"
- }
- },
- {
- ["name"] = "Red Petal Block",
- ["id"] = "Botania:petalBlock:14",
- ["recipe"] = {
- "Botania:petal:14", "Botania:petal:14", "Botania:petal:14",
- "Botania:petal:14", "Botania:petal:14", "Botania:petal:14",
- "Botania:petal:14", "Botania:petal:14", "Botania:petal:14"
- }
- },
- {
- ["name"] = "Black Petal Block",
- ["id"] = "Botania:petalBlock:15",
- ["recipe"] = {
- "Botania:petal:15", "Botania:petal:15", "Botania:petal:15",
- "Botania:petal:15", "Botania:petal:15", "Botania:petal:15",
- "Botania:petal:15", "Botania:petal:15", "Botania:petal:15"
- }
- },
- }
- for i = 1, #make do
- make[i].output = make[i].output or 1
- make[i].slotMax = make[i].slotMax or 64
- end
- -- Translation of recipe slots to turtle inventory slots.
- local bench = {1, 2, 3, 5, 6, 7, 9, 10 ,11}
- local function registerItem(slot, id, amount)
- if items[slot] then
- items[slot] = items[slot] + amount
- local ref = items[id]
- if ref then
- ref.amount = ref.amount + amount
- for i = 1, #ref do
- if ref[i] == slot then
- return
- end
- end
- end
- error("Attempt to register "..amount.." "..id.." in chest slot "..slot..", but it holds another item type.")
- else
- items[slot] = amount
- items.freeSlots = items.freeSlots - 1
- local ref = items[id]
- if ref then
- ref[#ref + 1] = slot
- ref.amount = ref.amount + amount
- else
- items[id] = {slot, ["amount"] = amount}
- end
- if slot == items.freeSlot then
- items.freeSlot = nil
- for i = 1, slots do
- if not items[i] then
- items.freeSlot = i
- break
- end
- end
- end
- end
- end
- local function readChestSlots()
- items = {["freeSlots"] = 0}
- for i = slots, 1, -1 do
- local stack = chest.getStackInSlot(i)
- if stack then
- registerItem(i, stack.id .. ":" .. stack.dmg, stack.qty)
- else
- items.freeSlot, items.freeSlots = i, items.freeSlots + 1
- end
- end
- end
- turtle.select(1)
- while true do
- readChestSlots()
- -- Loop through all recipes in the database and attempt to craft them.
- for i = 1, #make do
- local crafted = true
- while crafted do
- crafted = false
- -- Eject anything the turtle's holding into the chest above.
- for j = 1, 16 do
- local item = turtle.getItemDetail(j)
- if item then
- local id, amount = item.name .. ":" .. item.damage, item.count
- -- Merge into whatever slots we can.
- if items[id] then
- local ref = items[id]
- for k = 1, #ref do
- if items[ref[k]] < 64 then
- local toPull = math.min(64 - items[ref[k]], amount)
- local pulled = chest.pullItemIntoSlot("down", j, toPull, ref[k])
- amount = amount - pulled
- if pulled > 0 then registerItem(ref[k], id, pulled) end
- if amount == 0 then break end
- end
- end
- end
- -- Use a free slot if we have to.
- while amount > 0 do
- if not items.freeSlot then error("Attempted to stash "..id..", but ran out of room in the chest!") end
- local pulled = chest.pullItemIntoSlot("down", j, amount, items.freeSlot)
- amount = amount - pulled
- if pulled > 0 then registerItem(items.freeSlot, id, pulled) end
- if amount > 0 then readChestSlots() end
- end
- end
- end
- -- Confirm whether we can craft the current recipe.
- -- First, how much of the recipe's output can we store?
- local item, maxCanStore, targetSlot = make[i], 0
- -- Is there a spare slot to stick things in?
- if items.freeSlot then
- maxCanStore, targetSlot = item.slotMax, items.freeSlot
- -- If not, will we be able to merge a stack?
- elseif items[item.id] then
- local list, lowest = items[item.id], item.slotMax
- for j = 1, #list do
- if items[list[j]] < lowest then
- lowest, targetSlot = items[list[j]], list[j]
- end
- end
- maxCanStore = item.slotMax - lowest
- end
- if maxCanStore > 0 then
- -- Have storage, but do we have ingrediants?
- local maxCanMake, resources = item.slotMax, {}
- -- Which ones do we need, and in what amounts?
- for j = 1, 9 do
- local part = item.recipe[j]
- if part then
- if not items[part] then
- maxCanMake = 0
- break
- end
- if resources[part] then
- resources[resources[part]] = resources[resources[part]] + 1
- else
- resources[part] = #resources + 1
- resources[resources[part]] = 1
- end
- if math.floor(items[part].amount / resources[resources[part]]) < maxCanMake then
- maxCanMake = math.floor(items[part].amount / resources[resources[part]])
- end
- end
- end
- local amount = math.min(math.floor(maxCanStore / item.output), maxCanMake)
- if amount > 0 then
- -- Let's craft some stuff!
- print("Crafting "..amount*item.output.." "..item.name..".")
- -- Gather the needed materials into the turtle's inventory.
- for j = 1, 9 do
- local part = item.recipe[j]
- if part then
- local needed = amount
- local slots = items[part]
- for k = #slots, 1, -1 do
- if needed < items[slots[k]] then
- chest.pushItemIntoSlot("down", slots[k], needed, bench[j])
- items[slots[k]] = items[slots[k]] - needed
- break
- else
- chest.pushItemIntoSlot("down", slots[k], items[slots[k]], bench[j])
- needed = needed - items[slots[k]]
- items[table.remove(slots, k)] = nil
- items.freeSlots = items.freeSlots + 1
- if needed == 0 then break end
- end
- end
- slots.amount = slots.amount - amount
- end
- end
- -- And then mash them together.
- crafted = turtle.craft()
- end
- end
- end
- end
- sleep(sleepSeconds)
- end
Add Comment
Please, Sign In to add comment