Skip to content
LLytho edited this page Oct 4, 2023 · 1 revision

Event

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.

onEvent("lootjs", (event) => {
    // your code
});

addBlockLootModifier(...blocks)

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

onEvent("lootjs", (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.

onEvent("lootjs", (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.

onEvent("lootjs", (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.

onEvent("lootjs", (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

onEvent("lootjs", (event) => {
    event.disableWitherStarDrop();
    event.disableCreeperHeadDrop();
    event.disableSkeletonHeadDrop();
    event.disableZombieHeadDrop();
});

enableLogging()

Enables the log output.

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

getGlobalModifiers() FORGE ONLY

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

onEvent("lootjs", (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.

onEvent("lootjs", (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.

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

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

Actions

Actions are used to change the current loot pool outcome or to trigger effects. You can simply chain multiple actions together. For every Loot Modification, you need at least one action.

addLoot(...items)

Adds one or multiple items to the current loot pool.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").addLoot("minecraft:flint");
});

addWeightedLoot(NumberProvider, [...items]) or addWeightedLoot([...items])

Adds one or multiple items with weights to the current loot pool. If a NumberProvider is given, it will roll multiple items based on it.

Example: [3, 10] is the number provider with 3 min and 10 max rolls. LootJS will randomly select a value between min and max.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .addWeightedLoot(
            [3, 10],
            [Item.of("minecraft:gunpowder").withChance(50), Item.of("minecraft:nether_star").withChance(5)]
        );
});

You can also use a number only which is then treated as [n, n].

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .addWeightedLoot(5, [
            Item.of("minecraft:gunpowder").withChance(50),
            Item.of("minecraft:nether_star").withChance(5),
        ]);
});

If you don't use a number provider, it's equal to [1, 1].

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .addWeightedLoot([
            Item.of("minecraft:gunpowder").withChance(50),
            Item.of("minecraft:nether_star").withChance(5),
        ]);
});

removeLoot(ItemFilter)

Removes all items from the current loot pool which matches the given ItemFilter.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").removeLoot("minecraft:flint");
});

replaceLoot(ItemFilter, item) or replaceLoot(ItemFilter, item, preserveCount)

Replaces all items from the current loot pool which match the given ItemFilter.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").replaceLoot("minecraft:flint", "minecraft:diamond");
    // or .replaceLoot("minecraft:flint", "minecraft:diamond", true) if you want to preserve the stack size
});

In this example, we want to replace flint with diamonds in the gravel loot pool.

modifyLoot(ItemFilter, callback)

For every item in the current loot pool which matches the given ItemFilter, a callback will be called. LootJS will pass the item into the callback to modify it and return the item. Make sure to always return an item.

onEvent("lootjs", (event) => {
    event
        .addLootTypeModifier(LootType.ENTITY)
        .weatherCheck({
            raining: true,
        })
        .modifyLoot(Ingredient.getAll(), (itemStack) => {
            itemStack.setCount(itemStack.getCount() * 2);
            return itemStack;
        });
});

In this example, we will double all loot when it's raining.

triggerExplosion(radius, destroy, fire)

Triggers an explosion on the position where the loot will be dropped. The items will not be destroyed. The radius can be any number. For destroy and fire you can pass true or false.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").triggerExplosion(1, false, false);
});

triggerLightningStrike(shouldDamage)

Triggers a lightning strike on the position where the loot will be dropped. The items will not be destroyed. Use true or false for shouldDamage.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").triggerLightningStrike(false);
});

pool(callback)

Roll a dynamic created pool. The callback provides a pool you can work with. If an NumberProvider is given through .rolls(), it will roll the pool multiple times.

Example: [1, 3] is the number provider with 3 min and 10 max rolls. LootJS will randomly select a value between min and max.

