Skip to content

Commit

Permalink
Drop our AdvancementProvider serves no use with out `ExistingFileHe…
Browse files Browse the repository at this point in the history
…lper`

Use vanillas `AdvancementProvider` instead now
  • Loading branch information
ApexModder committed Dec 25, 2024
1 parent cf02b33 commit d41bbd7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
--- a/net/minecraft/data/advancements/AdvancementProvider.java
+++ b/net/minecraft/data/advancements/AdvancementProvider.java
@@ -16,6 +_,11 @@
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;

+/**
+ * @deprecated NeoForge: Use {@link net.neoforged.neoforge.common.data.AdvancementProvider} instead,
+ * provides ease of access for the {@link net.neoforged.neoforge.common.data.ExistingFileHelper} in the generator
+ */
+@Deprecated
public class AdvancementProvider implements DataProvider {
private final PackOutput.PathProvider pathProvider;
private final List<AdvancementSubProvider> subProviders;
@@ -37,7 +_,7 @@
throw new IllegalStateException("Duplicate advancement " + p_339356_.id());
} else {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
import net.minecraft.data.advancements.AdvancementProvider;
import net.minecraft.data.advancements.AdvancementSubProvider;
import net.minecraft.data.advancements.packs.VanillaAdvancementProvider;
import net.minecraft.data.advancements.packs.VanillaHusbandryAdvancements;
Expand All @@ -59,15 +60,14 @@
import net.neoforged.neoforge.common.advancements.critereon.PiglinCurrencyItemPredicate;
import net.neoforged.neoforge.common.advancements.critereon.PiglinNeutralArmorEntityPredicate;
import net.neoforged.neoforge.common.advancements.critereon.SnowBootsEntityPredicate;
import net.neoforged.neoforge.common.data.AdvancementProvider;
import org.jetbrains.annotations.Nullable;

public class NeoForgeAdvancementProvider extends AdvancementProvider {
public NeoForgeAdvancementProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
super(output, registries, getVanillaAdvancementProviders(output, registries));
}

private static List<AdvancementGenerator> getVanillaAdvancementProviders(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
private static List<AdvancementSubProvider> getVanillaAdvancementProviders(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
List<BiFunction<Criterion<?>, HolderLookup.Provider, Criterion<?>>> criteriaReplacers = new ArrayList<>();
criteriaReplacers.add(replaceMatchToolCriteria(ItemAbilities.AXE_WAX_OFF, getPrivateValue(VanillaHusbandryAdvancements.class, null, "WAX_SCRAPING_TOOLS")));
criteriaReplacers.add(replaceInteractCriteria(ItemPredicate.Builder.item().withSubPredicate(ItemAbilityPredicate.TYPE, new ItemAbilityPredicate(ItemAbilities.SHEARS_REMOVE_ARMOR)).build(), Items.SHEARS));
Expand All @@ -85,9 +85,9 @@ private static List<AdvancementGenerator> getVanillaAdvancementProviders(PackOut
//Walk on powdered snow
criteriaReplacers.add(replaceWearingPredicate(SnowBootsEntityPredicate.INSTANCE, predicate -> predicate.feet().filter(item -> predicateMatches(item, Items.LEATHER_BOOTS)).isPresent()));

List<AdvancementSubProvider> subProviders = getPrivateValue(net.minecraft.data.advancements.AdvancementProvider.class, VanillaAdvancementProvider.create(output, registries), "subProviders");
List<AdvancementSubProvider> subProviders = getPrivateValue(AdvancementProvider.class, VanillaAdvancementProvider.create(output, registries), "subProviders");
return subProviders.stream()
.<AdvancementGenerator>map(vanillaProvider -> new NeoForgeAdvancementGenerator(vanillaProvider, criteriaReplacers))
.<AdvancementSubProvider>map(vanillaProvider -> new NeoForgeAdvancementGenerator(vanillaProvider, criteriaReplacers))
.toList();
}

Expand Down Expand Up @@ -246,7 +246,7 @@ private static <T, C> T getPrivateValue(Class<C> clazz, @Nullable C inst, String
return value;
}

private record NeoForgeAdvancementGenerator(AdvancementSubProvider vanillaProvider, List<BiFunction<Criterion<?>, HolderLookup.Provider, Criterion<?>>> criteriaReplacers) implements AdvancementGenerator {
private record NeoForgeAdvancementGenerator(AdvancementSubProvider vanillaProvider, List<BiFunction<Criterion<?>, HolderLookup.Provider, Criterion<?>>> criteriaReplacers) implements AdvancementSubProvider {
@Override
public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolder> saver) {
// Warning: ugly code here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import net.minecraft.advancements.critereon.ItemSubPredicate;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.advancements.AdvancementProvider;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameType;
import net.neoforged.neoforge.common.data.AdvancementProvider;
import net.neoforged.neoforge.event.entity.player.AdvancementEvent;
import net.neoforged.testframework.DynamicTest;
import net.neoforged.testframework.annotation.ForEachTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.advancements.AdvancementProvider;
import net.minecraft.data.advancements.AdvancementSubProvider;
import net.minecraft.data.recipes.RecipeBuilder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.neoforged.neoforge.common.data.AdvancementProvider;
import net.neoforged.neoforge.event.OnDatapackSyncEvent;
import net.neoforged.testframework.DynamicTest;
import net.neoforged.testframework.annotation.ForEachTest;
Expand All @@ -32,7 +33,7 @@ static void modDatapack(final DynamicTest test) {
final ResourceLocation testAdvancement = ResourceLocation.fromNamespaceAndPath(test.createModId(), "recipes/misc/test_advancement");

test.registrationHelper().addClientProvider(event -> {
List<AdvancementProvider.AdvancementGenerator> generators = List.of((registries, saver) -> Advancement.Builder.recipeAdvancement()
List<AdvancementSubProvider> generators = List.of((registries, saver) -> Advancement.Builder.recipeAdvancement()
.parent(RecipeBuilder.ROOT_RECIPE_ADVANCEMENT)
.addCriterion("has_scute", CriteriaTriggers.INVENTORY_CHANGED.createCriterion(
new InventoryChangeTrigger.TriggerInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.data.advancements.AdvancementProvider;
import net.minecraft.data.advancements.AdvancementSubProvider;
import net.minecraft.data.metadata.PackMetadataGenerator;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
Expand Down Expand Up @@ -88,7 +90,6 @@
import net.neoforged.neoforge.common.crafting.CompoundIngredient;
import net.neoforged.neoforge.common.crafting.DifferenceIngredient;
import net.neoforged.neoforge.common.crafting.IntersectionIngredient;
import net.neoforged.neoforge.common.data.AdvancementProvider;
import net.neoforged.neoforge.common.data.BlockTagsProvider;
import net.neoforged.neoforge.common.data.DatapackBuiltinEntriesProvider;
import net.neoforged.neoforge.common.data.GeneratingOverlayMetadataSection;
Expand Down Expand Up @@ -521,7 +522,7 @@ protected void addTranslations() {
}
}

private static class Advancements implements AdvancementProvider.AdvancementGenerator {
private static class Advancements implements AdvancementSubProvider {
@Override
public void generate(HolderLookup.Provider registries, Consumer<AdvancementHolder> saver) {
var obtainDirt = Advancement.Builder.advancement()
Expand Down

0 comments on commit d41bbd7

Please sign in to comment.