Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local source = "turtle_2238"
- local dispense_from = "minecraft:ironchest_crystal_469"
- local monitor = peripheral.wrap "monitor_2978"
- local button = "top"
- local dispense_count = 16
- local dispense_direction = "west"
- local size = peripheral.call(dispense_from, "size")
- local stack_size = 64
- local display_name = "Melon"
- local function mon_write(...)
- monitor.setTextScale(1)
- local oldterm = term.redirect(monitor)
- term.clear()
- term.setCursorPos(1, 1)
- write(...)
- term.redirect(oldterm)
- end
- local function fill_chest()
- while true do
- local current_contents = peripheral.call(dispense_from, "list")
- local item_count = 0
- local can_fill = true
- for slot = 1, size do
- local slot_contents = current_contents[slot]
- if slot_contents and slot_contents.count then
- item_count = item_count + slot_contents.count
- end
- if can_fill and (not slot_contents or slot_contents.count < stack_size) then
- print("Filling slot", slot)
- local source_contents = peripheral.call(source, "list")
- local moved
- for source_slot in pairs(source_contents) do
- moved = peripheral.call(source, "pushItems", dispense_from, source_slot, nil, slot)
- end
- if moved then
- print("Moved", moved, "items")
- else
- print("Insufficient items in source")
- can_fill = false
- end
- end
- end
- mon_write(("%dx %s stored\n\nPress button for %dx %s"):format(item_count, display_name, dispense_count, display_name))
- sleep(5)
- end
- end
- local function handle_button()
- while true do
- os.pullEvent "redstone"
- if redstone.getInput(button) then
- local contents = peripheral.call(dispense_from, "list")
- for slot, stack in pairs(contents) do
- if stack.count > dispense_count then
- print("Dispensing", dispense_count, "from", slot, "to", dispense_direction)
- peripheral.call(dispense_from, "drop", slot, dispense_count, dispense_direction)
- break
- end
- end
- end
- end
- end
- parallel.waitForAll(handle_button, fill_chest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement