View difference between Paste ID: KLvYLU9r and UehPuYGB
SHOW: | | - or go back to the newest paste.
1-
local source = "turtle_2238"
1+
local storage = peripheral.find "minecraft:ender chest"
2-
local dispense_from = "minecraft:ironchest_crystal_469"
2+
local monitor = peripheral.find "monitor"
3-
local monitor = peripheral.wrap "monitor_2978"
3+
local button = settings.get "melon.button" or "right"
4-
local button = "top"
4+
5
local dispense_direction = settings.get "melon.dispense" or "west"
6-
local dispense_direction = "west"
6+
7-
local size = peripheral.call(dispense_from, "size")
7+
local to_store = "minecraft:melon"
8-
local stack_size = 64
8+
9
local function mon_write(...)
10
	monitor.setTextScale(1)
11
	local oldterm = term.redirect(monitor)
12
	term.clear()
13
	term.setCursorPos(1, 1)
14
	print "GTech AutoMelon"
15
	write(...)
16
	term.redirect(oldterm)
17
end
18
19
local function fill_chest()
20
	while true do
21
		local count = 0
22-
		local current_contents = peripheral.call(dispense_from, "list")
22+
		for slot, stack in pairs(storage.list()) do
23
			if stack.name == to_store then
24-
		local item_count = 0
24+
				count = count + stack.count
25-
		local can_fill = true
25+
26-
		for slot = 1, size do
26+
27-
			local slot_contents = current_contents[slot]
27+
		mon_write(("%dx %s stored\nPress button for %dx %s"):format(count, display_name, dispense_count, display_name))
28
		local timer = os.startTimer(5)
29-
			if slot_contents and slot_contents.count then
29+
		while true do
30-
				item_count = item_count + slot_contents.count
30+
			local ev, param = os.pullEvent()
31
			if (ev == "timer" and param == timer) or ev == "refresh_storage" then break end
32-
			if can_fill and (not slot_contents or slot_contents.count < stack_size) then
32+
33-
				print("Filling slot", slot)
33+
34-
				local source_contents = peripheral.call(source, "list")
34+
35-
				local moved
35+
36-
				for source_slot in pairs(source_contents) do
36+
37-
					moved = peripheral.call(source, "pushItems", dispense_from, source_slot, nil, slot)
37+
38
		os.pullEvent "redstone"
39-
				if moved then
39+
40-
					print("Moved", moved, "items")
40+
			local contents = storage.list()
41-
				else
41+
42-
					print("Insufficient items in source")
42+
43-
					can_fill = false
43+
44
					storage.drop(slot, dispense_count, dispense_direction)
45
					os.queueEvent("refresh_storage")
46
					break		
47
				end
48-
		mon_write(("%dx %s stored\n\nPress button for %dx %s"):format(item_count, display_name, dispense_count, display_name))
48+
49-
		sleep(5)
49+
50
	end
51
end
52
53
parallel.waitForAll(handle_button, fill_chest)