This command replaces all dispensers in a specified area with dispensers fully filled with TNT.
fill ~ ~ ~ ~ ~ ~ dispenser{Items:[{Slot:0b,id:"minecraft:tnt",Count:64b},{Slot:1b,id:"minecraft:tnt",Count:64b},{Slot:2b,id:"minecraft:tnt",Count:64b},{Slot:3b,id:"minecraft:tnt",Count:64b},{Slot:4b,id:"minecraft:tnt",Count:64b},{Slot:5b,id:"minecraft:tnt",Count:64b},{Slot:6b,id:"minecraft:tnt",Count:64b},{Slot:7b,id:"minecraft:tnt",Count:64b},{Slot:8b,id:"minecraft:tnt",Count:64b}]} replace dispenser
If you would like the dispensers to be only filled with 1 TNT, use this command:
fill ~ ~ ~ ~ ~ ~ dispenser{Items:[{Slot:0b,id:"minecraft:tnt",Count:1b}]} replace dispenser
Unfortunately, the fill command will not preserve the orientation of the preexisting dispensers. To avoid this issue, you will need 6 commands (1 for each dispenser orientation). You can optimize this yourself by removing the commands that reference dispenser orientations that your TNT cannon does not use:
fill ~ ~ ~ ~ ~ ~ dispenser[facing=north]{Items:[{Slot:0b,id:"minecraft:tnt",Count:1b}]} replace dispenser[facing=north]
fill ~ ~ ~ ~ ~ ~ dispenser[facing=east]{Items:[{Slot:0b,id:"minecraft:tnt",Count:1b}]} replace dispenser[facing=east]
fill ~ ~ ~ ~ ~ ~ dispenser[facing=south]{Items:[{Slot:0b,id:"minecraft:tnt",Count:1b}]} replace dispenser[facing=south]
fill ~ ~ ~ ~ ~ ~ dispenser[facing=west]{Items:[{Slot:0b,id:"minecraft:tnt",Count:1b}]} replace dispenser[facing=west]
fill ~ ~ ~ ~ ~ ~ dispenser[facing=up]{Items:[{Slot:0b,id:"minecraft:tnt",Count:1b}]} replace dispenser[facing=up]
fill ~ ~ ~ ~ ~ ~ dispenser[facing=down]{Items:[{Slot:0b,id:"minecraft:tnt",Count:1b}]} replace dispenser[facing=down]
replaceitem
command alone. I suggest doing some research into theexecute
command, as well as using invisible armor stands to mark important locations.