onEvent("lootjs", (event) => {
    event.addEntityLootModifier("minecraft:creeper").pool((pool) => {
        pool.rolls([1, 3]);
        pool.randomChance(0.3)
            .or((or) => {
                or.anyBiome("minecraft:jungle");
                or.lightLevel(0, 7);
            })
            .addLoot("minecraft:diamond");
    });
});

playerAction(callback)

Use playerAction to trigger custom actions to a player. The callback provides you the vanilla player, not the PlayerJS class from KubeJS.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:diamond_block").playerAction((player) => {
        player.giveExperiencePoints(100);
    });
});

apply(callback)

With apply, you apply a custom callback onto the current loot pool. LootJS will provide you the LootContextJS.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").apply((context) => {
        // do whatever you like
        // example: context.level to access the level
    });
});

Conditions

Besides Actions, you can use conditions to apply filters.
If a condition fails, no actions will be triggered after the failing condition. You also can chain multiple conditions to apply more filters to your loot modifier.

matchLoot(ItemFilter, exact)

Matching the loot pool by the given ItemFilter.
exact is optional and does not need to be passed. The default value is false. If exact is true, all items in the current loot pool need to match the ItemFilter.

onEvent("lootjs", (event) => {
    event.addEntityLootModifier("minecraft:cow").matchLoot("minecraft:leather").addLoot("minecraft:carrot");
});

matchMainHand(ItemFilter)

Matching the players' main hand by the given ItemFilter.

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("#forge:ores")
        .matchMainHand(Item.of("minecraft:netherite_pickaxe").ignoreNBT())
        .addLoot("minecraft:gravel");
});

matchOffHand(ItemFilter)

Matching the players' off hand by the given ItemFilter.

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("#forge:ores")
        .matchOffHand(Item.of("minecraft:netherite_pickaxe").ignoreNBT())
        .addLoot("minecraft:gravel");
});

matchEquip(slot, ItemFilter)

Matching the players' equipment slot by the given ItemFilter.

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("#forge:ores")
        .matchEquip(EquipmentSlot.MAINHAND, Item.of("minecraft:netherite_pickaxe").ignoreNBT())
        .addLoot("minecraft:gravel");
});

survivesExplosion()

Returns true if the destroyed block would survive an explosion. This condition doesn't invoke an explosion.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").survivesExplosion().addLoot("minecraft:gravel");
});

timeCheck(period, min, max) & timeCheck(min, max)

Checks for the game time which is the age of the world in-game ticks.

From Minecraft Wiki: period-> "If present, the game time is first reduced modulo the given number before being checked against. Setting this to 24000 causes the checked time to be equal to the current daytime."

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .timeCheck(24000, 0, 9000) // good morning
        .addLoot("minecraft:diamond");
});

weatherCheck(value)

Checks if the current weather is rain and/or thunder.

Value syntax:

{
    raining: true, // or false
    thundering: true // or false
}

If you just use one, the other one will be ignored.

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .weatherCheck({
            raining: true,
        })
        .addLoot("minecraft:diamond");
});

If you want to check for clear weather, set both values to false.

randomChance(value)

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .randomChance(0.3) // 30%
        .addLoot("minecraft:diamond");
});

randomChanceWithLooting(value, looting)

Random chance with a looting multiplier. More on Minecraft Wiki.

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .randomChanceWithLooting(0.3, 2) // 30%
        .addLoot("minecraft:diamond");
});

randomChanceWithEnchantment(enchantment, [chances])

Random chance with enchantment. More on Minecraft Wiki for table_bonus.

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .randomChanceWithEnchantment("minecraft:looting", [0, 0.1, 0.5, 1])
        .addLoot("minecraft:diamond");

    /*
        [0, 0.1, 0.5, 1]:
          0% for no looting
         10% for looting 1
         50% for looting 2
        100% for looting 3
    */
});

biome(...biomes)

Checks for given biomes. If multiple biomes given, all biomes must match. With the prefix #, you can pass biome tags, so it's possible to check if a biome is #minecraft:is_forest for example.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").biome("minecraft:jungle").addLoot("minecraft:diamond");
});

