SHOW:
|
|
- or go back to the newest paste.
| 1 | local chest = "back" | |
| 2 | local chest_to_turtle = "east" | |
| 3 | local turtle_to_chest = "west" | |
| 4 | ||
| 5 | local function sum_inv(i) | |
| 6 | local out = {}
| |
| 7 | for _, v in pairs(i) do | |
| 8 | out[v.name] = (out[v.name] or 0) + v.count | |
| 9 | end | |
| 10 | return out | |
| 11 | end | |
| 12 | ||
| 13 | local function clear_inv() | |
| 14 | for i = 1, 16 do | |
| 15 | peripheral.call(chest, "pullItems", turtle_to_chest, i) | |
| 16 | end | |
| 17 | end | |
| 18 | ||
| 19 | local recipe = {
| |
| 20 | {"minecraft:sand", "minecraft:sand", "minecraft:sand"},
| |
| 21 | {"minecraft:sand", "minecraft:gravel", "minecraft:gravel"},
| |
| 22 | {"minecraft:gravel", "minecraft:gravel", "minecraft:dye"},
| |
| 23 | } | |
| 24 | local reqs = {}
| |
| 25 | for y, row in pairs(recipe) do | |
| 26 | for x, item in pairs(row) do | |
| 27 | reqs[item] = (reqs[item] or 0) + 1 | |
| 28 | end | |
| 29 | end | |
| 30 | ||
| 31 | local function satisfied(reqs, by) | |
| 32 | for req, qty in pairs(reqs) do | |
| 33 | if qty > (by[req] or 0) then return false end | |
| 34 | end | |
| 35 | return true | |
| 36 | end | |
| 37 | ||
| 38 | local function move(what, to) | |
| 39 | for slot, stack in pairs(peripheral.call(chest, "list")) do | |
| 40 | if stack.name == what then peripheral.call(chest, "pushItems", chest_to_turtle, slot, 1, to) return end | |
| 41 | end | |
| 42 | end | |
| 43 | ||
| 44 | while true do | |
| 45 | local contents = peripheral.call(chest, "list") | |
| 46 | local items = sum_inv(contents) | |
| 47 | if satisfied(reqs, items) then | |
| 48 | print "Requirements satisfied; crafting." | |
| 49 | for y, row in pairs(recipe) do | |
| 50 | for x, item in pairs(row) do | |
| 51 | local tslot = ((y - 1) * 4) + x | |
| 52 | move(item, tslot) | |
| 53 | sleep() | |
| 54 | end | |
| 55 | end | |
| 56 | turtle.select(1) | |
| 57 | turtle.craft() | |
| 58 | --turtle.dropDown() | |
| 59 | repeat turtle.place() sleep() | |
| 60 | until turtle.getItemCount() == 0 | |
| 61 | else | |
| 62 | print "Not crafting; requirements not satisfied." | |
| 63 | end | |
| 64 | sleep(1) | |
| 65 | end |