diff --git a/patches/net/minecraft/client/data/Main.java.patch b/patches/net/minecraft/client/data/Main.java.patch index 5aa2dc3ded6..2bb26918216 100644 --- a/patches/net/minecraft/client/data/Main.java.patch +++ b/patches/net/minecraft/client/data/Main.java.patch @@ -1,12 +1,11 @@ --- a/net/minecraft/client/data/Main.java +++ b/net/minecraft/client/data/Main.java -@@ -30,16 +_,33 @@ +@@ -30,16 +_,31 @@ OptionSpec optionspec1 = optionparser.accepts("client", "Include client generators"); OptionSpec optionspec2 = optionparser.accepts("all", "Include all generators"); OptionSpec optionspec3 = optionparser.accepts("output", "Output folder").withRequiredArg().defaultsTo("generated"); + OptionSpec existing = optionparser.accepts("existing", "Existing resource packs that generated resources can reference").withRequiredArg(); -+ OptionSpec existingMod = optionparser.accepts("existing-mod", "Existing mods that generated resources can reference the resource packs of").withRequiredArg(); -+ OptionSpec gameDir = optionparser.accepts("gameDir").withRequiredArg().ofType(java.io.File.class).defaultsTo(new java.io.File(".")).required(); //Need by modlauncher, so lets just eat it ++ optionparser.accepts("gameDir").withRequiredArg().ofType(java.io.File.class).defaultsTo(new java.io.File(".")).required(); //Need by modlauncher, so lets just eat it + OptionSpec mod = optionparser.accepts("mod", "A modid to dump").withRequiredArg().withValuesSeparatedBy(","); + OptionSpec flat = optionparser.accepts("flat", "Do not append modid prefix to output directory when generating for multiple mods"); + OptionSpec assetIndex = optionparser.accepts("assetIndex").withRequiredArg(); @@ -21,7 +20,6 @@ - ClientBootstrap.bootstrap(); - DataGenerator datagenerator = new DataGenerator(path, SharedConstants.getCurrentVersion(), true); + java.util.Collection existingPacks = optionset.valuesOf(existing).stream().map(Paths::get).toList(); -+ java.util.Set existingMods = new java.util.HashSet<>(optionset.valuesOf(existingMod)); + java.util.Set mods = new java.util.HashSet<>(optionset.valuesOf(mod)); + boolean isFlat = mods.isEmpty() || optionset.has(flat); + boolean validate = optionset.has(validateSpec); @@ -30,7 +28,7 @@ addClientProviders(datagenerator, flag1); - datagenerator.run(); + } -+ net.neoforged.neoforge.data.loading.DatagenModLoader.begin(mods, path, java.util.List.of(), existingPacks, existingMods, false, false, validate, isFlat, optionset.valueOf(assetIndex), optionset.valueOf(assetsDir), () -> { ++ net.neoforged.neoforge.data.loading.DatagenModLoader.begin(mods, path, java.util.List.of(), existingPacks, false, false, validate, isFlat, optionset.valueOf(assetIndex), optionset.valueOf(assetsDir), () -> { + ClientBootstrap.bootstrap(); + net.neoforged.neoforge.client.ClientHooks.registerSpriteSourceTypes(); + net.neoforged.neoforge.client.entity.animation.json.AnimationTypeManager.init(); diff --git a/patches/net/minecraft/data/Main.java.patch b/patches/net/minecraft/data/Main.java.patch index eed2934cc48..0a9542b0368 100644 --- a/patches/net/minecraft/data/Main.java.patch +++ b/patches/net/minecraft/data/Main.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/data/Main.java +++ b/net/minecraft/data/Main.java -@@ -73,21 +_,34 @@ +@@ -73,21 +_,32 @@ OptionSpec optionspec1 = optionparser.accepts("server", "Include server generators"); OptionSpec optionspec2 = optionparser.accepts("dev", "Include development tools"); OptionSpec optionspec3 = optionparser.accepts("reports", "Include data reports"); @@ -10,7 +10,6 @@ OptionSpec optionspec5 = optionparser.accepts("output", "Output folder").withRequiredArg().defaultsTo("generated"); OptionSpec optionspec6 = optionparser.accepts("input", "Input folder").withRequiredArg(); + OptionSpec existing = optionparser.accepts("existing", "Existing resource packs that generated resources can reference").withRequiredArg(); -+ OptionSpec existingMod = optionparser.accepts("existing-mod", "Existing mods that generated resources can reference the resource packs of").withRequiredArg(); + OptionSpec gameDir = optionparser.accepts("gameDir").withRequiredArg().ofType(java.io.File.class).defaultsTo(new java.io.File(".")).required(); //Need by modlauncher, so lets just eat it + OptionSpec mod = optionparser.accepts("mod", "A modid to dump").withRequiredArg().withValuesSeparatedBy(","); + OptionSpec flat = optionparser.accepts("flat", "Do not append modid prefix to output directory when generating for multiple mods"); @@ -24,17 +23,16 @@ boolean flag3 = flag || optionset.has(optionspec3); Collection collection = optionset.valuesOf(optionspec6).stream().map(p_129659_ -> Paths.get(p_129659_)).toList(); - DataGenerator datagenerator = new DataGenerator(path, SharedConstants.getCurrentVersion(), true); -+ Collection existingPacks = optionset.valuesOf(existing).stream().map(Paths::get).toList(); -+ java.util.Set existingMods = new java.util.HashSet<>(optionset.valuesOf(existingMod)); + java.util.Set mods = new java.util.HashSet<>(optionset.valuesOf(mod)); + boolean isFlat = mods.isEmpty() || optionset.has(flat); + boolean validate = optionset.has(validateSpec); + DataGenerator datagenerator = new DataGenerator(isFlat ? path : path.resolve("minecraft"), SharedConstants.getCurrentVersion(), true); ++ java.util.Collection existingPacks = optionset.valuesOf(existing).stream().map(Paths::get).toList(); + if (mods.contains("minecraft") || mods.isEmpty()) { addServerProviders(datagenerator, collection, flag1, flag2, flag3); - datagenerator.run(); + } -+ net.neoforged.neoforge.data.loading.DatagenModLoader.begin(mods, path, collection, existingPacks, existingMods, flag2, flag3, validate, isFlat, null, null, () -> {}, ++ net.neoforged.neoforge.data.loading.DatagenModLoader.begin(mods, path, collection, existingPacks, flag2, flag3, validate, isFlat, null, null, () -> {}, + net.neoforged.neoforge.data.event.GatherDataEvent.Server::new, datagenerator); } else { optionparser.printHelpOn(System.out); 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/patches/net/minecraft/data/tags/BannerPatternTagsProvider.java.patch b/patches/net/minecraft/data/tags/BannerPatternTagsProvider.java.patch index 12d3607d4fd..de58f6caa68 100644 --- a/patches/net/minecraft/data/tags/BannerPatternTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/BannerPatternTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.level.block.entity.BannerPatterns; public class BannerPatternTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #BannerPatternTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #BannerPatternTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public BannerPatternTagsProvider(PackOutput p_256451_, CompletableFuture p_256420_) { super(p_256451_, Registries.BANNER_PATTERN, p_256420_); + } -+ public BannerPatternTagsProvider(PackOutput p_256451_, CompletableFuture p_256420_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_256451_, Registries.BANNER_PATTERN, p_256420_, modId, existingFileHelper); ++ public BannerPatternTagsProvider(PackOutput p_256451_, CompletableFuture p_256420_, String modId) { ++ super(p_256451_, Registries.BANNER_PATTERN, p_256420_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/BiomeTagsProvider.java.patch b/patches/net/minecraft/data/tags/BiomeTagsProvider.java.patch index ddb9d5a733e..eee10d38d76 100644 --- a/patches/net/minecraft/data/tags/BiomeTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/BiomeTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.level.biome.MultiNoiseBiomeSourceParameterList; public class BiomeTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #BiomeTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #BiomeTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public BiomeTagsProvider(PackOutput p_255800_, CompletableFuture p_256205_) { super(p_255800_, Registries.BIOME, p_256205_); + } -+ public BiomeTagsProvider(PackOutput p_255800_, CompletableFuture p_256205_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_255800_, Registries.BIOME, p_256205_, modId, existingFileHelper); ++ public BiomeTagsProvider(PackOutput p_255800_, CompletableFuture p_256205_, String modId) { ++ super(p_255800_, Registries.BIOME, p_256205_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/CatVariantTagsProvider.java.patch b/patches/net/minecraft/data/tags/CatVariantTagsProvider.java.patch index 353d5eb05d7..6e970532dbf 100644 --- a/patches/net/minecraft/data/tags/CatVariantTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/CatVariantTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.entity.animal.CatVariant; public class CatVariantTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #CatVariantTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #CatVariantTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public CatVariantTagsProvider(PackOutput p_256547_, CompletableFuture p_256090_) { super(p_256547_, Registries.CAT_VARIANT, p_256090_); + } -+ public CatVariantTagsProvider(PackOutput p_256547_, CompletableFuture p_256090_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_256547_, Registries.CAT_VARIANT, p_256090_, modId, existingFileHelper); ++ public CatVariantTagsProvider(PackOutput p_256547_, CompletableFuture p_256090_, String modId) { ++ super(p_256547_, Registries.CAT_VARIANT, p_256090_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/DamageTypeTagsProvider.java.patch b/patches/net/minecraft/data/tags/DamageTypeTagsProvider.java.patch index e97a601992c..51ba4f92fa2 100644 --- a/patches/net/minecraft/data/tags/DamageTypeTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/DamageTypeTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.damagesource.DamageTypes; public class DamageTypeTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #DamageTypeTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #DamageTypeTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public DamageTypeTagsProvider(PackOutput p_270719_, CompletableFuture p_270256_) { super(p_270719_, Registries.DAMAGE_TYPE, p_270256_); + } -+ public DamageTypeTagsProvider(PackOutput p_270719_, CompletableFuture p_270256_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_270719_, Registries.DAMAGE_TYPE, p_270256_, modId, existingFileHelper); ++ public DamageTypeTagsProvider(PackOutput p_270719_, CompletableFuture p_270256_, String modId) { ++ super(p_270719_, Registries.DAMAGE_TYPE, p_270256_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/EnchantmentTagsProvider.java.patch b/patches/net/minecraft/data/tags/EnchantmentTagsProvider.java.patch index 067e7b45995..1252d962c99 100644 --- a/patches/net/minecraft/data/tags/EnchantmentTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/EnchantmentTagsProvider.java.patch @@ -4,12 +4,12 @@ import net.minecraft.world.item.enchantment.Enchantment; public abstract class EnchantmentTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #EnchantmentTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #EnchantmentTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ public EnchantmentTagsProvider(PackOutput p_341044_, CompletableFuture p_341146_) { super(p_341044_, Registries.ENCHANTMENT, p_341146_); + } -+ public EnchantmentTagsProvider(PackOutput p_341044_, CompletableFuture p_341146_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_341044_, Registries.ENCHANTMENT, p_341146_, modId, existingFileHelper); ++ public EnchantmentTagsProvider(PackOutput p_341044_, CompletableFuture p_341146_, String modId) { ++ super(p_341044_, Registries.ENCHANTMENT, p_341146_, modId); } protected void tooltipOrder(HolderLookup.Provider p_341105_, ResourceKey... p_345255_) { diff --git a/patches/net/minecraft/data/tags/EntityTypeTagsProvider.java.patch b/patches/net/minecraft/data/tags/EntityTypeTagsProvider.java.patch index fa8be023008..be399fe410b 100644 --- a/patches/net/minecraft/data/tags/EntityTypeTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/EntityTypeTagsProvider.java.patch @@ -4,14 +4,14 @@ import net.minecraft.world.entity.EntityType; public class EntityTypeTagsProvider extends IntrinsicHolderTagsProvider> { -+ /** @deprecated Forge: Use the {@linkplain #EntityTypeTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #EntityTypeTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public EntityTypeTagsProvider(PackOutput p_256095_, CompletableFuture p_256572_) { - super(p_256095_, Registries.ENTITY_TYPE, p_256572_, p_256665_ -> p_256665_.builtInRegistryHolder().key()); -+ this(p_256095_, p_256572_, "vanilla", null); ++ this(p_256095_, p_256572_, "vanilla"); + } -+ public EntityTypeTagsProvider(PackOutput p_256095_, CompletableFuture p_256572_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_256095_, Registries.ENTITY_TYPE, p_256572_, p_256665_ -> p_256665_.builtInRegistryHolder().key(), modId, existingFileHelper); ++ public EntityTypeTagsProvider(PackOutput p_256095_, CompletableFuture p_256572_, String modId) { ++ super(p_256095_, Registries.ENTITY_TYPE, p_256572_, p_256665_ -> p_256665_.builtInRegistryHolder().key(), modId); } @Override diff --git a/patches/net/minecraft/data/tags/FlatLevelGeneratorPresetTagsProvider.java.patch b/patches/net/minecraft/data/tags/FlatLevelGeneratorPresetTagsProvider.java.patch index 0c0dbad8820..c957228cf24 100644 --- a/patches/net/minecraft/data/tags/FlatLevelGeneratorPresetTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/FlatLevelGeneratorPresetTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorPresets; public class FlatLevelGeneratorPresetTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #FlatLevelGeneratorPresetTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #FlatLevelGeneratorPresetTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public FlatLevelGeneratorPresetTagsProvider(PackOutput p_256604_, CompletableFuture p_255962_) { super(p_256604_, Registries.FLAT_LEVEL_GENERATOR_PRESET, p_255962_); + } -+ public FlatLevelGeneratorPresetTagsProvider(PackOutput p_256604_, CompletableFuture p_255962_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_256604_, Registries.FLAT_LEVEL_GENERATOR_PRESET, p_255962_, modId, existingFileHelper); ++ public FlatLevelGeneratorPresetTagsProvider(PackOutput p_256604_, CompletableFuture p_255962_, String modId) { ++ super(p_256604_, Registries.FLAT_LEVEL_GENERATOR_PRESET, p_255962_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/FluidTagsProvider.java.patch b/patches/net/minecraft/data/tags/FluidTagsProvider.java.patch index c1549c59b4a..05a3f8d19c4 100644 --- a/patches/net/minecraft/data/tags/FluidTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/FluidTagsProvider.java.patch @@ -4,14 +4,14 @@ import net.minecraft.world.level.material.Fluids; public class FluidTagsProvider extends IntrinsicHolderTagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #FluidTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #FluidTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public FluidTagsProvider(PackOutput p_255941_, CompletableFuture p_256600_) { - super(p_255941_, Registries.FLUID, p_256600_, p_256474_ -> p_256474_.builtInRegistryHolder().key()); -+ this(p_255941_, p_256600_, "vanilla", null); ++ this(p_255941_, p_256600_, "vanilla"); + } -+ public FluidTagsProvider(PackOutput p_255941_, CompletableFuture p_256600_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_255941_, Registries.FLUID, p_256600_, p_256474_ -> p_256474_.builtInRegistryHolder().key(), modId, existingFileHelper); ++ public FluidTagsProvider(PackOutput p_255941_, CompletableFuture p_256600_, String modId) { ++ super(p_255941_, Registries.FLUID, p_256600_, p_256474_ -> p_256474_.builtInRegistryHolder().key(), modId); } @Override diff --git a/patches/net/minecraft/data/tags/GameEventTagsProvider.java.patch b/patches/net/minecraft/data/tags/GameEventTagsProvider.java.patch index 9b0020e2ed9..a3435fb1f78 100644 --- a/patches/net/minecraft/data/tags/GameEventTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/GameEventTagsProvider.java.patch @@ -4,15 +4,15 @@ GameEvent.UNEQUIP.key() ); -+ /** @deprecated Neo: Use the {@linkplain #GameEventTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Neo: Use the {@linkplain #GameEventTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public GameEventTagsProvider(PackOutput p_256060_, CompletableFuture p_255621_) { - super(p_256060_, Registries.GAME_EVENT, p_255621_); -+ this(p_256060_, p_255621_, "vanilla", null); ++ this(p_256060_, p_255621_, "vanilla"); + } + -+ public GameEventTagsProvider(PackOutput p_256060_, CompletableFuture p_255621_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_256060_, Registries.GAME_EVENT, p_255621_, modId, existingFileHelper); ++ public GameEventTagsProvider(PackOutput p_256060_, CompletableFuture p_255621_, String modId) { ++ super(p_256060_, Registries.GAME_EVENT, p_255621_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/InstrumentTagsProvider.java.patch b/patches/net/minecraft/data/tags/InstrumentTagsProvider.java.patch index e0f8c97fcb7..6c5de5e058f 100644 --- a/patches/net/minecraft/data/tags/InstrumentTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/InstrumentTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.item.Instruments; public class InstrumentTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #InstrumentTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #InstrumentTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public InstrumentTagsProvider(PackOutput p_256418_, CompletableFuture p_256038_) { super(p_256418_, Registries.INSTRUMENT, p_256038_); + } -+ public InstrumentTagsProvider(PackOutput p_256418_, CompletableFuture p_256038_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_256418_, Registries.INSTRUMENT, p_256038_, modId, existingFileHelper); ++ public InstrumentTagsProvider(PackOutput p_256418_, CompletableFuture p_256038_, String modId) { ++ super(p_256418_, Registries.INSTRUMENT, p_256038_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/IntrinsicHolderTagsProvider.java.patch b/patches/net/minecraft/data/tags/IntrinsicHolderTagsProvider.java.patch index 77d5adc360b..dfbd494a0df 100644 --- a/patches/net/minecraft/data/tags/IntrinsicHolderTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/IntrinsicHolderTagsProvider.java.patch @@ -13,48 +13,31 @@ ) { - super(p_256164_, p_256155_, p_256488_); - this.keyExtractor = p_256168_; -+ this(p_256164_, p_256155_, p_256488_, p_256168_, "vanilla", null); ++ this(p_256164_, p_256155_, p_256488_, p_256168_, "vanilla"); } + @Deprecated public IntrinsicHolderTagsProvider( PackOutput p_275304_, ResourceKey> p_275709_, -@@ -30,20 +_,46 @@ +@@ -30,20 +_,29 @@ CompletableFuture> p_275311_, Function> p_275566_ ) { - super(p_275304_, p_275709_, p_275227_, p_275311_); -+ this(p_275304_, p_275709_, p_275227_, p_275311_, p_275566_, "vanilla", null); ++ this(p_275304_, p_275709_, p_275227_, p_275311_, p_275566_, "vanilla"); + } + -+ public IntrinsicHolderTagsProvider( -+ PackOutput p_256164_, -+ ResourceKey> p_256155_, -+ CompletableFuture p_256488_, -+ Function> p_256168_, -+ String modId, -+ @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper -+ ) { -+ super(p_256164_, p_256155_, p_256488_, modId, existingFileHelper); ++ public IntrinsicHolderTagsProvider(PackOutput p_256164_, ResourceKey> p_256155_, CompletableFuture p_256488_, Function> p_256168_, String modId) { ++ super(p_256164_, p_256155_, p_256488_, modId); + this.keyExtractor = p_256168_; + } + -+ public IntrinsicHolderTagsProvider( -+ PackOutput p_275304_, -+ ResourceKey> p_275709_, -+ CompletableFuture p_275227_, -+ CompletableFuture> p_275311_, -+ Function> p_275566_, -+ String modId, -+ @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper -+ ) { -+ super(p_275304_, p_275709_, p_275227_, p_275311_, modId, existingFileHelper); ++ public IntrinsicHolderTagsProvider(PackOutput p_275304_, ResourceKey> p_275709_, CompletableFuture p_275227_, CompletableFuture> p_275311_, Function> p_275566_, String modId) { ++ super(p_275304_, p_275709_, p_275227_, p_275311_, modId); this.keyExtractor = p_275566_; } -+ -+ protected IntrinsicHolderTagsProvider.IntrinsicTagAppender tag(TagKey p_255730_) { TagBuilder tagbuilder = this.getOrCreateRawBuilder(p_255730_); - return new IntrinsicHolderTagsProvider.IntrinsicTagAppender<>(tagbuilder, this.keyExtractor); diff --git a/patches/net/minecraft/data/tags/ItemTagsProvider.java.patch b/patches/net/minecraft/data/tags/ItemTagsProvider.java.patch index 04bbff65586..bfe747b57ab 100644 --- a/patches/net/minecraft/data/tags/ItemTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/ItemTagsProvider.java.patch @@ -1,22 +1,22 @@ --- a/net/minecraft/data/tags/ItemTagsProvider.java +++ b/net/minecraft/data/tags/ItemTagsProvider.java -@@ -17,19 +_,48 @@ +@@ -17,19 +_,35 @@ private final Map, TagKey> tagsToCopy = new HashMap<>(); public ItemTagsProvider( + /** -+ * @deprecated Forge: Use the {@linkplain #ItemTagsProvider(PackOutput, CompletableFuture, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} ++ * @deprecated Forge: Use the {@linkplain #ItemTagsProvider(PackOutput, CompletableFuture, CompletableFuture, String) mod id variant} + */ + @Deprecated PackOutput p_275343_, CompletableFuture p_275729_, CompletableFuture> p_275322_ ) { - super(p_275343_, Registries.ITEM, p_275729_, p_255790_ -> p_255790_.builtInRegistryHolder().key()); - this.blockTags = p_275322_; -+ this(p_275343_, p_275729_, p_275322_, "vanilla", null); ++ this(p_275343_, p_275729_, p_275322_, "vanilla"); } + /** -+ * @deprecated Forge: Use the {@linkplain #ItemTagsProvider(PackOutput, CompletableFuture, CompletableFuture, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} ++ * @deprecated Forge: Use the {@linkplain #ItemTagsProvider(PackOutput, CompletableFuture, CompletableFuture, CompletableFuture, String) mod id variant} + */ + @Deprecated public ItemTagsProvider( @@ -26,29 +26,16 @@ CompletableFuture> p_275634_ ) { - super(p_275204_, Registries.ITEM, p_275194_, p_275207_, p_274765_ -> p_274765_.builtInRegistryHolder().key()); -+ this(p_275204_, p_275194_, p_275207_, p_275634_, "vanilla", null); ++ this(p_275204_, p_275194_, p_275207_, p_275634_, "vanilla"); + } + -+ public ItemTagsProvider( -+ PackOutput p_275343_, -+ CompletableFuture p_275729_, -+ CompletableFuture> p_275322_, -+ String modId, -+ @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper -+ ) { -+ super(p_275343_, Registries.ITEM, p_275729_, p_255790_ -> p_255790_.builtInRegistryHolder().key(), modId, existingFileHelper); ++ public ItemTagsProvider(PackOutput p_275343_, CompletableFuture p_275729_, CompletableFuture> p_275322_, String modId) { ++ super(p_275343_, Registries.ITEM, p_275729_, p_255790_ -> p_255790_.builtInRegistryHolder().key(), modId); + this.blockTags = p_275322_; + } + -+ public ItemTagsProvider( -+ PackOutput p_275204_, -+ CompletableFuture p_275194_, -+ CompletableFuture> p_275207_, -+ CompletableFuture> p_275634_, -+ String modId, -+ @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper -+ ) { -+ super(p_275204_, Registries.ITEM, p_275194_, p_275207_, p_274765_ -> p_274765_.builtInRegistryHolder().key(), modId, existingFileHelper); ++ public ItemTagsProvider(PackOutput p_275204_, CompletableFuture p_275194_, CompletableFuture> p_275207_, CompletableFuture> p_275634_, String modId) { ++ super(p_275204_, Registries.ITEM, p_275194_, p_275207_, p_274765_ -> p_274765_.builtInRegistryHolder().key(), modId); this.blockTags = p_275634_; } diff --git a/patches/net/minecraft/data/tags/PaintingVariantTagsProvider.java.patch b/patches/net/minecraft/data/tags/PaintingVariantTagsProvider.java.patch index 80c4eec6533..1f1f41aacaf 100644 --- a/patches/net/minecraft/data/tags/PaintingVariantTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/PaintingVariantTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.entity.decoration.PaintingVariants; public class PaintingVariantTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #PaintingVariantTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #PaintingVariantTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public PaintingVariantTagsProvider(PackOutput p_255750_, CompletableFuture p_256184_) { super(p_255750_, Registries.PAINTING_VARIANT, p_256184_); + } -+ public PaintingVariantTagsProvider(PackOutput p_255750_, CompletableFuture p_256184_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_255750_, Registries.PAINTING_VARIANT, p_256184_, modId, existingFileHelper); ++ public PaintingVariantTagsProvider(PackOutput p_255750_, CompletableFuture p_256184_, String modId) { ++ super(p_255750_, Registries.PAINTING_VARIANT, p_256184_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/PoiTypeTagsProvider.java.patch b/patches/net/minecraft/data/tags/PoiTypeTagsProvider.java.patch index 1e01e6327fe..cec97a67dc8 100644 --- a/patches/net/minecraft/data/tags/PoiTypeTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/PoiTypeTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.entity.ai.village.poi.PoiTypes; public class PoiTypeTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #PoiTypeTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #PoiTypeTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public PoiTypeTagsProvider(PackOutput p_256012_, CompletableFuture p_256617_) { super(p_256012_, Registries.POINT_OF_INTEREST_TYPE, p_256617_); + } -+ public PoiTypeTagsProvider(PackOutput p_256012_, CompletableFuture p_256617_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_256012_, Registries.POINT_OF_INTEREST_TYPE, p_256617_, modId, existingFileHelper); ++ public PoiTypeTagsProvider(PackOutput p_256012_, CompletableFuture p_256617_, String modId) { ++ super(p_256012_, Registries.POINT_OF_INTEREST_TYPE, p_256617_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/StructureTagsProvider.java.patch b/patches/net/minecraft/data/tags/StructureTagsProvider.java.patch index 3785cd91735..58e997492ce 100644 --- a/patches/net/minecraft/data/tags/StructureTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/StructureTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.level.levelgen.structure.Structure; public class StructureTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #StructureTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #StructureTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public StructureTagsProvider(PackOutput p_256522_, CompletableFuture p_256661_) { super(p_256522_, Registries.STRUCTURE, p_256661_); + } -+ public StructureTagsProvider(PackOutput p_256522_, CompletableFuture p_256661_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_256522_, Registries.STRUCTURE, p_256661_, modId, existingFileHelper); ++ public StructureTagsProvider(PackOutput p_256522_, CompletableFuture p_256661_, String modId) { ++ super(p_256522_, Registries.STRUCTURE, p_256661_, modId); } @Override diff --git a/patches/net/minecraft/data/tags/TagsProvider.java.patch b/patches/net/minecraft/data/tags/TagsProvider.java.patch index ce4a79ab1f2..1c892e39b2c 100644 --- a/patches/net/minecraft/data/tags/TagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/TagsProvider.java.patch @@ -1,28 +1,24 @@ --- a/net/minecraft/data/tags/TagsProvider.java +++ b/net/minecraft/data/tags/TagsProvider.java -@@ -32,26 +_,54 @@ +@@ -32,26 +_,48 @@ private final CompletableFuture> parentProvider; protected final ResourceKey> registryKey; protected final Map builders = Maps.newLinkedHashMap(); + protected final String modId; -+ @org.jetbrains.annotations.Nullable -+ protected final net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper; -+ private final net.neoforged.neoforge.common.data.ExistingFileHelper.IResourceType resourceType; -+ private final net.neoforged.neoforge.common.data.ExistingFileHelper.IResourceType elementResourceType; // FORGE: Resource type for validating required references to datapack registry elements. + /** -+ * @deprecated Forge: Use the {@linkplain #TagsProvider(PackOutput, ResourceKey, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} ++ * @deprecated Forge: Use the {@linkplain #TagsProvider(PackOutput, ResourceKey, CompletableFuture, String) mod id variant} + */ protected TagsProvider(PackOutput p_256596_, ResourceKey> p_255886_, CompletableFuture p_256513_) { - this(p_256596_, p_255886_, p_256513_, CompletableFuture.completedFuture(TagsProvider.TagLookup.empty())); -+ this(p_256596_, p_255886_, p_256513_, "vanilla", null); ++ this(p_256596_, p_255886_, p_256513_, "vanilla"); + } -+ protected TagsProvider(PackOutput p_256596_, ResourceKey> p_255886_, CompletableFuture p_256513_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ this(p_256596_, p_255886_, p_256513_, CompletableFuture.completedFuture(TagsProvider.TagLookup.empty()), modId, existingFileHelper); ++ protected TagsProvider(PackOutput p_256596_, ResourceKey> p_255886_, CompletableFuture p_256513_, String modId) { ++ this(p_256596_, p_255886_, p_256513_, CompletableFuture.completedFuture(TagsProvider.TagLookup.empty()), modId); } + /** -+ * @deprecated Forge: Use the {@linkplain #TagsProvider(PackOutput, ResourceKey, CompletableFuture, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} ++ * @deprecated Forge: Use the {@linkplain #TagsProvider(PackOutput, ResourceKey, CompletableFuture, CompletableFuture, String) mod id variant} + */ + @Deprecated protected TagsProvider( @@ -31,17 +27,15 @@ CompletableFuture p_275222_, CompletableFuture> p_275565_ ) { -+ this(p_275432_, p_275476_, p_275222_, p_275565_, "vanilla", null); ++ this(p_275432_, p_275476_, p_275222_, p_275565_, "vanilla"); + } -+ protected TagsProvider(PackOutput p_275432_, ResourceKey> p_275476_, CompletableFuture p_275222_, CompletableFuture> p_275565_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { ++ ++ protected TagsProvider(PackOutput p_275432_, ResourceKey> p_275476_, CompletableFuture p_275222_, CompletableFuture> p_275565_, String modId) { this.pathProvider = p_275432_.createRegistryTagsPathProvider(p_275476_); this.registryKey = p_275476_; this.parentProvider = p_275565_; this.lookupProvider = p_275222_; + this.modId = modId; -+ this.existingFileHelper = existingFileHelper; -+ this.resourceType = new net.neoforged.neoforge.common.data.ExistingFileHelper.ResourceType(net.minecraft.server.packs.PackType.SERVER_DATA, ".json", net.minecraft.core.registries.Registries.tagsDirPath(p_275476_)); -+ this.elementResourceType = new net.neoforged.neoforge.common.data.ExistingFileHelper.ResourceType(net.minecraft.server.packs.PackType.SERVER_DATA, ".json", net.neoforged.neoforge.common.CommonHooks.prefixNamespace(p_275476_.location())); + } + + // Forge: Allow customizing the path for a given tag or returning null @@ -63,8 +57,8 @@ List list = tagbuilder.build(); - List list1 = list.stream().filter(p_274771_ -> !p_274771_.verifyIfPresent(predicate, predicate1)).toList(); + List list1 = java.util.stream.Stream.concat(list.stream(), tagbuilder.getRemoveEntries()) -+ .filter((p_274771_) -> !p_274771_.verifyIfPresent(predicate, predicate1)) -+ .filter(this::missing) ++ // Neo: Assume tags from other namespaces always exists ++ .filter((p_274771_) -> p_274771_.getId().getNamespace().equals(modId) && !p_274771_.verifyIfPresent(predicate, predicate1)) + .toList(); if (!list1.isEmpty()) { throw new IllegalArgumentException( @@ -82,19 +76,8 @@ } } ) -@@ -106,12 +_,24 @@ - ); - } +@@ -108,7 +_,7 @@ -+ private boolean missing(TagEntry reference) { -+ // Optional tags should not be validated -+ -+ if (reference.isRequired()) { -+ return existingFileHelper == null || !existingFileHelper.exists(reference.getId(), reference.isTag() ? resourceType : elementResourceType); -+ } -+ return false; -+ } -+ protected TagsProvider.TagAppender tag(TagKey p_206425_) { TagBuilder tagbuilder = this.getOrCreateRawBuilder(p_206425_); - return new TagsProvider.TagAppender<>(tagbuilder); @@ -102,12 +85,6 @@ } protected TagBuilder getOrCreateRawBuilder(TagKey p_236452_) { -+ if (existingFileHelper != null) { -+ existingFileHelper.trackGenerated(p_236452_.location(), resourceType); -+ } - return this.builders.computeIfAbsent(p_236452_.location(), p_236442_ -> TagBuilder.create()); - } - @@ -131,7 +_,15 @@ private final TagBuilder builder; diff --git a/patches/net/minecraft/data/tags/WorldPresetTagsProvider.java.patch b/patches/net/minecraft/data/tags/WorldPresetTagsProvider.java.patch index 779b22baead..a8fc2b267bc 100644 --- a/patches/net/minecraft/data/tags/WorldPresetTagsProvider.java.patch +++ b/patches/net/minecraft/data/tags/WorldPresetTagsProvider.java.patch @@ -4,13 +4,13 @@ import net.minecraft.world.level.levelgen.presets.WorldPresets; public class WorldPresetTagsProvider extends TagsProvider { -+ /** @deprecated Forge: Use the {@linkplain #WorldPresetTagsProvider(PackOutput, CompletableFuture, String, net.neoforged.neoforge.common.data.ExistingFileHelper) mod id variant} */ ++ /** @deprecated Forge: Use the {@linkplain #WorldPresetTagsProvider(PackOutput, CompletableFuture, String) mod id variant} */ + @Deprecated public WorldPresetTagsProvider(PackOutput p_255701_, CompletableFuture p_255974_) { super(p_255701_, Registries.WORLD_PRESET, p_255974_); + } -+ public WorldPresetTagsProvider(PackOutput p_255701_, CompletableFuture p_255974_, String modId, @org.jetbrains.annotations.Nullable net.neoforged.neoforge.common.data.ExistingFileHelper existingFileHelper) { -+ super(p_255701_, Registries.WORLD_PRESET, p_255974_, modId, existingFileHelper); ++ public WorldPresetTagsProvider(PackOutput p_255701_, CompletableFuture p_255974_, String modId) { ++ super(p_255701_, Registries.WORLD_PRESET, p_255974_, modId); } @Override diff --git a/src/generated/resources/data/neoforge/tags/damage_type/is_poison.json b/src/generated/resources/data/neoforge/tags/damage_type/is_poison.json index a20ac8c9b0d..45ecffa2ef9 100644 --- a/src/generated/resources/data/neoforge/tags/damage_type/is_poison.json +++ b/src/generated/resources/data/neoforge/tags/damage_type/is_poison.json @@ -1,6 +1,9 @@ { "values": [ - "neoforge:poison", + { + "id": "neoforge:poison", + "required": false + }, { "id": "#forge:is_poison", "required": false 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 f83687f4dc6..00000000000 --- a/src/main/java/net/neoforged/neoforge/common/data/AdvancementProvider.java +++ /dev/null @@ -1,63 +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 existingFileHelper a helper used to find whether a file exists - * @param subProviders the generators used to create the advancements - */ - public AdvancementProvider(PackOutput output, CompletableFuture registries, ExistingFileHelper existingFileHelper, List subProviders) { - super(output, registries, subProviders.stream().map(generator -> generator.toSubProvider(existingFileHelper)).toList()); - } - - /** - * An interface used to generated modded advancements. This is parallel to - * vanilla's {@link AdvancementSubProvider} with access to the {@link ExistingFileHelper}. - * - * @see AdvancementSubProvider - */ - public interface AdvancementGenerator { - /** - * A method used to generate advancements for a mod. Advancements should be - * built via {@link IAdvancementBuilderExtension#save(Consumer, ResourceLocation, ExistingFileHelper)}. - * - * @param registries a lookup for registries and their objects - * @param saver a consumer used to write advancements to a file - * @param existingFileHelper a helper used to find whether a file exists - */ - void generate(HolderLookup.Provider registries, Consumer saver, ExistingFileHelper existingFileHelper); - - /** - * Creates an {@link AdvancementSubProvider} from this generator. - * - * @param existingFileHelper a helper used to find whether a file exists - * @return a sub provider wrapping this generator - */ - default AdvancementSubProvider toSubProvider(ExistingFileHelper existingFileHelper) { - return (registries, saver) -> this.generate(registries, saver, existingFileHelper); - } - } -} diff --git a/src/main/java/net/neoforged/neoforge/common/data/BlockTagsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/BlockTagsProvider.java index 263b64b0838..2a673799ea1 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/BlockTagsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/BlockTagsProvider.java @@ -11,11 +11,9 @@ import net.minecraft.data.PackOutput; import net.minecraft.data.tags.IntrinsicHolderTagsProvider; import net.minecraft.world.level.block.Block; -import org.jetbrains.annotations.Nullable; public abstract class BlockTagsProvider extends IntrinsicHolderTagsProvider { - @SuppressWarnings("deprecation") - public BlockTagsProvider(PackOutput output, CompletableFuture lookupProvider, String modId, @Nullable ExistingFileHelper existingFileHelper) { - super(output, Registries.BLOCK, lookupProvider, block -> block.builtInRegistryHolder().key(), modId, existingFileHelper); + public BlockTagsProvider(PackOutput output, CompletableFuture lookupProvider, String modId) { + super(output, Registries.BLOCK, lookupProvider, block -> block.builtInRegistryHolder().key(), modId); } } diff --git a/src/main/java/net/neoforged/neoforge/common/data/ExistingFileHelper.java b/src/main/java/net/neoforged/neoforge/common/data/ExistingFileHelper.java deleted file mode 100644 index bea5dd18c26..00000000000 --- a/src/main/java/net/neoforged/neoforge/common/data/ExistingFileHelper.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (c) Forge Development LLC and contributors - * SPDX-License-Identifier: LGPL-2.1-only - */ - -package net.neoforged.neoforge.common.data; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import java.io.File; -import java.io.FileNotFoundException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import net.minecraft.client.resources.ClientPackSource; -import net.minecraft.client.resources.IndexedAssetSource; -import net.minecraft.data.DataProvider; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.FilePackResources; -import net.minecraft.server.packs.PackLocationInfo; -import net.minecraft.server.packs.PackResources; -import net.minecraft.server.packs.PackType; -import net.minecraft.server.packs.PathPackResources; -import net.minecraft.server.packs.VanillaPackResources; -import net.minecraft.server.packs.repository.PackSource; -import net.minecraft.server.packs.repository.ServerPacksSource; -import net.minecraft.server.packs.resources.MultiPackResourceManager; -import net.minecraft.server.packs.resources.Resource; -import net.minecraft.server.packs.resources.ResourceManager; -import net.neoforged.fml.ModList; -import net.neoforged.neoforge.data.event.GatherDataEvent; -import net.neoforged.neoforge.resource.ResourcePackLoader; -import net.neoforged.neoforgespi.language.IModFileInfo; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.VisibleForTesting; - -/** - * Enables data providers to check if other data files currently exist. The - * instance provided in the {@link GatherDataEvent} utilizes the standard - * resources (via {@link VanillaPackResources}), forge's resources, as well as any - * extra resource packs passed in via the {@code --existing} argument, - * or mod resources via the {@code --existing-mod} argument. - * - * @deprecated To be removed without replacement. - */ -@Deprecated(forRemoval = true, since = "1.21.4") -public class ExistingFileHelper { - public interface IResourceType { - PackType getPackType(); - - String getSuffix(); - - String getPrefix(); - } - - public static class ResourceType implements IResourceType { - final PackType packType; - final String suffix, prefix; - - public ResourceType(PackType type, String suffix, String prefix) { - this.packType = type; - this.suffix = suffix; - this.prefix = prefix; - } - - @Override - public PackType getPackType() { - return packType; - } - - @Override - public String getSuffix() { - return suffix; - } - - @Override - public String getPrefix() { - return prefix; - } - } - - private final MultiPackResourceManager clientResources, serverData; - private final boolean enable; - private final Multimap generated = HashMultimap.create(); - - /** - * Create a new helper. This should probably NOT be used by mods, as - * the instance provided by forge is designed to be a central instance that - * tracks existence of generated data. - *