anyBiome(...biomes)

Checks for given biomes. If multiple biomes are given, at least one biome must match. With the prefix #, you can pass biome tags, so it's possible to check if a biome is #minecraft:is_forest for example.

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .anyBiome("minecraft:jungle", "#minecraft:is_forest")
        .addLoot("minecraft:diamond");
});

anyDimension(...dimensions)

Checks for given dimensions. If multiple dimensions are given, at least one dimension must match.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").anyDimension("minecraft:nether").addLoot("minecraft:diamond");
});

anyStructure([structures], exact)

Checks for given structures. You have to pass the structures as an array-like.

If exact is true, it will check if the player is inside the structure parts (like houses in a village).
If exact is false, it will just check if the player is within the structure bounds.

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .anyStructure(["minecraft:stronghold", "minecraft:village"], false)
        .addLoot("minecraft:diamond");
});

lightLevel(min, max)

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:gravel").lightLevel(0, 15).addLoot("minecraft:diamond");
});

killedByPlayer()

onEvent("lootjs", (event) => {
    event.addEntityLootModifier("minecraft:creeper").killedByPlayer().addLoot("minecraft:diamond");
});

matchEntity(callback)

Matches against the entity that died, opened the chest or destroyed the block. LootJS will provide EntityPredicateBuilderJS in your callback to match against the entity.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .matchEntity((entity) => {
            // Your code. Check EntityPredicateBuilderJS for more information
        })
        .addLoot("minecraft:diamond");
});

matchDirectKiller(callback)

Matches against the direct entity which caused the death, e.g. the arrow entity, not the shooter. LootJS will provide EntityPredicateBuilderJS in your callback to match against an entity.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .matchDirectKiller((entity) => {
            // Your code. Check EntityPredicateBuilderJS for more information
        })
        .addLoot("minecraft:diamond");
});

matchKiller(callback)

Matches against the entity which caused the death. LootJS will provide EntityPredicateBuilderJS in your callback to match against an entity.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .matchKiller((entity) => {
            // Your code. Check EntityPredicateBuilderJS for more information
        })
        .addLoot("minecraft:diamond");
});

matchPlayer(callback)

Matches against the player. If a player kills another player, it will check against the killer. LootJS will provide EntityPredicateBuilderJS in your callback to match against an entity.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .matchPlayer((player) => {
            // Your code. Check EntityPredicateBuilderJS for more information
        })
        .addLoot("minecraft:diamond");
});

matchDamageSource(callback)

Matches against the damage source. LootJS will provide DamageSourcePredicateBuilderJS in your callback to check against.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .matchDamageSource((source) => {
            // Your code. Check DamageSourcePredicateBuilderJS for more information
        })
        .addLoot("minecraft:diamond");
});

distanceToKiller(interval)

For the interval, use IntervalJS.

onEvent("lootjs", (event) => {
    event.addEntityLootModifier("minecraft:creeper").distanceToKiller(Interval.min(25)).addLoot("minecraft:diamond");
});

hasAnyStage(...stages)

Checks for player stages.

onEvent("lootjs", (event) => {
    event.addEntityLootModifier("minecraft:pig").hasAnyStage("stoneage").addLoot("minecraft:coal");
});

playerPredicate(callback)

Custom callback predicate to check the player. The callback must return either true or false.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:pig")
        .playerPredicate((player) => player.getHealth() > 5)
        .addLoot("minecraft:emerald");
});

entityPredicate(callback)

Custom callback predicate to check the entity. The callback must return either true or false.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:pig")
        .entityPredicate((entity) => entity.type == "minecraft:pig")
        .addLoot("minecraft:diamond");
});

killerPredicate(callback)

Custom callback predicate to check the killer. The callback must return either true or false.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:pig")
        .killerPredicate((entity) => entity.type == "minecraft:pig")
        .addLoot("minecraft:feather");
});

