How to make an item unbreakable when appearing in inventory?
Solution 1:
To do this you would need a few command blocks for each item you want to make unbreakable. To identify the player who has the item in their inventory we are going to use scoreboards. In this example we will use a diamond sword but you can change wherever it syas diamond sword to whatever item you would like.
Setup
run this once:
/scoreboard objectives add hasItem stat.craftItem.minecraft.diamond_sword
Detection
put this in a repeating command block:
/testfor @a[score_hasItem_min=1]
Execution
Using a comparator, run these commands when a player is found:
/clear @a[score_hasItem_min=1] minecraft:diamond_sword 0
/give @a[score_hasItem_min=1] minecraft:diamond_sword 1 1 {Unbreakable:1b}
/scoreboard players reset @a hasItem
Layout
Here is my layout: Where the commands are from 1 - 4:
/testfor @a[score_hasItem_min=1]
/clear @a[score_hasItem_min=1] minecraft:diamond_sword 0
/give @a[score_hasItem_min=1] minecraft:diamond_sword 1 1 {Unbreakable:1b}
/scoreboard players reset @a hasItem