Minecraft – Fill and Replace command with prefilled dispenser

minecraft-commandsminecraft-java-edition

I'm creating a TNT cannon with dispensers and a clock. It's a long tower of dispensers and after the cannon is done firing TNT, you have to painfully refill it or at least replace it with this /give given dispenser;

/give @p dispenser 1 0 {BlockEntityTag:{Items:[{id:"tnt",Count:64b,Slot:0b}, {id:"tnt",Count:64b,Slot:1b}, {id:"tnt",Count:64b,Slot:2b},{id:"tnt",Count:64b,Slot:3b}, {id:"tnt",Count:64b,Slot:4b}, {id:"tnt",Count:64b,Slot:5b}, {id:"tnt",Count:64b,Slot:6b}, {id:"tnt",Count:64b,Slot:7b}, {id:"tnt",Count:64b,Slot:8b}]}}

I know how to use the /fill command but is it possible to fill blocks with a prefilled dispenser?

Like this; /fill ~ ~ ~ ~5 ~ ~5 dispenser 0 {FILLED ITEMS} replace wool 14

The above should replace all red wool within the relative dimensions of 6x6x1 with prefilled dispensers.

Best Answer

Your fill statement is almost correct. You have to specify oldBlockHandling, as per the syntax of the command:

fill <x1> <y1> <z1> <x2> <y2> <z2> <TileName> [dataValue] [oldBlockHandling] [dataTag]

(http://minecraft.gamepedia.com/Commands#fill)

Your command would look like this:

/fill ~ ~ ~ ~5 ~ ~5 minecraft:dispenser 0 replace {Items:[{id:"tnt",Count:64b,Slot:0b}, {id:"tnt",Count:64b,Slot:1b}, {id:"tnt",Count:64b,Slot:2b},{id:"tnt",Count:64b,Slot:3b}, {id:"tnt",Count:64b,Slot:4b}, {id:"tnt",Count:64b,Slot:5b}, {id:"tnt",Count:64b,Slot:6b}, {id:"tnt",Count:64b,Slot:7b}, {id:"tnt",Count:64b,Slot:8b}]}

Note that if you want to change the rotation of the dispenser, you would change the dataValue.