How can I use the CanPlaceOn tag on a mob drop?
I am making an adventure map in 1.9 and while I know exactly how CanPlaceOn
works, I want to know how I can edit a drop of a mob which has a CanPlaceOn tag in it.
Example: I want to spawn a zombie which drops a lever or a button that can only be placed on certain blocks. Ive been messing with codes already and I cant seem to spawn a zombie which drops a lever with the CanPlaceOn tag in it.
Best Answer
Use a loot table
The best way to do this is using custom loot tables and the set_nbt function. The following loot_table makes a mob drop a single lever that can be placed on diamond blocks.
{
"pools":[
{
"rolls":1,
"entries":[
{
"type":"item",
"name":"minecraft:lever",
"weight":1,
"functions":[
{
"function":"set_nbt",
"tag":"{CanPlaceOn:[\"minecraft:diamond_block\"]}"
}
]
}
]
}
]
}
Loot tables look fairly complicated, but that's because they are extremely powerful and versatile (take a look at the default dungeon chest loot table for example). Luckily, you can find loot table generators like this one by MrPingouin on the web.
What happens here is that there is only one category of items (a "pool"), from which 1 item is randomly chosen ("rolls"). The pool only contains a single item ("entry"), which is our lever. The set_nbt function is used to set the NBT data of the lever to include the CanPlaceOn tag, set to diamond blocks.
Once you have generated your loot table, download it and save it in <map folder>/data/loot_tables/<some folder>/<some name>.json.
To use it in the game, you can use the DeathLootTable data tag in your summon command, e.g.
/summon Zombie ~ ~ ~ {DeathLootTable:"<some folder>:<some name>"}
Pictures about "How can I use the CanPlaceOn tag on a mob drop?"



How do you modify a mob drop?
Editing mob drops is as simple as editing the config file of the mod, config\\editmobdrops\\editmobdrops. cfg (in 1.7. 10 and 1.12. 2), or config\\editmobdrops\\editmobdrops.What is the rarest drop from a mob in Minecraft?
1) Slime balls from baby pandas Baby pandas are arguably the most adorable mob in Minecraft. They also have one of the rarest drops in the game. Baby pandas have a 0.00166% chance to drop slime balls upon sneezing.How do you make a mob not drop anything?
How to Disable Mobs Dropping Loot on your Minecraft ServerWhat is the most useful mob drop in Minecraft?
Top 5 mob item drops in Minecraft- 5) Iron Golem - Iron Ingots.
- 4) Enderman - Ender Pearls.
- 3) Shulker - Shulker Shells.
- 2) Blaze - Blaze Rods.
- 1) Wither - Nether Star.
Minecraft Tutorial Part 038 - CanPlaceOn and CanDestroy
More answers regarding how can I use the CanPlaceOn tag on a mob drop?
Answer 2
You don't have to do a loot table, you can use a command to choose what the mob drops.
/summon Zombie ~ ~1 ~ {CustomName:"ZombieNameHere",CustomNameVisible:1,IsVillager:0,ArmorItems:[{},{},{},{id:leather_helmet,Count:1,tag:{Unbreakable:1}}],HandItems:[{id:lever,Count:1,tag:{CanPlaceOn:["minecraft:diamond_block"],display:{Name:"LeverNameHere",Lore:[LeverLoreHere]}}},{}],ArmorDropChances:[0.085F,0.085F,0.085F,0.0F],HandDropChances:[1.0F,0.085F],PersistenceRequired:1} I also gave him a helmet just in case
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Anete Lusina, Andrea Piacquadio, Julia Avamotive, Erik Mclean
