-
Notifications
You must be signed in to change notification settings - Fork 4
1.19.2 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.
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");
});
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");
});
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");
});
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");
});
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");
});
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");
});
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
.
LootJS.modifiers((event) => {
event
.addBlockLootModifier("minecraft:gravel")
.randomChance(0.3) // 30%
.addLoot("minecraft:diamond");
});
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");
});
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
*/
});
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");
});
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");
});
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");
});
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");
});
LootJS.modifiers((event) => {
event
.addBlockLootModifier("minecraft:gravel")
.lightLevel(0, 15)
.addLoot("minecraft:diamond");
});
LootJS.modifiers((event) => {
event
.addEntityLootModifier("minecraft:creeper")
.killedByPlayer()
.addLoot("minecraft:diamond");
});
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");
});
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");
});
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");
});
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");
});
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");
});
For the interval, use IntervalJS
.
LootJS.modifiers((event) => {
event
.addEntityLootModifier("minecraft:creeper")
.distanceToKiller(Interval.min(25))
.addLoot("minecraft:diamond");
});
Checks for player stages.
LootJS.modifiers((event) => {
event
.addEntityLootModifier("minecraft:pig")
.hasAnyStage("stoneage")
.addLoot("minecraft:coal");
});
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");
});
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");
});
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");
});
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");
});
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");
});
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");
});
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");
});
Adds a custom condition via json.
LootJS.modifiers((event) => {
event
.addBlockLootModifier("minecraft:gravel")
.customCondition({
condition: "minecraft:survives_explosion"
})
.addLoot("minecraft:diamond");
});