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 theinverse
tag set to trueimport 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
, andLootPool.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 LootConditionErrors: if
json
does not parse successfully.- json - an instance of
- static LootCondition zenscript(loottweaker.CustomLootCondition zenFunction) ¶
Adapts
zenFunction
into aLootCondition
.Parameters: - zenFunction - a ZenScript function
with parameters
(IRandom, LootContext)
and return typeboolean
.
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(); }) ] );
- zenFunction - a ZenScript function
with parameters
-
loottweaker.CustomLootCondition
¶ A ZenScript function with parameters
(IRandom, LootContext)
and return typeboolean