directKillerPredicate(callback)

Custom callback predicate to check the direct killer. The callback must return either true or false.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:pig")
        .directKillerPredicate((entity) => entity.type == "minecraft:pig")
        .addLoot("minecraft:stone");
});

not(callback)

Add a condition through the callback which will be negated.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .not((n) => {
            n.biome("minecraft:jungle");
        })
        .addLoot("minecraft:diamond");
});

or(callback)

Add multiple conditions through the callback which will return true when at least one condition returns true.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .or((or) => {
            or.biome("minecraft:jungle").anyDimension("minecraft:nether");
        })
        .addLoot("minecraft:diamond");
});

and(callback)

Add multiple conditions through the callback which will return true when all conditions return true.

onEvent("lootjs", (event) => {
    event
        .addEntityLootModifier("minecraft:creeper")
        .and((and) => {
            and.biome("minecraft:jungle").distanceToKiller(Interval.min(25));
        })
        .addLoot("minecraft:diamond");
});

customCondition(json)

Adds a custom condition via json.

onEvent("lootjs", (event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .customCondition({
            condition: "minecraft:survives_explosion",
        })
        .addLoot("minecraft:diamond");
});

Functions

Loot functions help you to transform items before they will be dropped. If you ever worked with vanilla loot tables, you will be familiar with them.

enchantRandomly() or enchantRandomly(...enchantments)

Randomly enchants the item. You can provide enchantments to choose from.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:diamond_axe");
        p.enchantRandomly();
    });
});

enchantWithLevels(NumberProvider) or enchantWithLevels(NumberProvider, allowTreasure)

Randomly enchants with specific levels. Roughly equivalent to using an enchantment table. allowTreasure can be true or false if treasure items are allowed.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:diamond_pickaxe");
        p.enchantWithLevels([2, 4]);
    });
});

applyLootingBonus(NumberProvider)

Adjusts the item stack size based on the looting enchantment level the killer has.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:emerald");
        p.applyLootingBonus([1, 3]);
    });
});

applyBinomialDistributionBonus(enchantment, probability, n)

Adjusts the item stack size based on a binomial distribution bonus.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:emerald");
        p.applyBinomialDistributionBonus("minecraft:fortune", 0.2, 3);
    });
});

applyOreBonus(enchantment)

Adjusts the item stack size based on ore bonus. Used to simulate fortune effect.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:emerald");
        p.applyOreBonus("minecraft:fortune");
    });
});

applyBonus(enchantment, multiplier)

Adjusts the item stack size based on a multiplier.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:emerald");
        p.applyBonus("minecraft:fortune", 3);
    });
});

simulateExplosionDecay()

Removes some items from the stack if there was an explosion.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot(Item.of("minecraft:emerald", 50));
        p.simulateExplosionDecay();
    });
});

smeltLoot()

Smelts the loot if possible. Can be used to simulate fire aspect. The example uses functions() to apply an ItemFilter.

onEvent("lootjs", (event) => {
    event.addEntityLootModifier("minecraft:chicken").functions(Item.of("chicken"), (f) => {
        f.smeltLoot();
    });
});

damage(NumberProvider)

Damages the item by friction between 0 and 1 where 0 is zero durability.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:netherite_sword");
        p.damage([0.3, 0.9]);
    });
});

addPotion(potion)

Applies the potion nbt to the item.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:potion");
        p.addPotion("poison");
    });
});

limitCount(NumberProvider, NumberProvider)

Limits the stack size against the given number providers, where the first provider stands for min and the second one for max.

The following example will limit the stack size to at least 5 - 10 and max 30 - 64.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:diamond");
        p.limitCount([5, 10], [30, 64]);
    });
});

addAttributes(callback)

Add attribute modifiers to the item. In the callback, you can use multiple functions to add attributes. probability can be used to have a random chance the attribute will be applied.

