Adding Custom Drops to Vanilla Mobs

For this tutorial I will be removing the normal pig drops, and replacing them with a gold ingot (because I can). Let’s get to it, shall we?

First I’ll clarify we’ll be fiddling with forge’s event listeners, and these are great stuff to “modify” vanilla Minecraft, by intercepting vanilla events, hence the name. For this time, we will use the LivingDropsEvent event. If you want to check out other events, check them out here. It’s not mine, so kudos to anyone who made that.

Okay, let’s make the event handler class. Usually, for organization purposes I place this class in another seperate package, called “handler” (duh). I will be naming my class “MobDropsHandler”.

public class MobDropsHandler
{
    @SubscribeEvent
    public void onMobDrops(LivingDropsEvent event)
    {
        if (event.entity instanceof EntityPig)
        {
            event.drops.clear();

            ItemStack stack = new ItemStack(Items.gold_ingot);
            EntityItem drop = new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, stack);

            event.drops.add(drop);
        }
    }
}

Alright, simple as that. Note the @SubscribeEvent annotation. All event handler methods MUST have that, or forge won’t recognize it. The method name can be anything you want, I just used onMobDrops for clarity.

This event has fields for us to use, one of them being the entity, and another being the EntityItem list of the itemstacks dropped. We’ll make use of both. First we check if the entity is a pig, because that’s what we want. If it IS a pig, we then clear it’s default drops. You can omit the clear() method if you don’t want this. After that, we create an EntityItem of the ItemStack we want to output, with the world and position from the entity. Lastly, we add our custom EntityItem back into the drops ArrayList.

We’re done with this class! All we need to do is register this in your main mod class. In your loading method (preInit, init, or postInit all works), add the following line to register our event handler:

MinecraftForge.EVENT_BUS.register(new MobDropsHandler());

And we’re done! Go ahead and try it out.

14 thoughts on “Adding Custom Drops to Vanilla Mobs

  1. Gravity February 8, 2016 / 10:29 PM

    how can you set the rarity of the droped item?

    Like

      • drshaggy February 22, 2016 / 6:15 AM

        Could you elaborate please?

        Like

      • Emx2000 February 22, 2016 / 5:15 PM

        add setRarity(EnumRarity.RARE); to your constructor. (example)

        Like

  2. DrDoom_347 March 3, 2016 / 8:48 AM

    How would I make my item drop from a wither skeleton specifically? Like, what’s the syntax for specifying extra entity data?

    Like

    • Emx2000 March 4, 2016 / 7:26 PM

      you could add more if-checks:

      if (entity.getTagCompound().hasTag(“CustomName”) {}

      Like

      • ShadowCooper77 March 23, 2016 / 2:36 AM

        Help… i dont know where to put “add setRarity = (EnumRarity.RARE);” in… im a noob sry where is the constructor pls help also how do you change it so that the entity also drops what it usually drops as well as the item you want? Please respond

        Like

      • Emx2000 March 24, 2016 / 1:56 PM

        don’t use equals.
        “setRarity(EnumRarity.RARE);”
        put this in the constructor (the method without return type (public ClassName())

        Like

  3. ShadowCooper77 March 23, 2016 / 3:27 AM

    Also, what to do if i want to make my crafting recipe make more than one item?
    One more thing. I want my dye to be a blue dye but theres no blue_dye you can put. Pls senpai help

    Like

    • Emx2000 March 24, 2016 / 1:57 PM

      blue dye is a dye with a damage value. so, use:
      new ItemStack(Items.dye, 14);
      Check Minecraft Wiki for dye damage values.

      Like

  4. ShadowCooper77 March 24, 2016 / 10:26 PM

    I dont understand… This is what mine looks like. Can you copy it and show where to put it?

    package handler;

    import net.minecraft.entity.item.EntityItem;
    import net.minecraft.entity.passive.EntityPig;
    import net.minecraft.entity.passive.EntitySheep;
    import net.minecraft.init.Items;
    import net.minecraft.item.EnumRarity;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.event.entity.living.LivingDropsEvent;
    import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
    import net.minecraftforge.fml.common.registry.GameRegistry;
    import shadowCooper77.clothing.init.ClothingItems;

    public class MobDropsHandler {
    @SubscribeEvent
    public void onMobDrops(LivingDropsEvent event) {
    if (event.entity instanceof EntitySheep) {
    event.drops.clear();
    ItemStack stack = new ItemStack(ClothingItems.Cloth);
    EntityItem drop = new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, stack);
    event.drops.add(drop);
    }
    }
    }

    Like

    • Emx2000 March 25, 2016 / 12:50 PM

      I’m sorry I don’t quite get what you asked for. This is a correct class, so what are you asking?

      Like

      • ShadowCooper77 March 26, 2016 / 8:05 PM

        I am asking how to set rarity, i have no idea what you meant before

        Like

      • ShadowCooper77 March 29, 2016 / 9:08 PM

        um will you reply its been 3 days

        Liked by 1 person

Leave a reply to ShadowCooper77 Cancel reply