How can I make every zombie that I kill spawns me one diamond?

I played on a Minecraft map which had this minigame arena mode where you get diamonds for killing each kind of mob. With these diamonds you were able to buy better equipment until you killed all the mobs, and then you moved to the next level. Is there a command for that? I'm playing Minecraft 1.14.


Solution 1:

The easiest way to do this is probably to set the loot table of every zombie to the loot table of diamond ore. You can do that by changing the DeathLootTable NBT data to the loot table that you want for that zombie. In this case that would be "blocks/diamond_ore". The command to change the DeathLootTable for every zombie looks like this:

/execute as @e[type=minecraft:zombie] run data modify entity @s DeathLootTable set value "blocks/diamond_ore"

I recommend using a repeating command block. Doing so will make zombies drop some experience and a single diamond, even with a looting 3 sword, or a fortune 3 pick axe.