0

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.

  • can you use the entity data to modify the dropped lever – Haroun Mohamed-Fakier Jun 13 '16 at 9:21
  • @HarounMohamed-Fakier possible, but fairly complicated. You'd have to track the mob, check if it died, and then apply entitydata at its position. – MrLemon Jun 13 '16 at 10:03
2

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>"}
  • 1
    For a feature-complete generator, though not nearly as visually pleasing/friendly, there is this one from MrPingouin1 (which includes the new limit tag for the looting_enchant function from 1.10). The mincraft.tools generator is outdated and missing a large amount of features, including major ones such as multiple pools. – Skylinerw Jun 13 '16 at 19:54
0

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

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.