Skip to content

AlmostReliable/lootjs

LootJS

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

Workflow Status License

Version Total Downloads CF Total Downloads MR

Discord Wiki

πŸ“‘ 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:

LootJS.modifiers((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:

LootJS.modifiers((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:

LootJS.modifiers((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.

LootJS.modifiers((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.

LootJS.modifiers((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"] {
        ❌ RandomChance
        βž₯ conditions are false. Stopping at AddLootAction
    }
    πŸ”§ "It's raining loot" {
        βœ”οΈ WeatherCheck
        βž₯ invoke ModifyLootAction
    }

πŸŽ“ License

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