If using simple, it will use the default equipment slot for the item.

  • simple(attribute, NumberProvider)
  • simple(probability, attribute, NumberProvider)
  • forSlots(attribute, NumberProvider, ...slots)
  • forSlots(probability, attribute, NumberProvider, ...slots)

Possible attributes:

  • generic.max_health
  • generic.follow_range
  • generic.knockback_resistance
  • generic.movement_speed
  • generic.flying_speed
  • generic.attack_damage
  • generic.attack_knockback
  • generic.attack_speed
  • generic.armor
  • generic.armor_toughness
  • generic.luck
onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:diamond_sword");
        p.addAttributes((attributes) => {
            attributes.simple("generic.max_health", 1);
            attributes.simple(0.99, "generic.max_health", 2);
            attributes.forSlots("generic.max_health", 3, [SLOT_MAINHAND]);
            attributes.forSlots(0.99, "generic.max_health", 4, [SLOT_OFFHAND]);
        });
    });
});

addLore(...components)

Adds lore to the item. Can be used for some custom tooltips. You can use any Text.of(...) notation from KubeJS or just simple strings. You can also pass multiple components if you need multiple lines.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("");
        p.addLore(["This is a lore", Text.red("This is a red lore")]);
    });
});

replaceLore(...components)

Replaces the current item lore.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("");
        p.replaceLore(Text.of("Some lore text for your item"));
    });
});

setName(component)

Sets the item's custom name.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:emerald");
        p.setName(Text.blue("This is a blue name"));
    });
});

addNBT(nbt) or addNbt(nbt)

Adds nbt to the item.

onEvent("lootjs", (event) => {
    event.addBlockLootModifier("minecraft:emerald_block").pool((p) => {
        p.addLoot("minecraft:iron_sword");
        p.addNBT({ Damage: 20 });
    });
});

functions(ItemFilter, callback)

Can be used to apply one or multiple functions to a specific ItemFilter. As a function will be applied to all items in the current pool, this or pools can be used to scope them.

onEvent("lootjs", (event) => {
    event.addEntityLootModifier("minecraft:chicken").functions(ItemFilter.FOOD, (f) => {
        f.smeltLoot();
    });
});

Types

Equipment Slots

EquipmentSlot.MAINHAND
EquipmentSlot.OFFHAND
EquipmentSlot.FEET
EquipmentSlot.LEGS
EquipmentSlot.CHEST
EquipmentSlot.HEAD

Loot Types

LootType.UNKNOWN
LootType.BLOCK
LootType.ENTITY
LootType.CHEST
LootType.FISHING
LootType.GIFT

LootContextJS

Holds information for the current loot drop. Is mostly used for .apply().

getType()

Returns the LootType.

getPosition()

getEntity()

Returns an EntityJS or null if no entity exists for the context.

getKillerEntity()

Returns an EntityJS for the killer or null if no entity exists for the context.

getPlayer()

Returns a PlayerJS or null if no player exists for the context. An example of null would be when a Skeleton shoots a Creeper.

getDamageSource()

Returns a DamageSourceJS or null if no source exists.

getTool()

Returns an ItemStackJS for the tool. If no tool exists in the context, it will return an empty item.

getDestroyedBlock()

Returns a BlockContainerJS for block loot. Will be null for every other loot type.

isExploded()

Returns true if the loot drop happens by an explosion.

getExplosionRadius()

Returns the explosion radius. If isExploded() returns false, the radius is 0.

getLevel()

Returns the LevelJS.

getServer()

Returns the ServerJS.

getLuck()

getLooting()

lootSize()

addLoot(item)

removeLoot(ItemFilter)

findLoot(ItemFilter)

hasLoot(ItemFilter)

forEachLoot(callback)

Iterates over each item and calls the given callback for it.

// callback example
const callback = (item) => {
    console.log(item);
};

EntityPredicateBuilderJS

anyType(...types)

Entity tags can also be passed when using # as a prefix. Example: #skeletons.

isOnFire(flag)

