From d41bbd7b6431a6d8fcced71eb5620a4ccfeeac49 Mon Sep 17 00:00:00 2001 From: Apex Date: Wed, 25 Dec 2024 23:41:32 +0000 Subject: [PATCH] Drop our `AdvancementProvider` serves no use with out `ExistingFileHelper` Use vanillas `AdvancementProvider` instead now --- .../AdvancementProvider.java.patch | 12 ---- .../common/data/AdvancementProvider.java | 60 ------------------- .../internal/NeoForgeAdvancementProvider.java | 10 ++-- .../debug/entity/player/AdvancementTests.java | 2 +- .../debug/resources/ModDatapackTest.java | 5 +- .../neoforge/oldtest/DataGeneratorTest.java | 5 +- 6 files changed, 12 insertions(+), 82 deletions(-) delete mode 100644 src/main/java/net/neoforged/neoforge/common/data/AdvancementProvider.java diff --git a/patches/net/minecraft/data/advancements/AdvancementProvider.java.patch b/patches/net/minecraft/data/advancements/AdvancementProvider.java.patch index 4bd6814b148..05735e12b0b 100644 --- a/patches/net/minecraft/data/advancements/AdvancementProvider.java.patch +++ b/patches/net/minecraft/data/advancements/AdvancementProvider.java.patch @@ -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 subProviders; @@ -37,7 +_,7 @@ throw new IllegalStateException("Duplicate advancement " + p_339356_.id()); } else { diff --git a/src/main/java/net/neoforged/neoforge/common/data/AdvancementProvider.java b/src/main/java/net/neoforged/neoforge/common/data/AdvancementProvider.java deleted file mode 100644 index d8f52188283..00000000000 --- a/src/main/java/net/neoforged/neoforge/common/data/AdvancementProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) Forge Development LLC and contributors - * SPDX-License-Identifier: LGPL-2.1-only - */ - -package net.neoforged.neoforge.common.data; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import net.minecraft.advancements.AdvancementHolder; -import net.minecraft.core.HolderLookup; -import net.minecraft.data.PackOutput; -import net.minecraft.data.advancements.AdvancementSubProvider; -import net.minecraft.resources.ResourceLocation; -import net.neoforged.neoforge.common.extensions.IAdvancementBuilderExtension; - -/** - * An extension of the vanilla {@code AdvancementProvider} to provide a feature-complete - * experience to generate modded advancements. - */ -public class AdvancementProvider extends net.minecraft.data.advancements.AdvancementProvider { - /** - * Constructs an advancement provider using the generators to write the - * advancements to a file. - * - * @param output the target directory of the data generator - * @param registries a future of a lookup for registries and their objects - * @param subProviders the generators used to create the advancements - */ - public AdvancementProvider(PackOutput output, CompletableFuture registries, List subProviders) { - super(output, registries, subProviders.stream().map(AdvancementGenerator::toSubProvider).toList()); - } - - /** - * An interface used to generated modded advancements. This is parallel to - * vanilla's {@link AdvancementSubProvider}. - * - * @see AdvancementSubProvider - */ - public interface AdvancementGenerator { - /** - * A method used to generate advancements for a mod. Advancements should be - * built via {@link IAdvancementBuilderExtension#save(Consumer, ResourceLocation)}. - * - * @param registries a lookup for registries and their objects - * @param saver a consumer used to write advancements to a file - */ - void generate(HolderLookup.Provider registries, Consumer saver); - - /** - * Creates an {@link AdvancementSubProvider} from this generator. - * - * @return a sub provider wrapping this generator - */ - default AdvancementSubProvider toSubProvider() { - return this::generate; - } - } -} diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeAdvancementProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeAdvancementProvider.java index 97da5118607..bcd59815a6b 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeAdvancementProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeAdvancementProvider.java @@ -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; @@ -59,7 +60,6 @@ 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 { @@ -67,7 +67,7 @@ public NeoForgeAdvancementProvider(PackOutput output, CompletableFuture getVanillaAdvancementProviders(PackOutput output, CompletableFuture registries) { + private static List getVanillaAdvancementProviders(PackOutput output, CompletableFuture registries) { List, 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)); @@ -85,9 +85,9 @@ private static List getVanillaAdvancementProviders(PackOut //Walk on powdered snow criteriaReplacers.add(replaceWearingPredicate(SnowBootsEntityPredicate.INSTANCE, predicate -> predicate.feet().filter(item -> predicateMatches(item, Items.LEATHER_BOOTS)).isPresent())); - List subProviders = getPrivateValue(net.minecraft.data.advancements.AdvancementProvider.class, VanillaAdvancementProvider.create(output, registries), "subProviders"); + List subProviders = getPrivateValue(AdvancementProvider.class, VanillaAdvancementProvider.create(output, registries), "subProviders"); return subProviders.stream() - .map(vanillaProvider -> new NeoForgeAdvancementGenerator(vanillaProvider, criteriaReplacers)) + .map(vanillaProvider -> new NeoForgeAdvancementGenerator(vanillaProvider, criteriaReplacers)) .toList(); } @@ -246,7 +246,7 @@ private static T getPrivateValue(Class clazz, @Nullable C inst, String return value; } - private record NeoForgeAdvancementGenerator(AdvancementSubProvider vanillaProvider, List, HolderLookup.Provider, Criterion>> criteriaReplacers) implements AdvancementGenerator { + private record NeoForgeAdvancementGenerator(AdvancementSubProvider vanillaProvider, List, HolderLookup.Provider, Criterion>> criteriaReplacers) implements AdvancementSubProvider { @Override public void generate(HolderLookup.Provider registries, Consumer saver) { // Warning: ugly code here. diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/entity/player/AdvancementTests.java b/tests/src/main/java/net/neoforged/neoforge/debug/entity/player/AdvancementTests.java index 7657536c60d..f749ee3679e 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/entity/player/AdvancementTests.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/entity/player/AdvancementTests.java @@ -16,6 +16,7 @@ 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; @@ -23,7 +24,6 @@ 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; diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/resources/ModDatapackTest.java b/tests/src/main/java/net/neoforged/neoforge/debug/resources/ModDatapackTest.java index e1d2133b6ca..0db0d12b3c5 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/resources/ModDatapackTest.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/resources/ModDatapackTest.java @@ -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; @@ -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 generators = List.of((registries, saver) -> Advancement.Builder.recipeAdvancement() + List generators = List.of((registries, saver) -> Advancement.Builder.recipeAdvancement() .parent(RecipeBuilder.ROOT_RECIPE_ADVANCEMENT) .addCriterion("has_scute", CriteriaTriggers.INVENTORY_CHANGED.createCriterion( new InventoryChangeTrigger.TriggerInstance( diff --git a/tests/src/main/java/net/neoforged/neoforge/oldtest/DataGeneratorTest.java b/tests/src/main/java/net/neoforged/neoforge/oldtest/DataGeneratorTest.java index 2f79733ec90..4f09ab22b0e 100644 --- a/tests/src/main/java/net/neoforged/neoforge/oldtest/DataGeneratorTest.java +++ b/tests/src/main/java/net/neoforged/neoforge/oldtest/DataGeneratorTest.java @@ -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; @@ -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; @@ -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 saver) { var obtainDirt = Advancement.Builder.advancement()