Files
Inventory-Manager-CC/dropperController.lua

56 lines
1.6 KiB
Lua

-- Dropper Controller: Runs on Computer 1 (next to dropper_0)
-- Watches the dropper and pulses redstone until it's empty.
local REDSTONE_SIDE = "back" -- side facing dropper_0
local PULSE_TIME = 0.3 -- redstone pulse duration in seconds
local POLL_INTERVAL = 0.5 -- how often to check the dropper
local DROPPER_SIDE = "back" -- side where the dropper is (as peripheral)
-------------------------------------------------
-- Helpers
-------------------------------------------------
-- Send a redstone pulse to trigger the dropper
local function pulseRedstone()
redstone.setOutput(REDSTONE_SIDE, true)
sleep(PULSE_TIME)
redstone.setOutput(REDSTONE_SIDE, false)
end
-- Check if the dropper has any items
local function dropperHasItems()
local dropper = peripheral.wrap(DROPPER_SIDE)
if not dropper then return false end
local contents = dropper.list()
if not contents then return false end
return next(contents) ~= nil
end
-------------------------------------------------
-- Main
-------------------------------------------------
print("=================================")
print(" Dropper Controller (ID " .. os.getComputerID() .. ")")
print("=================================")
print("")
print("Redstone side: " .. REDSTONE_SIDE)
print("Watching dropper for items...")
print("")
while true do
if dropperHasItems() then
print("[DISPENSE] Items detected, firing dropper...")
-- Keep pulsing until the dropper is empty
while dropperHasItems() do
pulseRedstone()
sleep(0.1)
end
print("[OK] Dropper empty.")
end
sleep(POLL_INTERVAL)
end