Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bridge = peripheral.wrap("left")
- local items = bridge.listItems();
- craft = {}
- craft[265] = 500
- craft[266] = 250
- crafting = {}
- function checkCraft()
- while true do
- for key,value in pairs(craft) do
- local craftCount = 0
- if crafting[key] == nil then
- if items[key] == nil then
- craftCount = value
- elseif items[key] < value then
- craftCount = value - items[key]
- end
- if craftCount > 0 then
- print("Craft " .. tostring(craftCount) .. " from itemid " .. key)
- bridge.craft(key, craftCount)
- crafting[key] = craftCount
- end
- end
- end
- os.sleep(60)
- end
- end
- function listenComplete()
- while true do
- print("Listening to events")
- local event, key = os.pullEvent("craftingComplete")
- print("Received craftingComplete event for item " .. event.itemCrafted)
- if crafting[event.itemCrafted] ~= nil then
- crafting[event.itemCrafted] = nil
- print("Removed from crafting table")
- end
- end
- end
- parallel.waitForAll(checkCraft, listenComplete)
Advertisement
Add Comment
Please, Sign In to add comment