MtnMCG

equipturtle

Sep 15th, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. -- Scan inventory to find dispenser
  2. local function findDispenserSlot()
  3. for i = 1, 16 do
  4. local item = turtle.getItemDetail(i)
  5. if item and item.name == "minecraft:dispenser" then
  6. return i
  7. end
  8. end
  9. return nil
  10. end
  11.  
  12. -- Place dispenser below facing up
  13. local function placeDispenserDown(slot)
  14. turtle.select(slot)
  15. turtle.placeDown()
  16. end
  17.  
  18. -- Move back, dig, and go down
  19. local function moveToDispenser()
  20. turtle.back()
  21. turtle.digDown()
  22. turtle.down()
  23. end
  24.  
  25. -- Fill dispenser with contents of inventory
  26. local function fillDispenser()
  27. for i = 1, 16 do
  28. if i ~= dispenserSlot then
  29. turtle.select(i)
  30. turtle.dropUp()
  31. end
  32. end
  33. end
  34.  
  35. -- Send redstone signal in front four times
  36. local function triggerDispenser()
  37. for i = 1, 4 do
  38. redstone.setOutput("front", true)
  39. os.sleep(0.1)
  40. redstone.setOutput("front", false)
  41. os.sleep(0.5)
  42. end
  43. end
  44.  
  45. -- Main program
  46. local dispenserSlot = findDispenserSlot()
  47. if dispenserSlot then
  48. placeDispenserDown(dispenserSlot)
  49. moveToDispenser()
  50. fillDispenser()
  51. triggerDispenser()
  52. print("Program completed successfully.")
  53. else
  54. print("No dispenser found in inventory.")
  55. end
Advertisement
Add Comment
Please, Sign In to add comment