isCrouching(flag)

isSprinting(flag)

isSwimming(flag)

isBaby(flag)

isInWater(flag)

isUnderWater(flag)

isMonster(flag)

isCreature(flag)

isOnGround(flag)

isUndeadMob(flag)

isArthropodMob(flag)

isIllegarMob(flag)

isWaterMob(flag)

hasEffect(effect, amplifier) & hasEffect(effect)

nbt(json)

matchMount(callback)

Matching the mount for the current entity. LootJS provides an EntityPredicateBuilderJS for the callback.

onEvent("lootjs", (event) => {
    event
        .addLootTypeModifier([LootType.ENTITY])
        .matchEntity((entity) => {
            entity.anyType("#skeletons");
            entity.matchMount((mount) => {
                mount.anyType("minecraft:spider");
            });
        })
        .addLoot("minecraft:magma_cream");
});

This example shows a Skeleton riding a Spider, also known as a spider jockey.

matchTargetedEntity(callback)

Matching the targeted entity for the current entity. LootJS provides a EntityPredicateBuilderJS for the callback.

matchSlot(slot, ItemFilter)

Returns true if the slot contains the specified ItemFilter.

DamageSourcePredicateBuilderJS

anyType(...types)

Returns true if at least one type matches. Possible types are: "inFire", "lightningBolt", "onFire", "lava", "hotFloor", "inWall", "cramming", "drown", "starve", "cactus", "fall", "flyIntoWall", "outOfWorld", "generic", "magic", "wither", "anvil", "fallingBlock", "dragonBreath", "dryout", "sweetBerryBush" and there might be more types added by other mods.

isProjectile(flag)

isExplosion(flag)

doesBypassArmor(flag)

doesBypassInvulnerability(flag)

doesBypassMagic(flag)

isFire(flag)

isMagic(flag)

isLightning(flag)

matchDirectEntity(callback)

Matching the direct entity. LootJS provides a EntityPredicateBuilderJS for the callback.

matchSourceEntity(callback)

Matching the source entity. LootJS provides a EntityPredicateBuilderJS for the callback.

ItemFilters

ItemFilters can be used as filters for different functions in LootJS. Though everywhere where ItemFilter is needed, you can also use the KubeJS methods Item.of() and Ingredient.of().

ItemFilter additionally supports these quick filters:

  • ItemFilter.ALWAYS_FALSE
  • ItemFilter.ALWAYS_TRUE
  • ItemFilter.SWORD
  • ItemFilter.PICKAXE
  • ItemFilter.AXE
  • ItemFilter.SHOVEL
  • ItemFilter.HOE
  • ItemFilter.TOOL
  • ItemFilter.POTION;
  • ItemFilter.HAS_TIER;
  • ItemFilter.PROJECTILE_WEAPON
  • ItemFilter.ARMOR;
  • ItemFilter.WEAPON;
    • Matches all swords, tools, trident and projectile weapons
  • ItemFilter.HEAD_ARMOR
  • ItemFilter.CHEST_ARMOR
  • ItemFilter.LEGS_ARMOR
  • ItemFilter.FEET_ARMOR
  • ItemFilter.FOOD
  • ItemFilter.DAMAGEABLE
  • ItemFilter.DAMAGED
  • ItemFilter.ENCHANTABLE
  • ItemFilter.ENCHANTED
  • ItemFilter.BLOCK
    • Matches if the item can be placed as block
  • ItemFilter.hasEnchantment(enchantment, minLevel, maxLevel) & ItemFilter.hasEnchantment(enchantment)
    • Check if an item has an enchantment

NumberProvider

NumberProvider is a vanilla object which gets type wrapped by KubeJS. If a function takes a number provider, you can pass a simple number to use a constant value, an array with a min and a max value [min, max] -> [3, 10] or if you want to have a binomial distribution, you can use { n: a, p: b} -> { n: 3, p: 0.5 }.

Clone this wiki locally