Skip to content

1.19.2 Event

Relentless edited this page May 6, 2024 · 2 revisions

Intro

LootJS provides the lootjs KubeJS event to create your loot modifications or for other stuff. The event is server-sided and can be reloaded by invoking /reload.
To learn more about KubeJS events, please refer to their wiki.

LootJS.modifiers((event) => {
    // your code
});

Functions

addBlockLootModifier(...blocks)

Adds a new loot modifier for blocks.
The function returns a builder object so you can add conditions and actions.

LootJS.modifiers((event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .randomChance(0.3)
        .addLoot("minecraft:gunpowder");
});

addEntityLootModifier(...entities)

Adds a new loot modifier for entities.
The function returns a builder object so you can add conditions and actions.

LootJS.modifiers((event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .addLoot("minecraft:gunpowder");
});

addLootTableModifier(...values)

Adds a new loot modifier for loot tables. You can use multiple loot table ids or use a regular expression for values.
The function returns a builder object so you can add conditions and actions.

LootJS.modifiers((event) => {
    // by id
    event
        .addLootTableModifier("minecraft:entities/creeper")
        .randomChance(0.3)
        .addLoot("minecraft:gunpowder");

    // by regular expression
    event
        .addLootTableModifier(/.*creeper.*/)
        .randomChance(0.3)
        .addLoot("minecraft:gunpowder");
});

addLootTypeModifier(...types)

Adds a new loot modifier for a loot type. You can also use multiple LootType's for types.
The function returns a builder object so you can add conditions and actions.

LootJS.modifiers((event) => {
    event
        .addLootTypeModifier(LootType.ENTITY) // or multiple LootType.BLOCK, LootType.ENTITY ...
        .randomChance(0.3)
        .addLoot("minecraft:gravel");
});

Disable wither nether star drop and mob head drops

LootJS.modifiers(event => {
    event.disableWitherStarDrop()
    event.disableCreeperHeadDrop()
    event.disableSkeletonHeadDrop()
    event.disableZombieHeadDrop()
})

enableLogging()

Enables the log output.

LootJS.modifiers((event) => {
    event.enableLogging();
});

getGlobalModifiers() FORGE ONLY

Returns a list of all registered global loot modifiers from other mods.

LootJS.modifiers((event) => {
    const modifiers = event.getGlobalModifiers();
    modifiers.forEach((modifier) => {
        console.log(modifier)
    });
});

removeGlobalModifier(...values) FORGE ONLY

Remove one or multiple global loot modifiers from other mods. Can be used to prevent mods from adding their own loot through global loot. This will not work if the mod adds their items directly into the loot tables.
You can pass multiple loot tables or mod ids.

LootJS.modifiers((event) => {
    event.removeGlobalModifier("examplemod:example_loot_change"); // by location
    event.removeGlobalModifier("@examplemod"); // by mod id. Use `@` as prefix
});

disableLootModification(...values) FORGE ONLY

Disables the loot modification for given values.
values can be resource locations for the loot table or a regular expression.

LootJS.modifiers((event) => {
    // all leaves disabled via regex
    event.disableLootModification(/.*:blocks\/.*_leaves/);
    
    // disable bats
    event.disableLootModification("minecraft:entities/bat");
});