Skip to content

Commit

Permalink
Bring back the generic loot modifier builder
Browse files Browse the repository at this point in the history
Misremembered its purpose
  • Loading branch information
KnightMiner committed Mar 14, 2024
1 parent c44fa63 commit 527e831
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package slimeknights.mantle.loot;

import lombok.RequiredArgsConstructor;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraftforge.common.data.GlobalLootModifierProvider;
import net.minecraftforge.common.loot.LootModifier;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

/** Base builder for a global loot modifier during datagen, intended to be used with {@link GlobalLootModifierProvider} */
public abstract class AbstractLootModifierBuilder<B extends AbstractLootModifierBuilder<B>> {
Expand All @@ -21,4 +24,15 @@ public B addCondition(LootItemCondition condition) {
protected LootItemCondition[] getConditions() {
return conditions.toArray(new LootItemCondition[0]);
}

/** Generic builder for a modifier that just takes conditions */
@RequiredArgsConstructor
public static class GenericLootModifierBuilder<M extends LootModifier> extends AbstractLootModifierBuilder<GenericLootModifierBuilder<M>> {
private final Function<LootItemCondition[],M> constructor;

/** Builds the final instance */
public M build() {
return constructor.apply(getConditions());
}
}
}

0 comments on commit 527e831

Please sign in to comment.