April_The_Sergal

ChestControl

Jul 27th, 2025 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. local source = "back" -- single-slot inventory
  2. local target = "bottom" -- destination chest
  3. local slot = 1
  4. local waitTime = 0.1
  5.  
  6. local owedDrop = false
  7.  
  8. local function isSlotEmpty()
  9. local item = peripheral.call(source, "getItemDetail", slot)
  10. return item == nil
  11. end
  12.  
  13. local function tryDrop()
  14. local moved = peripheral.call(source, "pushItems", target, slot, 1)
  15. if moved > 0 then
  16. print("Dropped 1 item.")
  17. return true
  18. else
  19. print("Nothing to drop or move failed.")
  20. return false
  21. end
  22. end
  23.  
  24. local function waitForNoSignal()
  25. while redstone.getInput("top") do
  26. sleep(waitTime)
  27. end
  28. end
  29.  
  30. local function waitForSignal()
  31. while not redstone.getInput("top") do
  32. sleep(waitTime)
  33. end
  34. end
  35.  
  36. while true do
  37. waitForNoSignal()
  38.  
  39. if not tryDrop() then
  40. print("Empty inventory — drop owed on reset.")
  41. owedDrop = true
  42. end
  43.  
  44. waitForSignal()
  45.  
  46. if owedDrop then
  47. print("Reset signal received. Performing owed drop...")
  48. while not tryDrop() do
  49. print("Still waiting for item to drop...")
  50. sleep(1)
  51. end
  52. owedDrop = false
  53. end
  54. end
  55.  
Advertisement
Add Comment
Please, Sign In to add comment