Minecraft – How do i make all torches have fire aspect

minecraft-commandsminecraft-java-edition

I wanted to make all torches (Crafted and found) have fire aspect using commands. I tried some different things but they didn't work out. Does anyone else have any ideas?

Best Answer

Default items have no data of which to detect in order to separate them from custom items. Unfortunately this greatly restricts methods of replacing default items since, for example, /clear would not be able to differentiate your custom torches with default ones.

One work-around is to detect each individual slot in the player's inventory and use /replaceitem, but that requires 64 command blocks for each of the 36 slots just for detection alone.

As a quick run-down:

  1. Find 1 torch in slot 0.

    /scoreboard players set @a TorchSlot0 1 {Inventory:[{id:"minecraft:torch",Count:1b,Slot:0b}]}
    
  2. Replace that torch with 1 custom torch.

    /replaceitem entity @a[score_TorchSlot0_min=1,score_TorchSlot0=1] slot.container.0 minecraft:torch 1 0 {ench:[{id:20s,lvl:1s}]}
    

Which would need to be repeated for every number of torches possible in every slot possible.


If using 1.9, you can customize the loot tables so that the torches that are at least found in chests will have the desired enchantment.

For example, the chests/abandoned_mineshaft.json loot table has the following entry:

{
    "type": "item",
    "name": "minecraft:torch",
    "functions": [
        {
            "function": "set_count",
            "count": {
                "min": 1,
                "max": 16
            }
        }
    ],
    "weight": 15
}

If you want it to be enchanted with fire aspect, you'd add the enchant_randomly function while only specifying minecraft:fire_aspect:

{
    "type": "item",
    "name": "minecraft:torch",
    "functions": [
        {
            "function": "set_count",
            "count": {
                "min": 1,
                "max": 16
            }
        },
        {
            "function": "enchant_randomly",
            "enchantments":[
                "minecraft:fire_aspect"
            ]
        }
    ],
    "weight": 15
}