Conditions

loottweaker.vanilla.loot.Conditions

JSON can be verbose and difficult to write. This type can help. It provides methods for creating simple loot conditions, but if you wish to use complex loot conditions you still have to write them in JSON. minecraft:entity_properties and minecraft:entity_scores do not have helper methods as they are too complex.

All methods on this page, except parse() create a vanilla loot condition, so their parameters are equivalent to the parameters of the equivalent loot condition. All vanilla loot conditions are listed and documented here.

The corresponding type for loot functions is Functions.

Methods

See here for an explanation of the method documentation format used on this page.

static LootCondition randomChance(float chance)
Equivalent to:

minecraft:random_chance

import loottweaker.vanilla.loot.Conditions;

// somePool is a LootPool created elsewhere
somePool.addItemEntry(
    <minecraft:potato>, 1, 0, [], // Arbitrary values for example purposes
    [
        Conditions.randomChance(0.5) // 50% chance
    ]
);
static LootCondition randomChanceWithLooting(float chance, float lootingMult)
Equivalent to:

minecraft:random_chance_with_looting

import loottweaker.vanilla.loot.Conditions;

// somePool is a LootPool created elsewhere
somePool.addItemEntry(
    <minecraft:potato>, 1, 0, [], // Arbitrary values for example purposes
    [
        // 50% + looting level x 1% chance
        Conditions.randomChanceWithLooting(0.5, 0.01)
    ]
);
static LootCondition killedByPlayer()
Equivalent to:

minecraft:killed_by_player

import loottweaker.vanilla.loot.Conditions;

// somePool is a LootPool created elsewhere
somePool.addItemEntry(
    <minecraft:potato>, 1, 0, [], // Arbitrary values for example purposes
    [
        Conditions.killedByPlayer()
    ]
);
static LootCondition killedByNonPlayer()
Equivalent to:

minecraft:killed_by_player with the inverse tag set to true

import loottweaker.vanilla.loot.Conditions;

// somePool is a LootPool created elsewhere
somePool.addItemEntry(
    <minecraft:potato>, 1, 0, [], // Arbitrary values for example purposes
    [
        Conditions.killedByNonPlayer()
    ]
);
static LootCondition parse(DataMap json)

Deprecated since version 0.3.0: LootPool.addItemEntry, LootPool.addLootTableEntry, and LootPool.addEmptyEntry are capable of automatically parsing Maps into LootConditions.

Parses a DataMap into a LootCondition.

Parameters:
  • json - an instance of DataMap representing a LootCondition in JSON form. It is recommended that the keys are enclosed in quotes to avoid conflicts between JSON key names and ZenScript keywords.

Returns:

json as a LootCondition

Errors:

if json does not parse successfully.

static LootCondition zenscript(loottweaker.CustomLootCondition zenFunction)

Adapts zenFunction into a LootCondition.

Parameters:
  • zenFunction - a ZenScript function with parameters (IRandom, LootContext) and return type boolean.

Returns:

a loot condition which passes if zenFunction returns true.

See:
import crafttweaker.util.IRandom;
import loottweaker.LootContext;
import loottweaker.vanilla.loot.Conditions;

// somePool is a LootPool created elsewhere
somePool.addItemEntry(
    <minecraft:potato>, 1, 0, [], // Arbitrary values for example purposes
    [
        Conditions.zenscript(function(rng as IRandom, context as LootContext) as boolean
        {
            return context.world().isRaining();
        })
    ]
);
loottweaker.CustomLootCondition

A ZenScript function with parameters (IRandom, LootContext) and return type boolean