Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local output = peripheral.wrap('minecraft:chest_3')
- local input = peripheral.wrap('minecraft:chest_1')
- local stock = {}
- local function checkStock()
- local items = input.list()
- for slot, item in pairs(items) do
- if not stock[item.name] then
- stock[item.name] = {}
- stock[item.name]['slots'] = {}
- end
- table.insert(stock[item.name]['slots'], {
- ['slot'] = slot,
- ['count'] = item.count
- })
- end
- for item, slots in pairs(stock) do
- local total = 0
- for _,slot in pairs(slots['slots']) do
- total = total + slot.count
- end
- stock[item]['stock'] = total
- end
- end
- local function getSlots(item)
- local counts = {}
- for _, v in pairs(stock[item]['slots']) do
- table.insert(counts,v.count)
- end
- table.sort(counts)
- local new = {}
- for _, v in pairs(stock[item]['slots']) do
- for i, b in pairs(counts) do
- if b == v.count then
- new[i] = {
- ['count'] = b,
- ['slot'] = v.slot
- }
- end
- end
- end
- return new
- end
- local function getItems(item,amount)
- if stock[item] and stock[item]['stock'] >= amount then
- print('yay')
- local remaining = amount
- repeat
- print(remaining)
- local slot = getSlots(item)[1]
- local amountToTake = math.min(slot.count, remaining)
- if amountToTake == slot.count then
- slot = nil
- else
- slot = {
- ['count'] = slot.count - amountToTake,
- ['slot'] = slot.slot
- }
- input.pushItems('minecraft:chest_3',slot.slot, amountToTake)
- remaining = remaining - amountToTake
- if remaining%32 == 0 then
- output.drop(1)
- end
- sleep(.1)
- until remaining == 0
- output.drop(1)
- else
- print('aw')
- end
- end
- local function printStock()
- for item, slots in pairs(stock) do
- print(stock[item]['stock']..' x '..item.. ' in stock')
- end
- end
- updateStock()
- --print(textutils.serialize(stock))
- printStock()
- --print(textutils.serialize(getSlots('minecraft:cooked_beef')))
- getItems('minecraft:cooked_beef',65)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement