2

I'm currently experimenting with building a TNT cannon in Minecraft 1.16.3. The idea is that a command block fills the dispensers just before shooting with 1 TNT. So far I managed found out how to give a single block to a single dispenser with the following command:

/replaceitem block ~ ~ ~1 container.0 minecraft:tnt 1

However I didn't want to create and set a new command block for every dispenser, and given that /fill exists, I was wondering if I could modify the above command to select multiple dispensers. Perhaps something along the line of

/replaceitem block ~ ~ [~1,~7] container.0 minecraft:tnt 1
1
  • This is certainly possible, but unfortunately it'll take more than the replaceitem command alone. I suggest doing some research into the execute command, as well as using invisible armor stands to mark important locations.
    – MBraedley
    Oct 29, 2020 at 12:22

1 Answer 1

3

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]
6
  • This is not what the question is asking for.
    – MBraedley
    Oct 29, 2020 at 12:25
  • Could you explain what it is asking for, then? I will edit my answer as needed.
    – ginkgo
    Oct 29, 2020 at 16:42
  • OP wants to add a TNT to a bunch of existing dispensers at once. They already know how to do that for a single dispenser, but need a way for identifying a group of dispensers and adding a TNT to each of them in a single pass.
    – MBraedley
    Oct 29, 2020 at 16:53
  • Fixed, thank you
    – ginkgo
    Oct 29, 2020 at 16:55
  • This answers the question as it allows me to reacharge the cannon, so I will mark it as approved. However the dispensers placed by /fill won't have the same orientation as the originals.
    – Mek101
    Oct 30, 2020 at 23:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .