Skip to content

1.19.2 Conditions

LLytho edited this page Apr 12, 2023 · 1 revision

Intro

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.

Conditions

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.

LootJS.modifiers((event) => {
    event
        .addEntityLootModifier("minecraft:cow")
        .matchLoot("minecraft:leather")
        .addLoot("minecraft:carrot");
});

matchMainHand(ItemFilter)

Matching the players' main hand by the given ItemFilter.

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

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

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

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

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

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

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

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

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

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

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

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

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

lightLevel(min, max)

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

killedByPlayer()

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

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

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

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

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

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

distanceToKiller(interval)

For the interval, use IntervalJS.

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

hasAnyStage(...stages)

Checks for player stages.

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

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

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

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

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

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

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

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

LootJS.modifiers((event) => {
    event
        .addBlockLootModifier("minecraft:gravel")
        .customCondition({
            condition: "minecraft:survives_explosion"
        })
        .addLoot("minecraft:diamond");
});