How to Change Drop Rates in Minecraft

In this post, we will share with you How to Change Drop Rates in Minecraft. So, read the article carefully to know the perfect way to Change Drop Rates in Minecraft.

How to Change Drop Rates in Minecraft

 

If You want to change what some crowd drops. If You want creatures to have a chance to drop bones, If you don’t want to exclude skeletons and zombies at all.

Also, sometimes If You want to play survival mode without worrying about a certain mob (like annoying ranged skeletons). I want to prevent them from breeding.

If you have no experience modifying Minecraft, If you are familiar with several scripting languages, and If you have the necessary IDEs to modify Minecraft’s source code. If you don’t want to create an in-game UI to change these values, you can go back to the source to modify the values ​​as you wish.

What files should match the entities I’m trying to modify (creatures, enemies, all mobs basically), and what values ​​should you change to change drop rates and spawn rates?

The packages you’re looking for are net.minecraft.entity.monster & net.minecraft.entity.passive.

Be aware though that jar modding is heavily incompatible, however modifying the drops can definitely be done without source code modding and probably spawn rate modification as well.

To prevent mob spawning you don’t need to edit the base class. There’s an event called CheckSpawn that fires before a mob spawns, which can be set to DENY to prevent spawning. There’s a thread here explaining how it’s done: Download

How Drops Are Controlled In the Code

The good news is that the drops list is a public ArrayList (of items) field in the Entity class and so it can be directly access and modified like any ArrayList.  The field is called capturedDrops.

However, it is not a static field or in a registry and so every instance of an Entity has its own capturedDrops list. So to modify all of an certain entity type, you’ll have to ensure that you modify the capturedDrops for each entity instance.

At What Point Should You Change The Drops

If we want to change the drops list we need to find the appropriate event — something that occurs after the entity has its capturedDrops list populated:
  • The EntityConstructing event isn’t a good place for changing the drops because the drops assignment seems to happen after the constructor.
  • The LivingSpawnEvent is also not a good choice because that can fire before the spawn even happens whether an entity instance is constructed or not.
In fact, the way the the capturedDrops list gets populated is a little bit complex — because some entities may have a dynamic inventory, the drops list is calculated at the time that the drop occurs (usually entity death/break).  So the only place you should really modify the drops is in the LivingDropsEvent. I know that seems sort of obvious, but I think it is worthwhile to also understand what doesn’t work and why.
Note: If you want to inspect the code where the vanilla drops list is populated, it is in the entityDropItem() method in the Entity class (and therefore inherited by all entities in the game), or in an overridden subclass.

Key point: The captureDrops list is populated at the time a drop happens (just before the LivingDropsEvent), so shouldn’t be modified earlier.

Handle LivingDropsEvent To Change The Drops

The capturedDrops list is passed as the event.drops field in the LivingDropsEvent.

The drops field is an ArrayList of Item class elements so (like any ArrayList) you can easily clear() it, remove() items, and add() items or use any other regular methods for modifying an ArrayList.

Tip: The LivingDropsEvent has a lootingLevel field that can be used to change drops based on looting bonus.  You can check the value of this field and drop different amounts or different items.

Example 1: Clear All Drops For EntitySheep

Create an event handler for the LivingDropsEvent.  Basically, you need a class containing the method example below that is registered to the EVENT_BUS.  To set that up see my tutorial on events:
The event handling method should contain something like this:
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(LivingDropsEvent event)
{
    if (event.entity instanceof EntitySheep)
    {
        // DEBUG
        System.out.println("EntitySheep drops event");
        event.drops.clear();
    }
} 

It is that simple.  Just clear the list and that will remove the drops.

Example 2: Change Drop For EntitySheep To Be 5 Apples

In this case, the event handling method should just add items after clearing it.

 

@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(LivingDropsEvent event)
{
    if (event.entity instanceof EntitySheep)
    {
        // DEBUG
        System.out.println("EntitySheep drops event");
        event.drops.clear();
        ItemStack itemStackToDrop = new ItemStack(Items.apple, 5);
        event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX,
              event.entity.posY, event.entity.posZ, itemStackToDrop));
    }
}

 

Conclusion

So, We have shared with you How to Change Drop Rates in Minecraft. If the Article has helpful then don’t forget to live a Comment.

Leave a Comment