Class LootModifier
java.lang.Object
net.neoforged.neoforge.common.loot.LootModifier
- All Implemented Interfaces:
IGlobalLootModifier
- Direct Known Subclasses:
AddTableLootModifier
A base implementation of a Global Loot Modifier for modders to extend.
Takes care of ILootCondition matching and comes with the base codec to extend.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Predicate<LootContext> protected final LootItemCondition[]protected final intFields inherited from interface IGlobalLootModifier
CONDITIONAL_CODEC, DEFAULT_PRIORITY, DIRECT_CODEC, LOOT_CONDITIONS_CODEC -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLootModifier(LootItemCondition[] conditions, int priority) Constructs a LootModifier. -
Method Summary
Modifier and TypeMethodDescriptionfinal it.unimi.dsi.fastutil.objects.ObjectArrayList<ItemStack> apply(it.unimi.dsi.fastutil.objects.ObjectArrayList<ItemStack> generatedLoot, LootContext context) Applies the modifier to the list of generated loot.protected static <T extends LootModifier>
com.mojang.datafixers.Products.P2<com.mojang.serialization.codecs.RecordCodecBuilder.Mu<T>, LootItemCondition[], Integer> codecStart(com.mojang.serialization.codecs.RecordCodecBuilder.Instance<T> instance) Simplifies codec creation, especially if no other fields are added:protected abstract it.unimi.dsi.fastutil.objects.ObjectArrayList<ItemStack> doApply(it.unimi.dsi.fastutil.objects.ObjectArrayList<ItemStack> generatedLoot, LootContext context) Applies the modifier to the generated loot (all loot conditions have already been checked and have returned true).intpriority()Returns the priority of this loot modifier.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IGlobalLootModifier
codec
-
Field Details
-
conditions
-
priority
protected final int priority -
combinedConditions
-
-
Constructor Details
-
LootModifier
Constructs a LootModifier.- Parameters:
conditionsIn- the ILootConditions that need to be matched before the loot is modified.
-
-
Method Details
-
codecStart
protected static <T extends LootModifier> com.mojang.datafixers.Products.P2<com.mojang.serialization.codecs.RecordCodecBuilder.Mu<T>, LootItemCondition[], Integer> codecStart(com.mojang.serialization.codecs.RecordCodecBuilder.Instance<T> instance) Simplifies codec creation, especially if no other fields are added:
Otherwise can follow this with #and() to add more fields. Examples: Forge Test Subclasses orpublic static final Codec<MyLootModifier> CODEC = RecordCodecBuilder.create(inst -> codecStart(inst).apply(inst, MyLootModifier::new));BendingTrunkPlacer.CODEC -
apply
public final it.unimi.dsi.fastutil.objects.ObjectArrayList<ItemStack> apply(it.unimi.dsi.fastutil.objects.ObjectArrayList<ItemStack> generatedLoot, LootContext context) Description copied from interface:IGlobalLootModifierApplies the modifier to the list of generated loot. This function needs to be responsible for checking ILootConditions as well.- Specified by:
applyin interfaceIGlobalLootModifier- Parameters:
generatedLoot- the list of ItemStacks that will be dropped, generated by loot tablescontext- the LootContext, identical to what is passed to loot tables- Returns:
- modified loot drops
-
priority
public int priority()Description copied from interface:IGlobalLootModifierReturns the priority of this loot modifier. Modifiers with a higher priority will be applied first. Modifiers with equal priority will be applied in an undefined order.The canonical "default" priority value is 1000, per
IGlobalLootModifier.DEFAULT_PRIORITY.- Specified by:
priorityin interfaceIGlobalLootModifier
-
doApply
protected abstract it.unimi.dsi.fastutil.objects.ObjectArrayList<ItemStack> doApply(it.unimi.dsi.fastutil.objects.ObjectArrayList<ItemStack> generatedLoot, LootContext context) Applies the modifier to the generated loot (all loot conditions have already been checked and have returned true).- Parameters:
generatedLoot- the list of ItemStacks that will be dropped, generated by loot tablescontext- the LootContext, identical to what is passed to loot tables- Returns:
- modified loot drops
-