Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Scan inventory to find dispenser
- local function findDispenserSlot()
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item and item.name == "minecraft:dispenser" then
- return i
- end
- end
- return nil
- end
- -- Place dispenser below facing up
- local function placeDispenserDown(slot)
- turtle.select(slot)
- turtle.placeDown()
- end
- -- Move back, dig, and go down
- local function moveToDispenser()
- turtle.back()
- turtle.digDown()
- turtle.down()
- end
- -- Fill dispenser with contents of inventory
- local function fillDispenser()
- for i = 1, 16 do
- if i ~= dispenserSlot then
- turtle.select(i)
- turtle.dropUp()
- end
- end
- end
- -- Send redstone signal in front four times
- local function triggerDispenser()
- for i = 1, 4 do
- redstone.setOutput("front", true)
- os.sleep(0.1)
- redstone.setOutput("front", false)
- os.sleep(0.5)
- end
- end
- -- Main program
- local dispenserSlot = findDispenserSlot()
- if dispenserSlot then
- placeDispenserDown(dispenserSlot)
- moveToDispenser()
- fillDispenser()
- triggerDispenser()
- print("Program completed successfully.")
- else
- print("No dispenser found in inventory.")
- end
Advertisement
Add Comment
Please, Sign In to add comment