/lootjs

A Minecraft mod for packdevs to easily modify the loot system with KubeJS.

Primary LanguageJavaGNU Lesser General Public License v3.0LGPL-3.0

LootJS

A Minecraft mod for packdevs to easily modify the loot system with KubeJS.

Version Total Downloads CF Total Downloads MR Workflow Status License

Discord | CurseForge | Modrinth

📑 Overview

This is a mod for Minecraft-Forge and Fabric and needs KubeJS.

🔧 Installation

  1. Download the latest mod jar from the releases, from CurseForge or from Modrinth.
  2. Download the latest mod jar of KubeJS.
  3. Install Minecraft Forge or Fabric.
  4. Drop both jar files into your mods folder.

✏️ Your first loot modification

Loot modifications are handled server side. So all your scripts will go into your your_minecraft_instance/kubejs/server_scripts directory. Just create a .js file and let's get started.

Here's simple example which adds a gunpowder for creepers:

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .randomChance(0.3) // 30% chance
        .thenAdd("minecraft:gunpowder");
});

Instead of using a loot table for reference, you can also apply the modification to all entities:

onEvent("lootjs", (event) => {
    event
        .addLootTypeModifier(LootType.ENTITY) // you also can use multiple types
        .logName("It's raining loot") // you can set a custom name for logging
        .weatherCheck({
            raining: true,
        })
        .thenModify(Ingredient.getAll(), (itemStack) => {
            // you have to return an item!
            return itemStack.withCount(itemStack.getCount() * 2);
        });
});

Next, let's check if the player holds a specific item:

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("#forge:ores") // keep in mind this is a block tag not an item tag
        .matchEquip(EquipmentSlot.MAINHAND, Item.of("minecraft:netherite_pickaxe").ignoreNBT())
        .thenAdd("minecraft:gravel");

    // for MainHand and OffHand you can also use:
    // matchMainHand(Item.of("minecraft:netherite_pickaxe").ignoreNBT())
    // matchOffHand(Item.of("minecraft:netherite_pickaxe").ignoreNBT())
});

⚙️ More Information

For more information about the usage and the functionality of the mod, please visit our wiki or explore the examples.

❌ Disable loot tables for loot modifications (Forge only)

Some blocks like leaves are getting randomly destroyed. If you don't want them to trigger your loot modifications, you can disable their loot tables. The default loot tables will still be triggered.

onEvent("lootjs", (event) => {
    // all leaves disabled via regex
    event.disableLootModification(/.*:blocks\/.*_leaves/);

    // disable bats
    event.disableLootModification("minecraft:entities/bat");
});

📜 Enable logging for loot modifications

With a lot of modifications, it can be hard to track which modification triggers on specific conditions. With enableLogging, LootJS will log every modification trigger into your_minecraft_instance/logs/kubejs/server.txt.

onEvent("lootjs", (event) => {
    event.enableLogging();
});

Here's the output for the additional gunpowder and raining loot examples:

[ Loot information ]
    LootTable    : "minecraft:entities/creeper"
    Loot Type    : ENTITY
    Current loot :
    Position     : (151.86, 80.00, -264.23)
    Entity       : Type="minecraft:creeper", Id=378, Dim="minecraft:overworld", x=151.86, y=80.00, z=-264.23
    Killer Entity: Type="minecraft:player", Id=122, Dim="minecraft:overworld", x=152.52, y=80.00, z=-262.85
    Direct Killer: Type="minecraft:player", Id=122, Dim="minecraft:overworld", x=152.52, y=80.00, z=-262.85
    Player       : Type="minecraft:player", Id=122, Dim="minecraft:overworld", x=152.52, y=80.00, z=-262.85
    Player Pos   : (152.52, 80.00, -262.85)
    Distance     : 1.53
    MainHand     : 1 netherite_sword {Damage:0}
[ Modifications ]
    🔧 LootTables["minecraft:entities/creeper"] {
        ❌ RandomChanceconditions are false. Stopping at AddLootAction
    }
    🔧 "It's raining loot" {
        ✔️ WeatherCheckinvoke ModifyLootAction
    }

🎓 License

This project is licensed under the GNU Lesser General Public License v3.0.