- * Only create a new helper if you intentionally want to ignore the existence of - * other generated files. - * - * @param existingPacks a collection of paths to existing packs - * @param existingMods a set of mod IDs for existing mods - * @param enable {@code true} if validation is enabled - * @param assetIndex the identifier for the asset index, generally Minecraft's current major version - * @param assetsDir the directory in which to find vanilla assets and indexes - */ - public ExistingFileHelper(Collection existingPacks, final Set existingMods, boolean enable, @Nullable final String assetIndex, @Nullable final File assetsDir) { - List candidateClientResources = new ArrayList<>(); - List candidateServerResources = new ArrayList<>(); - - if (assetIndex != null && assetsDir != null && assetsDir.exists()) { - candidateClientResources.add(ClientPackSource.createVanillaPackSource(IndexedAssetSource.createIndexFs(assetsDir.toPath(), assetIndex))); - } - candidateServerResources.add(ServerPacksSource.createVanillaPackSource()); - for (Path existing : existingPacks) { - File file = existing.toFile(); - if (!file.exists()) - continue; - PackResources pack = file.isDirectory() ? new PathPackResources(new PackLocationInfo(file.getName(), Component.empty(), PackSource.BUILT_IN, Optional.empty()), file.toPath()) : new FilePackResources(new PackLocationInfo(file.getName(), Component.empty(), PackSource.BUILT_IN, Optional.empty()), new FilePackResources.SharedZipFileAccess(file), ""); - candidateClientResources.add(pack); - candidateServerResources.add(pack); - } - for (String existingMod : existingMods) { - IModFileInfo modFileInfo = ModList.get().getModFileById(existingMod); - if (modFileInfo != null) { - // Only opens primary packs - overlays are not currently considered for datagen - final String name = "mod/" + existingMod; - candidateClientResources.add(ResourcePackLoader.createPackForMod(modFileInfo).openPrimary(new PackLocationInfo(name, Component.empty(), PackSource.BUILT_IN, Optional.empty()))); - candidateServerResources.add(ResourcePackLoader.createPackForMod(modFileInfo).openPrimary(new PackLocationInfo(name, Component.empty(), PackSource.BUILT_IN, Optional.empty()))); - } - } - - this.clientResources = new MultiPackResourceManager(PackType.CLIENT_RESOURCES, candidateClientResources); - this.serverData = new MultiPackResourceManager(PackType.SERVER_DATA, candidateServerResources); - - this.enable = enable; - } - - private ResourceManager getManager(PackType packType) { - return packType == PackType.CLIENT_RESOURCES ? clientResources : serverData; - } - - private ResourceLocation getLocation(ResourceLocation base, String suffix, String prefix) { - return ResourceLocation.fromNamespaceAndPath(base.getNamespace(), prefix + "/" + base.getPath() + suffix); - } - - /** - * Check if a given resource exists in the known resource packs. - * - * @param loc the complete location of the resource, e.g. - * {@code "minecraft:textures/block/stone.png"} - * @param packType the type of resources to check - * @return {@code true} if the resource exists in any pack, {@code false} - * otherwise - */ - public boolean exists(ResourceLocation loc, PackType packType) { - if (!enable) { - return true; - } - return generated.get(packType).contains(loc) || getManager(packType).getResource(loc).isPresent(); - } - - /** - * Check if a given resource exists in the known resource packs. This is a - * convenience method to avoid repeating type/prefix/suffix and instead use the - * common definitions in {@link ResourceType}, or a custom {@link IResourceType} - * definition. - * - * @param loc the base location of the resource, e.g. - * {@code "minecraft:block/stone"} - * @param type a {@link IResourceType} describing how to form the path to the - * resource - * @return {@code true} if the resource exists in any pack, {@code false} - * otherwise - */ - public boolean exists(ResourceLocation loc, IResourceType type) { - return exists(getLocation(loc, type.getSuffix(), type.getPrefix()), type.getPackType()); - } - - /** - * Check if a given resource exists in the known resource packs. - * - * @param loc the base location of the resource, e.g. - * {@code "minecraft:block/stone"} - * @param packType the type of resources to check - * @param pathSuffix a string to append after the path, e.g. {@code ".json"} - * @param pathPrefix a string to append before the path, before a slash, e.g. - * {@code "models"} - * @return {@code true} if the resource exists in any pack, {@code false} - * otherwise - */ - public boolean exists(ResourceLocation loc, PackType packType, String pathSuffix, String pathPrefix) { - return exists(getLocation(loc, pathSuffix, pathPrefix), packType); - } - - /** - * Track the existence of a generated file. This is a convenience method to - * avoid repeating type/prefix/suffix and instead use the common definitions in - * {@link ResourceType}, or a custom {@link IResourceType} definition. - *

