In Minecraft, mobs drop various items upon death, and this loot plays a crucial role in progression and gameplay. By default, the loot tables for mobs are pre-configured, but what if you want to customize what a mob drops, either for a specific gameplay experience or for creating new mechanics within your modpack? This is where KubeJS comes into play.
KubeJS is a JavaScript-based mod that allows for powerful customization of Minecraft, including tweaking loot tables, recipes, world generation, and more. With KubeJS, modpack creators and players alike can easily change what mobs drop, whether it’s adding new items, modifying existing drops, or introducing completely new mechanics to make the game more interesting.
In this guide, we’ll walk through how to modify mob drops using KubeJS, explain the different ways you can interact with mob loot tables, and provide practical code examples and tips for creating custom mob loot systems.
Prerequisites
Before we begin, ensure you have the following prerequisites:
- Minecraft 1.16+ with KubeJS installed.
- A working knowledge of basic Minecraft modding concepts, including working with JavaScript and KubeJS scripts.
- A modding environment set up with access to the Minecraft server or client files.
Understanding Mob Loot Tables
In Minecraft, the loot that mobs drop is controlled by loot tables. These loot tables define what an entity drops upon death and can be configured to provide a variety of rewards, from basic items to rarer, more valuable drops.
KubeJS provides an easy-to-use interface to manipulate loot tables, but first, it’s essential to understand how loot tables are structured. By default, loot tables for mobs are located in the game’s data
folder (for vanilla mobs) or in the data
folder of mods that add custom mobs. Each loot table is a JSON file that defines the drops for that mob.
A basic loot table for a mob might look something like this:
In this example, the mob will drop either a stone sword or a gold ingot, based on the roll. Each “pool” contains one or more “entries” that define individual items.
With KubeJS, you can modify these loot tables dynamically, changing what items a mob drops.
Modifying Mob Loot with KubeJS
To modify mob drops in Minecraft using KubeJS, you will be interacting with the Loot
system via scripts. The easiest way to get started is by creating a script in your modpack’s scripts
folder. Here’s how to do it:
- Create a Script: In your Minecraft directory, navigate to
config/kubejs/server_scripts/
and create a new JavaScript file, for example,mobLoot.js
. - Write the Script: In this script, you’ll define the behavior of the mob drops using KubeJS’s API.
Basic Syntax for Loot Modifications
KubeJS provides an API called Loot
that allows you to modify existing loot tables or add new ones. Here is a basic example of how to change what a mob drops:
Explanation of the Code:
onEvent('loot.modify', event => { })
: This listens for when loot tables are being modified. Inside the callback function, you have access to theevent
object, which contains the loot tables that you can modify.event.modify("minecraft:entities/zombie", lootTable => { })
: This targets the loot table for zombies. You can change the"minecraft:entities/zombie"
to any mob type you wish to modify.lootTable.pools = []
: This clears any existing loot pools for the zombie. You might not always need this, but if you want to entirely replace the drops, this is the way to go.lootTable.addPool(pool => { })
: Adds a new loot pool to the loot table.pool.addEntry(entry => { })
: Adds an entry (drop item) to the loot pool. The entry specifies the item dropped (in this case, a diamond).
You can experiment with this basic code to add different drops, change drop weights, and modify other loot-related properties.
Advanced Loot Modifications
While basic loot changes like adding items are common, you can also make more advanced modifications. Here are a few examples of more complex loot customizations:
1. Adding Conditional Drops
You can add conditional drops based on whether the mob was killed by a player, by fire, or by another specific event. Here’s an example of a conditional drop:
In this example, the zombie will drop an enchanted book only if it was killed by a player. This is just one of many conditions that can be applied.
2. Modifying Drop Chances
You can also modify the chance of a particular drop occurring by setting the probability
property of the entry. This allows you to control the rarity of certain drops.
In this case, the skeleton has a 5% chance to drop a bow.
3. Adding Multiple Items in One Pool
You can add multiple items to a loot pool so that the mob has a chance to drop one of several items.
In this example, spiders will drop either string or spider eye. The game will randomly pick one of these items when the spider dies.
Integrating KubeJS with Other Mods
If you’re using other mods alongside KubeJS that add new mobs or loot tables, you can modify those as well. Here’s how you can target a loot table from a mod:
Simply replace 'modid:entities/my_custom_mob'
and 'modid:custom_item'
with the actual identifiers of the mob and item added by the mod you’re using.
Debugging and Testing
After making changes to loot tables using KubeJS, you’ll want to test your changes. Here’s how you can debug:
- Reload Scripts: In the game, use
/reload
to reload your scripts without restarting the game. - Check Loot Tables: Use
/loot
commands in Minecraft to see the current loot table for a mob. This can help you confirm that your changes are applied.
Conclusion
With KubeJS, modifying what mobs drop in Minecraft becomes a simple task. Whether you want to add custom loot, tweak drop rates, or add advanced conditional drops, the possibilities are vast. By writing a few lines of JavaScript, you can significantly alter the loot system of the game, making your Minecraft experience more customizable and exciting.
Remember, KubeJS allows for even deeper customization, and this guide only scratches the surface of what’s possible. Experiment with different conditions, probabilities, and new items to create the ultimate mob loot experience for your Minecraft world!