I'm working on an adventure/RPG map where the player fights mobs, and I was wondering if you could change mob drops based on what armor the player has on. I know you can detect a certain type of armor on a player, but I have absolutely no idea how to change mob drops based on that (besides looting, which is not what I need.)

Said mobs are modified vanilla mobs that spawn from spawners. I don't know how to change these mobs' drops based on this armor, but I'm not sure if it's impossible/very hard/simple.

  • I don't think it's possible to dynamically change a mob's loot table like this. It could probably be done through some complex entitydata setup, but I don't know how well that would work. One common alternative method that I've seen maps use is giving the player new sets of spawners to farm from as the map progresses, so the player can simply abandon old spawners in favor of new ones with better gear. – Unionhawk Nov 26 '18 at 15:47
  • Firstly, please self-answer. This site exists also as a knowlesge base and your solution can help more people. Secondly, I think you can also make parts of a loot table dependent on the killing player's NBT, so you could even do it without modifying the mob during its lifetime. But I don't know how that works – Fabian Röling Nov 26 '18 at 16:06
  • Thanks for mentioning entitydata! I just tested out a prototype thing: – The Creepy Monkey Nov 26 '18 at 16:08

I managed to figure it out myself after someone else mentioned entitydata.

I used the following command on a loop:

/execute as @p
    run data merge entity @e[
                id:"minecraft:iron_chestplate",Count:1b,tag:{display:{Name:"{\"text\":\"This Thing Is Changed\"}"}}},{}]

If the person is wearing an iron chestplate, the data merge entity command will run, which modifies the chest slot of the closest zombie. Although this will change the essence of the mob by modifying its armor, it serves my purpose in that it does drop a different item when the player is wearing one. It will also only work for one zombie at a time, but unfortunately I couldn't find a way around that.

By running the command on a semi-loop-thing, you can modify the zombies in a certain area to drop different items/get changed. This can be used to buff mobs too - if you want to make a mob stronger while the player is wearing a certain item, then you can use data merge entity with your desired parameters (e.g. modify maxhealth, add an effect, change armor)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.