- * This should be called by data providers immediately when a new data object is - * created, i.e. not during - * {@link DataProvider#run(net.minecraft.data.CachedOutput) run} but instead - * when the "builder" (or whatever intermediate object) is created, such as a - * {@link ModelBuilder}. - *

- * This represents a promise to generate the file later, since other - * datagen may rely on this file existing. - * - * @param loc the base location of the resource, e.g. - * {@code "minecraft:block/stone"} - * @param type a {@link IResourceType} describing how to form the path to the - * resource - */ - public void trackGenerated(ResourceLocation loc, IResourceType type) { - this.generated.put(type.getPackType(), getLocation(loc, type.getSuffix(), type.getPrefix())); - } - - /** - * Track the existence of a generated file. - *

- * This should be called by data providers immediately when a new data object is - * created, i.e. not during - * {@link DataProvider#run(net.minecraft.data.CachedOutput) run} but instead - * when the "builder" (or whatever intermediate object) is created, such as a - * {@link ModelBuilder}. - *

- * This represents a promise to generate the file later, since other - * datagen may rely on this file existing. - * - * @param loc the base location of the resource, e.g. - * {@code "minecraft:block/stone"} - * @param packType the type of resources to check - * @param pathSuffix a string to append after the path, e.g. {@code ".json"} - * @param pathPrefix a string to append before the path, before a slash, e.g. - * {@code "models"} - */ - public void trackGenerated(ResourceLocation loc, PackType packType, String pathSuffix, String pathPrefix) { - this.generated.put(packType, getLocation(loc, pathSuffix, pathPrefix)); - } - - @VisibleForTesting - public Resource getResource(ResourceLocation loc, PackType packType, String pathSuffix, String pathPrefix) throws FileNotFoundException { - return getResource(getLocation(loc, pathSuffix, pathPrefix), packType); - } - - @VisibleForTesting - public Resource getResource(ResourceLocation loc, PackType packType) throws FileNotFoundException { - return getManager(packType).getResourceOrThrow(loc); - } - - @VisibleForTesting - public List getResourceStack(ResourceLocation loc, PackType packType) { - return getManager(packType).getResourceStack(loc); - } - - /** - * @return {@code true} if validation is enabled, {@code false} otherwise - */ - public boolean isEnabled() { - return enable; - } -} diff --git a/src/main/java/net/neoforged/neoforge/common/data/JsonCodecProvider.java b/src/main/java/net/neoforged/neoforge/common/data/JsonCodecProvider.java index db097c5d3dd..df993a37846 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/JsonCodecProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/JsonCodecProvider.java @@ -25,11 +25,9 @@ import net.minecraft.data.PackOutput; import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.PackType; import net.neoforged.neoforge.common.conditions.ConditionalOps; import net.neoforged.neoforge.common.conditions.ICondition; import net.neoforged.neoforge.common.conditions.WithConditions; -import net.neoforged.neoforge.common.data.ExistingFileHelper.ResourceType; import org.slf4j.Logger; /** @@ -44,9 +42,7 @@ */ public abstract class JsonCodecProvider implements DataProvider { private static final Logger LOGGER = LogUtils.getLogger(); - protected final ResourceType resourceType; protected final PackOutput.PathProvider pathProvider; - protected final ExistingFileHelper existingFileHelper; protected final CompletableFuture lookupProvider; protected final String modid; protected final String directory; @@ -55,22 +51,12 @@ public abstract class JsonCodecProvider implements DataProvider { /** * @param output {@linkplain PackOutput} provided by the {@link DataGenerator}. - * @param packType PackType specifying whether to generate entries in assets or data. * @param directory String representing the directory to generate jsons in, e.g. "dimension" or "cheesemod/cheese". * @param codec Codec to encode values to jsons with using the provided DynamicOps. */ - public JsonCodecProvider(PackOutput output, - PackOutput.Target target, - String directory, - PackType packType, - Codec codec, - CompletableFuture lookupProvider, - String modId, - ExistingFileHelper existingFileHelper) { + public JsonCodecProvider(PackOutput output, PackOutput.Target target, String directory, Codec codec, CompletableFuture lookupProvider, String modId) { // Track generated data so other dataproviders can validate if needed. - this.resourceType = new ResourceType(packType, ".json", directory); this.pathProvider = output.createPathProvider(target, directory); - this.existingFileHelper = existingFileHelper; this.modid = modId; this.directory = directory; this.codec = codec; @@ -119,8 +105,6 @@ public void conditionally(ResourceLocation id, Consumer withConditions) { - this.existingFileHelper.trackGenerated(id, this.resourceType); - this.conditions.put(id, withConditions); } } diff --git a/src/main/java/net/neoforged/neoforge/common/data/ParticleDescriptionProvider.java b/src/main/java/net/neoforged/neoforge/common/data/ParticleDescriptionProvider.java index 31902b82e48..267954afa7a 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/ParticleDescriptionProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/ParticleDescriptionProvider.java @@ -25,7 +25,6 @@ import net.minecraft.data.DataProvider; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.PackType; import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent; import net.neoforged.neoforge.data.event.GatherDataEvent; import org.jetbrains.annotations.VisibleForTesting; @@ -69,19 +68,15 @@ public abstract class ParticleDescriptionProvider implements DataProvider { private final PackOutput.PathProvider particlesPath; @VisibleForTesting - protected final ExistingFileHelper fileHelper; - @VisibleForTesting protected final Map> descriptions; /** * Creates an instance of the data provider. * - * @param output the expected root directory the data generator outputs to - * @param fileHelper the helper used to validate a texture's existence + * @param output the expected root directory the data generator outputs to */ - protected ParticleDescriptionProvider(PackOutput output, ExistingFileHelper fileHelper) { + protected ParticleDescriptionProvider(PackOutput output) { this.particlesPath = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, "particles"); - this.fileHelper = fileHelper; this.descriptions = new HashMap<>(); } @@ -200,8 +195,6 @@ protected void spriteSet(ParticleType type, Iterable textur // Validate textures List desc = new ArrayList<>(); for (var texture : textures) { - Preconditions.checkArgument(this.fileHelper.exists(texture, PackType.CLIENT_RESOURCES, ".png", "textures/particle"), - "Texture '%s' does not exist in any known resource pack", texture); desc.add(texture.toString()); } Preconditions.checkArgument(desc.size() > 0, "The particle type '%s' must have one texture", particle); diff --git a/src/main/java/net/neoforged/neoforge/common/data/SoundDefinitionsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/SoundDefinitionsProvider.java index fba916e81a5..1c6cf35b68f 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/SoundDefinitionsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/SoundDefinitionsProvider.java @@ -17,7 +17,6 @@ import net.minecraft.data.DataProvider; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.PackType; import net.minecraft.sounds.SoundEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -30,7 +29,6 @@ public abstract class SoundDefinitionsProvider implements DataProvider { private static final Logger LOGGER = LogManager.getLogger(); private final PackOutput output; private final String modId; - private final ExistingFileHelper helper; private final Map sounds = new LinkedHashMap<>(); @@ -39,12 +37,10 @@ public abstract class SoundDefinitionsProvider implements DataProvider { * * @param output The {@linkplain PackOutput} instance provided by the data generator. * @param modId The mod ID of the current mod. - * @param helper The existing file helper provided by the event you are initializing this provider in. */ - protected SoundDefinitionsProvider(final PackOutput output, final String modId, final ExistingFileHelper helper) { + protected SoundDefinitionsProvider(final PackOutput output, final String modId) { this.output = output; this.modId = modId; - this.helper = helper; } /** @@ -194,38 +190,15 @@ private void validate() { } private boolean validate(final String name, final SoundDefinition def) { - return def.soundList().stream().allMatch(it -> this.validate(name, it)); - } - - private boolean validate(final String name, final SoundDefinition.Sound sound) { - switch (sound.type()) { - case SOUND: - return this.validateSound(name, sound.name()); - case EVENT: - return this.validateEvent(name, sound.name()); - } - // Differently from all the other errors, this is not a 'missing sound' but rather something completely different - // that has broken the invariants of this sound definition's provider. In fact, a sound may only be either of - // SOUND or EVENT type. Any other values is somebody messing with the internals, reflectively adding something - // to an enum or passing `null` to a parameter that isn't annotated with `@Nullable`. - throw new IllegalArgumentException("The given sound '" + sound.name() + "' does not have a valid type: expected either SOUND or EVENT, but found " + sound.type()); - } - - private boolean validateSound(final String soundName, final ResourceLocation name) { - final boolean valid = this.helper.exists(name, PackType.CLIENT_RESOURCES, ".ogg", "sounds"); - if (!valid) { - final String path = name.getNamespace() + ":sounds/" + name.getPath() + ".ogg"; - LOGGER.warn("Unable to find corresponding OGG file '{}' for sound event '{}'", path, soundName); - } - return valid; - } - - private boolean validateEvent(final String soundName, final ResourceLocation name) { - final boolean valid = this.sounds.containsKey(soundName) || BuiltInRegistries.SOUND_EVENT.containsKey(name); - if (!valid) { - LOGGER.warn("Unable to find event '{}' referenced from '{}'", name, soundName); - } - return valid; + return def.soundList().stream() + .filter(it -> it.type() == SoundDefinition.SoundType.EVENT) + .allMatch(it -> { + final boolean valid = this.sounds.containsKey(name) || BuiltInRegistries.SOUND_EVENT.containsKey(it.name()); + if (!valid) { + LOGGER.warn("Unable to find event '{}' referenced from '{}'", it.name(), name); + } + return valid; + }); } private CompletableFuture save(final CachedOutput cache, final Path targetFile) { diff --git a/src/main/java/net/neoforged/neoforge/common/data/SpriteSourceProvider.java b/src/main/java/net/neoforged/neoforge/common/data/SpriteSourceProvider.java index 98c55018546..62817669d41 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/SpriteSourceProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/SpriteSourceProvider.java @@ -15,7 +15,6 @@ import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.PackType; /** *

Data provider for atlas configuration files.
@@ -38,13 +37,13 @@ public abstract class SpriteSourceProvider extends JsonCodecProvider atlases = new HashMap<>(); - public SpriteSourceProvider(PackOutput output, CompletableFuture lookupProvider, String modId, ExistingFileHelper existingFileHelper) { - super(output, PackOutput.Target.RESOURCE_PACK, "atlases", PackType.CLIENT_RESOURCES, SpriteSources.FILE_CODEC, lookupProvider, modId, existingFileHelper); + public SpriteSourceProvider(PackOutput output, CompletableFuture lookupProvider, String modId) { + super(output, PackOutput.Target.RESOURCE_PACK, "atlases", SpriteSources.FILE_CODEC, lookupProvider, modId); } /** * Get or create a {@link SourceList} for the given atlas - * + * * @param id The texture atlas the sources should be added to, see constants at the top for the format * and the vanilla atlases * @return an existing {@code SourceList} for the given atlas or a new one if not present yet @@ -60,7 +59,7 @@ protected final SourceList atlas(ResourceLocation id) { protected record SourceList(List sources) { /** * Add the given {@link SpriteSource} to this atlas configuration - * + * * @param source The {@code SpriteSource} to be added */ public SourceList addSource(SpriteSource source) { 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 55477b729a5..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,16 +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 net.neoforged.neoforge.common.data.ExistingFileHelper; import org.jetbrains.annotations.Nullable; public class NeoForgeAdvancementProvider extends AdvancementProvider { - public NeoForgeAdvancementProvider(PackOutput output, CompletableFuture registries, ExistingFileHelper existingFileHelper) { - super(output, registries, existingFileHelper, getVanillaAdvancementProviders(output, registries)); + public NeoForgeAdvancementProvider(PackOutput output, CompletableFuture registries) { + super(output, registries, getVanillaAdvancementProviders(output, registries)); } - private static List 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)); @@ -86,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(); } @@ -247,9 +246,9 @@ 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, ExistingFileHelper existingFileHelper) { + public void generate(HolderLookup.Provider registries, Consumer saver) { // Warning: ugly code here. // Wrap the registries to allow using any tag. This is used to make decoding using the codec work in `replacePlayerPredicate`. var registriesWithAnyTag = new HolderLookup.Provider() { @@ -298,7 +297,7 @@ public Optional> get(TagKey tagKey) { vanillaProvider.generate(registriesWithAnyTag, advancementHolder -> { Advancement.Builder newBuilder = findAndReplaceInHolder(advancementHolder, registriesWithAnyTag); if (newBuilder != null) { - newBuilder.save(saver, advancementHolder.id(), existingFileHelper); + newBuilder.save(saver, advancementHolder.id()); } }); } diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeBiomeTagsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeBiomeTagsProvider.java index dc3c91284de..df51c0d2a2d 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeBiomeTagsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeBiomeTagsProvider.java @@ -16,11 +16,10 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biomes; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.data.ExistingFileHelper; public final class NeoForgeBiomeTagsProvider extends BiomeTagsProvider { - public NeoForgeBiomeTagsProvider(PackOutput output, CompletableFuture lookupProvider, ExistingFileHelper existingFileHelper) { - super(output, lookupProvider, "neoforge", existingFileHelper); + public NeoForgeBiomeTagsProvider(PackOutput output, CompletableFuture lookupProvider) { + super(output, lookupProvider, "neoforge"); } @Override diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeBlockTagsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeBlockTagsProvider.java index c8455ac2b73..57f1e68922e 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeBlockTagsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeBlockTagsProvider.java @@ -20,12 +20,10 @@ import net.minecraft.world.level.block.Blocks; import net.neoforged.neoforge.common.Tags; import net.neoforged.neoforge.common.data.BlockTagsProvider; -import net.neoforged.neoforge.common.data.ExistingFileHelper; -import org.jetbrains.annotations.Nullable; public final class NeoForgeBlockTagsProvider extends BlockTagsProvider { - public NeoForgeBlockTagsProvider(PackOutput output, CompletableFuture lookupProvider, @Nullable ExistingFileHelper existingFileHelper) { - super(output, lookupProvider, "neoforge", existingFileHelper); + public NeoForgeBlockTagsProvider(PackOutput output, CompletableFuture lookupProvider) { + super(output, lookupProvider, "neoforge"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeDamageTypeTagsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeDamageTypeTagsProvider.java index 4bea60e3848..d215a477192 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeDamageTypeTagsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeDamageTypeTagsProvider.java @@ -22,11 +22,10 @@ import net.minecraft.world.damagesource.DamageTypes; import net.neoforged.neoforge.common.NeoForgeMod; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.data.ExistingFileHelper; public final class NeoForgeDamageTypeTagsProvider extends DamageTypeTagsProvider { - public NeoForgeDamageTypeTagsProvider(PackOutput output, CompletableFuture lookupProvider, ExistingFileHelper existingFileHelper) { - super(output, lookupProvider, "neoforge", existingFileHelper); + public NeoForgeDamageTypeTagsProvider(PackOutput output, CompletableFuture lookupProvider) { + super(output, lookupProvider, "neoforge"); } private final Map vanillaBuilders = Maps.newLinkedHashMap(); @@ -48,7 +47,7 @@ protected void addTags(HolderLookup.Provider lookupProvider) { super.addTags(lookupProvider); inVanilla = false; - tag(NeoForgeMod.POISON_DAMAGE, Tags.DamageTypes.IS_POISON); + tag(Tags.DamageTypes.IS_POISON).addOptional(NeoForgeMod.POISON_DAMAGE.location()); tag(DamageTypes.WITHER, Tags.DamageTypes.IS_WITHER); tag(DamageTypes.WITHER_SKULL, Tags.DamageTypes.IS_WITHER); diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeEnchantmentTagsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeEnchantmentTagsProvider.java index b115bf69900..eec104bd4b2 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeEnchantmentTagsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeEnchantmentTagsProvider.java @@ -11,11 +11,10 @@ import net.minecraft.data.tags.EnchantmentTagsProvider; import net.minecraft.world.item.enchantment.Enchantments; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.data.ExistingFileHelper; public final class NeoForgeEnchantmentTagsProvider extends EnchantmentTagsProvider { - public NeoForgeEnchantmentTagsProvider(PackOutput output, CompletableFuture lookupProvider, ExistingFileHelper existingFileHelper) { - super(output, lookupProvider, "neoforge", existingFileHelper); + public NeoForgeEnchantmentTagsProvider(PackOutput output, CompletableFuture lookupProvider) { + super(output, lookupProvider, "neoforge"); } @Override diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeEntityTypeTagsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeEntityTypeTagsProvider.java index 23c7aeda23d..3a1062c0c45 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeEntityTypeTagsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeEntityTypeTagsProvider.java @@ -13,11 +13,10 @@ import net.minecraft.tags.EntityTypeTags; import net.minecraft.world.entity.EntityType; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.data.ExistingFileHelper; public class NeoForgeEntityTypeTagsProvider extends EntityTypeTagsProvider { - public NeoForgeEntityTypeTagsProvider(PackOutput output, CompletableFuture lookupProvider, ExistingFileHelper existingFileHelper) { - super(output, lookupProvider, "neoforge", existingFileHelper); + public NeoForgeEntityTypeTagsProvider(PackOutput output, CompletableFuture lookupProvider) { + super(output, lookupProvider, "neoforge"); } @Override diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeFluidTagsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeFluidTagsProvider.java index 5d96ec98ba1..4ec59eae499 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeFluidTagsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeFluidTagsProvider.java @@ -15,11 +15,10 @@ import net.minecraft.world.level.material.Fluid; import net.neoforged.neoforge.common.NeoForgeMod; import net.neoforged.neoforge.common.Tags.Fluids; -import net.neoforged.neoforge.common.data.ExistingFileHelper; public final class NeoForgeFluidTagsProvider extends FluidTagsProvider { - public NeoForgeFluidTagsProvider(PackOutput output, CompletableFuture lookupProvider, ExistingFileHelper existingFileHelper) { - super(output, lookupProvider, "neoforge", existingFileHelper); + public NeoForgeFluidTagsProvider(PackOutput output, CompletableFuture lookupProvider) { + super(output, lookupProvider, "neoforge"); } @Override diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeItemTagsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeItemTagsProvider.java index 99ed40f00ec..6601e0ae01b 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeItemTagsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeItemTagsProvider.java @@ -21,11 +21,10 @@ import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Block; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.data.ExistingFileHelper; public final class NeoForgeItemTagsProvider extends ItemTagsProvider { - public NeoForgeItemTagsProvider(PackOutput output, CompletableFuture lookupProvider, CompletableFuture> blockTagProvider, ExistingFileHelper existingFileHelper) { - super(output, lookupProvider, blockTagProvider, "neoforge", existingFileHelper); + public NeoForgeItemTagsProvider(PackOutput output, CompletableFuture lookupProvider, CompletableFuture> blockTagProvider) { + super(output, lookupProvider, blockTagProvider, "neoforge"); } @SuppressWarnings("unchecked") diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeSpriteSourceProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeSpriteSourceProvider.java index a3de59b56d8..6e2b605fad9 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeSpriteSourceProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeSpriteSourceProvider.java @@ -11,12 +11,11 @@ import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; -import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.neoforged.neoforge.common.data.SpriteSourceProvider; public class NeoForgeSpriteSourceProvider extends SpriteSourceProvider { - public NeoForgeSpriteSourceProvider(PackOutput output, CompletableFuture lookupProvider, ExistingFileHelper fileHelper) { - super(output, lookupProvider, "neoforge", fileHelper); + public NeoForgeSpriteSourceProvider(PackOutput output, CompletableFuture lookupProvider) { + super(output, lookupProvider, "neoforge"); } @Override diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeStructureTagsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeStructureTagsProvider.java index 532a394f919..6156fee4d01 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeStructureTagsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeStructureTagsProvider.java @@ -10,11 +10,10 @@ import net.minecraft.data.PackOutput; import net.minecraft.data.tags.StructureTagsProvider; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.data.ExistingFileHelper; public final class NeoForgeStructureTagsProvider extends StructureTagsProvider { - public NeoForgeStructureTagsProvider(PackOutput output, CompletableFuture lookupProvider, ExistingFileHelper existingFileHelper) { - super(output, lookupProvider, "neoforge", existingFileHelper); + public NeoForgeStructureTagsProvider(PackOutput output, CompletableFuture lookupProvider) { + super(output, lookupProvider, "neoforge"); } @Override diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/VanillaSoundDefinitionsProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/VanillaSoundDefinitionsProvider.java index c02816a4118..379791ac28a 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/VanillaSoundDefinitionsProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/VanillaSoundDefinitionsProvider.java @@ -7,12 +7,11 @@ import net.minecraft.data.PackOutput; import net.neoforged.neoforge.common.NeoForgeMod; -import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.neoforged.neoforge.common.data.SoundDefinitionsProvider; public class VanillaSoundDefinitionsProvider extends SoundDefinitionsProvider { - public VanillaSoundDefinitionsProvider(PackOutput output, ExistingFileHelper helper) { - super(output, "minecraft", helper); + public VanillaSoundDefinitionsProvider(PackOutput output) { + super(output, "minecraft"); } @Override diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IAdvancementBuilderExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IAdvancementBuilderExtension.java index 0e2681240ff..b9223271022 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IAdvancementBuilderExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IAdvancementBuilderExtension.java @@ -5,13 +5,10 @@ package net.neoforged.neoforge.common.extensions; -import java.util.Optional; import java.util.function.Consumer; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.PackType; -import net.neoforged.neoforge.common.data.ExistingFileHelper; public interface IAdvancementBuilderExtension { private Advancement.Builder self() { @@ -19,26 +16,16 @@ private Advancement.Builder self() { } /** - * Saves this builder with the given id using the {@link ExistingFileHelper} to check if the parent is already known. + * Saves this builder with the given id. * - * @param saver a {@link Consumer} which saves any advancements provided - * @param id the {@link ResourceLocation} id for the new advancement - * @param fileHelper the {@link ExistingFileHelper} where all known advancements are registered + * @param saver a {@link Consumer} which saves any advancements provided + * @param id the {@link ResourceLocation} id for the new advancement * @return the built advancement * @throws IllegalStateException if the parent of the advancement is not known */ - default AdvancementHolder save(Consumer saver, ResourceLocation id, ExistingFileHelper fileHelper) { + default AdvancementHolder save(Consumer saver, ResourceLocation id) { AdvancementHolder advancementholder = self().build(id); - - Optional parent = advancementholder.value().parent(); - if (parent.isPresent() && !fileHelper.exists(parent.get(), PackType.SERVER_DATA, ".json", "advancement")) { - throw new IllegalStateException("The parent: '%s' of advancement '%s', has not been saved yet!".formatted( - parent.orElseThrow(), - id)); - } - saver.accept(advancementholder); - fileHelper.trackGenerated(id, PackType.SERVER_DATA, ".json", "advancement"); return advancementholder; } } diff --git a/src/main/java/net/neoforged/neoforge/data/event/GatherDataEvent.java b/src/main/java/net/neoforged/neoforge/data/event/GatherDataEvent.java index f35bb1768a1..01327891148 100644 --- a/src/main/java/net/neoforged/neoforge/data/event/GatherDataEvent.java +++ b/src/main/java/net/neoforged/neoforge/data/event/GatherDataEvent.java @@ -5,6 +5,8 @@ package net.neoforged.neoforge.data.event; +import com.google.common.collect.Lists; +import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Path; @@ -13,40 +15,62 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Predicate; import java.util.stream.Collectors; import net.minecraft.DetectedVersion; +import net.minecraft.client.resources.ClientPackSource; +import net.minecraft.client.resources.IndexedAssetSource; import net.minecraft.core.HolderLookup; import net.minecraft.data.DataGenerator; import net.minecraft.data.DataProvider; import net.minecraft.data.PackOutput; import net.minecraft.data.tags.TagsProvider; +import net.minecraft.network.chat.Component; +import net.minecraft.server.packs.PackLocationInfo; +import net.minecraft.server.packs.PackResources; +import net.minecraft.server.packs.PackType; +import net.minecraft.server.packs.PathPackResources; +import net.minecraft.server.packs.repository.PackSource; +import net.minecraft.server.packs.repository.ServerPacksSource; +import net.minecraft.server.packs.resources.MultiPackResourceManager; +import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.neoforged.bus.api.Event; import net.neoforged.fml.ModContainer; +import net.neoforged.fml.ModList; import net.neoforged.fml.event.IModBusEvent; -import net.neoforged.neoforge.common.data.ExistingFileHelper; +import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.neoforge.resource.ResourcePackLoader; +import org.jetbrains.annotations.Nullable; public abstract class GatherDataEvent extends Event implements IModBusEvent { private final DataGenerator dataGenerator; private final DataGeneratorConfig config; - private final ExistingFileHelper existingFileHelper; private final ModContainer modContainer; - public GatherDataEvent(final ModContainer mc, final DataGenerator dataGenerator, final DataGeneratorConfig dataGeneratorConfig, ExistingFileHelper existingFileHelper) { + public GatherDataEvent(final ModContainer mc, final DataGenerator dataGenerator, final DataGeneratorConfig dataGeneratorConfig) { this.modContainer = mc; this.dataGenerator = dataGenerator; this.config = dataGeneratorConfig; - this.existingFileHelper = existingFileHelper; } public ModContainer getModContainer() { return this.modContainer; } + public ResourceManager getResourceManager(PackType packType) { + return switch (packType) { + case CLIENT_RESOURCES -> config.clientResourceManager; + case SERVER_DATA -> config.serverResourceManager; + }; + } + public Collection getInputs() { return this.config.getInputs(); } @@ -55,10 +79,6 @@ public DataGenerator getGenerator() { return this.dataGenerator; } - public ExistingFileHelper getExistingFileHelper() { - return existingFileHelper; - } - public CompletableFuture getLookupProvider() { return this.config.lookupProvider; } @@ -76,14 +96,14 @@ public boolean validate() { } public static class Server extends GatherDataEvent { - public Server(ModContainer mc, DataGenerator dataGenerator, DataGeneratorConfig dataGeneratorConfig, ExistingFileHelper existingFileHelper) { - super(mc, dataGenerator, dataGeneratorConfig, existingFileHelper); + public Server(ModContainer mc, DataGenerator dataGenerator, DataGeneratorConfig dataGeneratorConfig) { + super(mc, dataGenerator, dataGeneratorConfig); } } public static class Client extends GatherDataEvent { - public Client(ModContainer mc, DataGenerator dataGenerator, DataGeneratorConfig dataGeneratorConfig, ExistingFileHelper existingFileHelper) { - super(mc, dataGenerator, dataGeneratorConfig, existingFileHelper); + public Client(ModContainer mc, DataGenerator dataGenerator, DataGeneratorConfig dataGeneratorConfig) { + super(mc, dataGenerator, dataGeneratorConfig); } } @@ -97,9 +117,11 @@ public static class DataGeneratorConfig { private final boolean validate; private final boolean flat; private final List generators = new ArrayList<>(); + private final ResourceManager clientResourceManager; + private final ResourceManager serverResourceManager; public DataGeneratorConfig(final Set mods, final Path path, final Collection inputs, final CompletableFuture lookupProvider, - final boolean dev, final boolean reports, final boolean validate, final boolean flat, final DataGenerator vanillaGenerator) { + final boolean dev, final boolean reports, final boolean validate, final boolean flat, final DataGenerator vanillaGenerator, final @Nullable String assetIndex, final @Nullable File assetsDir, Collection existingPacks) { this.mods = mods; this.path = path; this.inputs = inputs; @@ -108,6 +130,14 @@ public DataGeneratorConfig(final Set mods, final Path path, final Collec this.reports = reports; this.validate = validate; this.flat = flat; + + clientResourceManager = createResourceManager(PackType.CLIENT_RESOURCES, mods::contains, existingPacks, consumer -> { + if (FMLEnvironment.dist.isClient() && assetIndex != null && assetsDir != null) + consumer.accept(ClientPackSource.createVanillaPackSource(IndexedAssetSource.createIndexFs(assetsDir.toPath(), assetIndex))); + }); + + serverResourceManager = createResourceManager(PackType.SERVER_DATA, mods::contains, existingPacks, consumer -> consumer.accept(ServerPacksSource.createVanillaPackSource())); + if (mods.contains("minecraft") || mods.isEmpty()) { this.generators.add(vanillaGenerator); } @@ -146,6 +176,34 @@ public void runAll() { } }); } + + private static ResourceManager createResourceManager(PackType packType, Predicate isGeneratedMod, Collection existingPacks, Consumer> consumer) { + var packs = Lists.newArrayList(); + // include vanilla resource packs first + consumer.accept(packs::add); + + // include existing packs + existingPacks.forEach(path -> { + var packInfo = new PackLocationInfo(path.getFileName().toString(), Component.empty(), PackSource.BUILT_IN, Optional.empty()); + packs.add(new PathPackResources(packInfo, path)); + }); + + // include mod resources last + ModList.get().getSortedMods().stream() + // ignore 'minecraft' mod, this is added via `[Server|Client]PackSource` + .filter(Predicate.not(mod -> mod.getModId().equals("minecraft"))) + // ignore actively generated models, their resource packs should be included using `--existing ` + // this is to workaround accidentally including resources being actively generated + .filter(Predicate.not(mod -> isGeneratedMod.test(mod.getModId()))) + .map(mod -> { + var owningFile = mod.getModInfo().getOwningFile(); + var packInfo = new PackLocationInfo("mod/" + mod.getModId(), Component.empty(), PackSource.BUILT_IN, Optional.empty()); + return ResourcePackLoader.createPackForMod(owningFile).openPrimary(packInfo); + }) + .forEach(packs::add); + + return new MultiPackResourceManager(packType, packs); + } } public T addProvider(T provider) { @@ -156,21 +214,13 @@ public T createProvider(DataProviderFromOutput build return addProvider(builder.create(dataGenerator.getPackOutput())); } - public T createProvider(DataProviderFromOutputFileHelper builder) { - return addProvider(builder.create(dataGenerator.getPackOutput(), existingFileHelper)); - } - public T createProvider(DataProviderFromOutputLookup builder) { return addProvider(builder.create(dataGenerator.getPackOutput(), config.lookupProvider)); } - public T createProvider(DataProviderFromOutputLookupFileHelper builder) { - return addProvider(builder.create(dataGenerator.getPackOutput(), config.lookupProvider, existingFileHelper)); - } - - public void createBlockAndItemTags(DataProviderFromOutputLookupFileHelper> blockTagsProvider, ItemTagsProvider itemTagsProvider) { + public void createBlockAndItemTags(DataProviderFromOutputLookup> blockTagsProvider, ItemTagsProvider itemTagsProvider) { var blockTags = createProvider(blockTagsProvider); - addProvider(itemTagsProvider.create(this.getGenerator().getPackOutput(), this.getLookupProvider(), blockTags.contentsGetter(), this.getExistingFileHelper())); + addProvider(itemTagsProvider.create(this.getGenerator().getPackOutput(), this.getLookupProvider(), blockTags.contentsGetter())); } @FunctionalInterface @@ -183,23 +233,13 @@ public interface DataProviderFromOutputLookup { T create(PackOutput output, CompletableFuture lookupProvider); } - @FunctionalInterface - public interface DataProviderFromOutputFileHelper { - T create(PackOutput output, ExistingFileHelper existingFileHelper); - } - - @FunctionalInterface - public interface DataProviderFromOutputLookupFileHelper { - T create(PackOutput output, CompletableFuture lookupProvider, ExistingFileHelper existingFileHelper); - } - @FunctionalInterface public interface GatherDataEventGenerator { - GatherDataEvent create(final ModContainer mc, final DataGenerator dataGenerator, final DataGeneratorConfig dataGeneratorConfig, ExistingFileHelper existingFileHelper); + GatherDataEvent create(final ModContainer mc, final DataGenerator dataGenerator, final DataGeneratorConfig dataGeneratorConfig); } @FunctionalInterface public interface ItemTagsProvider { - TagsProvider create(PackOutput output, CompletableFuture lookupProvider, CompletableFuture> contentsGetter, ExistingFileHelper existingFileHelper); + TagsProvider create(PackOutput output, CompletableFuture lookupProvider, CompletableFuture> contentsGetter); } } diff --git a/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java b/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java index faa52ca084e..6540788c64d 100644 --- a/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java +++ b/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java @@ -16,18 +16,17 @@ import net.minecraft.data.registries.VanillaRegistries; import net.minecraft.server.Bootstrap; import net.neoforged.fml.ModLoader; -import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.neoforged.neoforge.data.event.GatherDataEvent; import net.neoforged.neoforge.internal.CommonModLoader; import net.neoforged.neoforge.internal.RegistrationEvents; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; public class DatagenModLoader extends CommonModLoader { private static final Logger LOGGER = LogManager.getLogger(); private static GatherDataEvent.DataGeneratorConfig dataGeneratorConfig; - private static ExistingFileHelper existingFileHelper; private static boolean runningDataGen; public static boolean isRunningDataGen() { @@ -36,8 +35,8 @@ public static boolean isRunningDataGen() { @ApiStatus.Internal public static void begin(final Set mods, final Path path, final Collection inputs, Collection existingPacks, - Set existingMods, final boolean devToolGenerators, final boolean reportsGenerator, - final boolean structureValidator, final boolean flat, final String assetIndex, final File assetsDir, Runnable setup, GatherDataEvent.GatherDataEventGenerator eventGenerator, + final boolean devToolGenerators, final boolean reportsGenerator, + final boolean structureValidator, final boolean flat, @Nullable final String assetIndex, @Nullable final File assetsDir, Runnable setup, GatherDataEvent.GatherDataEventGenerator eventGenerator, DataGenerator vanillaGenerator) { if (mods.contains("minecraft") && mods.size() == 1) return; @@ -48,15 +47,10 @@ public static void begin(final Set mods, final Path path, final Collecti // Modify components as the (modified) defaults may be required in datagen, i.e. stack size RegistrationEvents.modifyComponents(); CompletableFuture lookupProvider = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor()); - dataGeneratorConfig = new GatherDataEvent.DataGeneratorConfig(mods, path, inputs, lookupProvider, devToolGenerators, reportsGenerator, structureValidator, flat, vanillaGenerator); - if (!mods.contains("neoforge")) { - // If we aren't generating data for forge, automatically add forge as an existing so mods can access forge's data - existingMods.add("neoforge"); - } + dataGeneratorConfig = new GatherDataEvent.DataGeneratorConfig(mods, path, inputs, lookupProvider, devToolGenerators, reportsGenerator, structureValidator, flat, vanillaGenerator, assetIndex, assetsDir, existingPacks); setup.run(); - existingFileHelper = new ExistingFileHelper(existingPacks, existingMods, structureValidator, assetIndex, assetsDir); ModLoader.runEventGenerator(mc -> eventGenerator.create(mc, dataGeneratorConfig.makeGenerator(p -> dataGeneratorConfig.isFlat() ? p : p.resolve(mc.getModId()), - dataGeneratorConfig.getMods().contains(mc.getModId())), dataGeneratorConfig, existingFileHelper)); + dataGeneratorConfig.getMods().contains(mc.getModId())), dataGeneratorConfig)); dataGeneratorConfig.runAll(); } } diff --git a/testframework/src/main/java/net/neoforged/testframework/impl/reg/RegistrationHelperImpl.java b/testframework/src/main/java/net/neoforged/testframework/impl/reg/RegistrationHelperImpl.java index 1382949cf2f..5942d182c1d 100644 --- a/testframework/src/main/java/net/neoforged/testframework/impl/reg/RegistrationHelperImpl.java +++ b/testframework/src/main/java/net/neoforged/testframework/impl/reg/RegistrationHelperImpl.java @@ -39,7 +39,6 @@ import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModContainer; import net.neoforged.neoforge.attachment.AttachmentType; -import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.neoforged.neoforge.common.data.GlobalLootModifierProvider; import net.neoforged.neoforge.common.data.LanguageProvider; import net.neoforged.neoforge.data.event.GatherDataEvent; @@ -61,7 +60,7 @@ public RegistrationHelperImpl(String modId) { } private interface DataGenProvider { - T create(PackOutput output, CompletableFuture registries, DataGenerator generator, ExistingFileHelper existingFileHelper, String modId, List> consumers); + T create(PackOutput output, CompletableFuture registries, DataGenerator generator, String modId, List> consumers); } private static final Map, DataGenProvider> PROVIDERS; @@ -74,13 +73,13 @@ void register(Class type, DataGenProvider provide } final var reg = new ProviderRegistrar(); - reg.register(LanguageProvider.class, (output, registries, generator, existingFileHelper, modId, consumers) -> new LanguageProvider(output, modId, "en_us") { + reg.register(LanguageProvider.class, (output, registries, generator, modId, consumers) -> new LanguageProvider(output, modId, "en_us") { @Override protected void addTranslations() { consumers.forEach(c -> c.accept(this)); } }); - reg.register(GlobalLootModifierProvider.class, (output, registries, generator, existingFileHelper, modId, consumers) -> new GlobalLootModifierProvider(output, registries, modId) { + reg.register(GlobalLootModifierProvider.class, (output, registries, generator, modId, consumers) -> new GlobalLootModifierProvider(output, registries, modId) { @Override protected void start() { consumers.forEach(c -> c.accept(this)); @@ -232,7 +231,7 @@ private void gatherClient(final GatherDataEvent.Client event) { private void gather(final T event, ListMultimap, Consumer> providers, List> directProviders) { providers.asMap().forEach((cls, cons) -> event.getGenerator().addProvider(true, PROVIDERS.get(cls).create( - event.getGenerator().getPackOutput(), event.getLookupProvider(), event.getGenerator(), event.getExistingFileHelper(), modId, (List) cons))); + event.getGenerator().getPackOutput(), event.getLookupProvider(), event.getGenerator(), modId, (List) cons))); directProviders.forEach(func -> event.getGenerator().addProvider(true, new DataProvider() { final DataProvider p = func.apply(event); diff --git a/tests/build.gradle b/tests/build.gradle index d432eaa198e..898423ccca2 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -91,7 +91,6 @@ neoDev { '--mod', 'custom_preset_editor_test', '--mod', 'custom_predicate_test', '--mod', 'neotests', - '--existing-mod', 'testframework', '--existing', project.file("src/main/resources").absolutePath, '--output', project.file("src/generated/resources").absolutePath } 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 b17af6164c4..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; @@ -95,13 +95,12 @@ static void customPredicateTest(final DynamicTest test, final RegistrationHelper reg.addClientProvider(event -> new AdvancementProvider( event.getGenerator().getPackOutput(), event.getLookupProvider(), - event.getExistingFileHelper(), - List.of((registries, saver, existingFileHelper) -> { + List.of((registries, saver) -> { Advancement.Builder.advancement() .parent(ResourceLocation.withDefaultNamespace("story/root")) .display(Items.ANVIL, Component.literal("Named!"), Component.literal("Get a named item"), null, AdvancementType.TASK, true, true, false) .addCriterion("has_named_item", InventoryChangeTrigger.TriggerInstance.hasItems(ItemPredicate.Builder.item().withSubPredicate(type, new CustomNamePredicate(1, 2)))) - .save(saver, ResourceLocation.fromNamespaceAndPath(reg.modId(), "named_item"), existingFileHelper); + .save(saver, ResourceLocation.fromNamespaceAndPath(reg.modId(), "named_item")); }))); test.onGameTest(helper -> { 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 ccd65e4e6a0..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,15 +33,15 @@ 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, existingFileHelper) -> 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( Optional.empty(), InventoryChangeTrigger.TriggerInstance.Slots.ANY, List.of( ItemPredicate.Builder.item().of(registries.lookupOrThrow(Registries.ITEM), Items.TURTLE_SCUTE).build())))) .rewards(AdvancementRewards.Builder.recipe(ResourceKey.create(Registries.RECIPE, ResourceLocation.fromNamespaceAndPath("minecraft", "turtle_helmet")))) - .save(saver, testAdvancement, existingFileHelper)); - return new AdvancementProvider(event.getGenerator().getPackOutput(), event.getLookupProvider(), event.getExistingFileHelper(), generators); + .save(saver, testAdvancement)); + return new AdvancementProvider(event.getGenerator().getPackOutput(), event.getLookupProvider(), generators); }); test.eventListeners().forge().addListener((OnDatapackSyncEvent event) -> { 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 ea89d90f541..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; @@ -60,6 +62,7 @@ import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.metadata.pack.PackMetadataSection; import net.minecraft.server.packs.resources.Resource; +import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.sounds.SoundEvents; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; @@ -87,10 +90,8 @@ 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.ExistingFileHelper; import net.neoforged.neoforge.common.data.GeneratingOverlayMetadataSection; import net.neoforged.neoforge.common.data.LanguageProvider; import net.neoforged.neoforge.common.data.ParticleDescriptionProvider; @@ -141,12 +142,12 @@ public static void gatherData(GatherDataEvent.Client event) { DetectedVersion.BUILT_IN.getPackVersion(PackType.CLIENT_RESOURCES), Optional.of(new InclusiveRange<>(0, Integer.MAX_VALUE))))); gen.addProvider(true, new Lang(packOutput)); - gen.addProvider(true, new SoundDefinitions(packOutput, event.getExistingFileHelper())); - gen.addProvider(true, new ParticleDescriptions(packOutput, event.getExistingFileHelper())); + gen.addProvider(true, new SoundDefinitions(packOutput, event.getResourceManager(PackType.CLIENT_RESOURCES))); + gen.addProvider(true, new ParticleDescriptions(packOutput, event.getResourceManager(PackType.CLIENT_RESOURCES))); gen.addProvider(true, new Recipes.Runner(packOutput, lookupProvider)); - gen.addProvider(true, new Tags(packOutput, lookupProvider, event.getExistingFileHelper())); - gen.addProvider(true, new AdvancementProvider(packOutput, lookupProvider, event.getExistingFileHelper(), List.of(new Advancements()))); + gen.addProvider(true, new Tags(packOutput, lookupProvider)); + gen.addProvider(true, new AdvancementProvider(packOutput, lookupProvider, List.of(new Advancements()))); gen.addProvider(true, new DatapackBuiltinEntriesProvider(packOutput, lookupProvider, BUILDER, Set.of(MODID))); } @@ -283,11 +284,13 @@ public String getName() { public static class SoundDefinitions extends SoundDefinitionsProvider { private static final Logger LOGGER = LogManager.getLogger(); - private final ExistingFileHelper helper; - public SoundDefinitions(final PackOutput output, final ExistingFileHelper helper) { - super(output, MODID, helper); - this.helper = helper; + private final ResourceManager resourceManager; + + public SoundDefinitions(final PackOutput output, final ResourceManager resourceManager) { + super(output, MODID); + + this.resourceManager = resourceManager; } @Override @@ -361,7 +364,7 @@ private void test() { } final JsonObject actual; try { - List resourceStack = this.helper.getResourceStack(ResourceLocation.withDefaultNamespace("sounds.json"), PackType.CLIENT_RESOURCES); + List resourceStack = this.resourceManager.getResourceStack(ResourceLocation.withDefaultNamespace("sounds.json")); // Get the first resource in the stack // This guarantees vanilla even when a forge sounds.json is present because getResourceStack reverses the list // so that the lower priority resources are first (to allow overwriting data in later entries) @@ -475,8 +478,8 @@ private List compareArrays(final JsonArray vanilla, final JsonElement ge } public static class Tags extends BlockTagsProvider { - public Tags(PackOutput output, CompletableFuture lookupProvider, @Nullable ExistingFileHelper existingFileHelper) { - super(output, lookupProvider, MODID, existingFileHelper); + public Tags(PackOutput output, CompletableFuture lookupProvider) { + super(output, lookupProvider, MODID); } @Override @@ -519,9 +522,9 @@ 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, ExistingFileHelper existingFileHelper) { + public void generate(HolderLookup.Provider registries, Consumer saver) { var obtainDirt = Advancement.Builder.advancement() .display(Items.DIRT, Component.translatable(Items.DIRT.getDescriptionId()), @@ -532,7 +535,7 @@ public void generate(HolderLookup.Provider registries, Consumer run(CachedOutput cache) { private void validateResults() { var errors = Stream.of(ParticleTypes.DRIPPING_LAVA, ParticleTypes.CLOUD, ParticleTypes.FISHING, ParticleTypes.ENCHANT) .map(BuiltInRegistries.PARTICLE_TYPE::getKey).map(particle -> { - try (var resource = this.fileHelper.getResource(particle, PackType.CLIENT_RESOURCES, ".json", "particles").openAsReader()) { + try (var resource = this.resourceManager.openAsReader(particle.withPath(path -> "particles/" + path + ".json"))) { var existingTextures = GSON.fromJson(resource, JsonObject.class).get("textures").getAsJsonArray(); var generatedTextures = this.descriptions.get(particle); diff --git a/tests/src/main/java/net/neoforged/neoforge/oldtest/RemoveTagDatagenTest.java b/tests/src/main/java/net/neoforged/neoforge/oldtest/RemoveTagDatagenTest.java index 9ef0b8f795f..79a2cc2b5b7 100644 --- a/tests/src/main/java/net/neoforged/neoforge/oldtest/RemoveTagDatagenTest.java +++ b/tests/src/main/java/net/neoforged/neoforge/oldtest/RemoveTagDatagenTest.java @@ -20,7 +20,6 @@ import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.common.data.BlockTagsProvider; -import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.neoforged.neoforge.data.event.GatherDataEvent; @Mod(RemoveTagDatagenTest.MODID) @@ -34,9 +33,8 @@ public RemoveTagDatagenTest(IEventBus modBus) { private void onGatherData(GatherDataEvent.Client event) { DataGenerator generator = event.getGenerator(); - ExistingFileHelper helper = event.getExistingFileHelper(); - var blocks = new BlockTagsProvider(generator.getPackOutput(), event.getLookupProvider(), MODID, helper) { + var blocks = new BlockTagsProvider(generator.getPackOutput(), event.getLookupProvider(), MODID) { @SuppressWarnings("unchecked") @Override protected void addTags(HolderLookup.Provider provider) { @@ -52,7 +50,7 @@ protected void addTags(HolderLookup.Provider provider) { generator.addProvider(true, blocks); - generator.addProvider(true, new ItemTagsProvider(generator.getPackOutput(), event.getLookupProvider(), blocks.contentsGetter(), MODID, helper) { + generator.addProvider(true, new ItemTagsProvider(generator.getPackOutput(), event.getLookupProvider(), blocks.contentsGetter(), MODID) { @Override protected void addTags(HolderLookup.Provider provider) { // This is for testing if it is functional, remove spruce_planks from planks, which makes us unable to craft beds with them.