Question

Can you change what a mob drops in KubeJS?

Answer and Explanation

Yes, you absolutely can change what a mob drops in KubeJS! KubeJS is a powerful mod for Minecraft that allows you to customize various aspects of the game, including mob drops, using JavaScript.

Here's how you can achieve this:

1. Understanding the KubeJS Scripting Environment:

- KubeJS uses JavaScript to define custom behaviors. You'll typically create a `.js` file within the `kubejs/server_scripts` directory of your Minecraft instance.

2. Using the `entity.loot` Event:

- The primary way to modify mob drops is by using the `entity.loot` event. This event is triggered whenever an entity is killed and is about to drop loot.

3. Example Code to Modify Mob Drops:

onEvent('entity.loot', event => {
  // Check if the entity is a Zombie
  if (event.entity.type == 'minecraft:zombie') {
    // Clear all default drops
    event.drops.clear();
    // Add a custom drop (e.g., a diamond)
    event.add('minecraft:diamond');
    // Add a custom drop with a specific quantity (e.g., 2 iron ingots)
    event.add('minecraft:iron_ingot', 2);
  }
  // Check if the entity is a Skeleton
  if (event.entity.type == 'minecraft:skeleton') {
    // Remove a specific drop (e.g., bones)
    event.remove('minecraft:bone');
    // Add a different drop (e.g., an arrow)
    event.add('minecraft:arrow', 3);
  }
});

4. Explanation of the Code:

- `onEvent('entity.loot', event => { ... });` sets up the event listener for entity loot drops.

- `event.entity.type` gets the type of the entity (e.g., 'minecraft:zombie').

- `event.drops.clear();` removes all default drops from the entity.

- `event.add('minecraft:diamond');` adds a diamond to the drops.

- `event.add('minecraft:iron_ingot', 2);` adds two iron ingots to the drops.

- `event.remove('minecraft:bone');` removes bones from the drops.

5. Important Considerations:

- You can use the `event.entity.type` to target specific mobs.

- You can add items from any mod, not just vanilla Minecraft.

- You can use conditional logic to make drops more complex (e.g., based on the player's level or the time of day).

- Remember to reload your KubeJS scripts using `/kubejs reload` in-game after making changes.

By using the `entity.loot` event in KubeJS, you have full control over what mobs drop, allowing for highly customized and unique gameplay experiences.

More questions