From 0dc2d7a9862e8e616d8b060b3481487f2c44775e Mon Sep 17 00:00:00 2001 From: karelmikie3 Date: Sat, 17 Feb 2024 03:20:19 +0100 Subject: [PATCH] Remove unnecessary mixin overwrite and turn it into an injection with the same result for more compatibility. --- .../mixin/ForgeMixinDatagenModLoader.java | 51 +++++-------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/mixin/ForgeMixinDatagenModLoader.java b/Forge/src/main/java/at/petrak/hexcasting/forge/mixin/ForgeMixinDatagenModLoader.java index b3cfea1a0..ca8554ef0 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/mixin/ForgeMixinDatagenModLoader.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/mixin/ForgeMixinDatagenModLoader.java @@ -1,61 +1,34 @@ package at.petrak.hexcasting.forge.mixin; -import net.minecraft.Util; -import net.minecraft.core.HolderLookup; -import net.minecraft.data.registries.VanillaRegistries; -import net.minecraft.server.Bootstrap; -import net.minecraftforge.common.data.ExistingFileHelper; -import net.minecraftforge.data.event.GatherDataEvent; import net.minecraftforge.data.loading.DatagenModLoader; -import net.minecraftforge.fml.ModLoader; -import net.minecraftforge.fml.ModWorkManager; -import org.apache.logging.log4j.Logger; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.io.File; import java.nio.file.Path; import java.util.Collection; import java.util.Set; -import java.util.concurrent.CompletableFuture; @Mixin(DatagenModLoader.class) public abstract class ForgeMixinDatagenModLoader { - @Shadow(remap = false) @Final - private static Logger LOGGER; - - @Shadow(remap = false) - private static GatherDataEvent.DataGeneratorConfig dataGeneratorConfig; - @Shadow(remap = false) - private static ExistingFileHelper existingFileHelper; - @Shadow(remap = false) - private static boolean runningDataGen; /** * Make it so non-vanilla registries can actually be tagged. */ - @Overwrite(remap = false) - public static void begin(final Set mods, final Path path, final Collection inputs, Collection existingPacks, - Set existingMods, final boolean serverGenerators, final boolean clientGenerators, final boolean devToolGenerators, final boolean reportsGenerator, - final boolean structureValidator, final boolean flat, final String assetIndex, final File assetsDir) { - if (mods.contains("minecraft") && mods.size() == 1) - return; - LOGGER.info("Initializing Data Gatherer for mods {}", mods); - runningDataGen = true; - Bootstrap.bootStrap(); - ModLoader.get().gatherAndInitializeMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), ()->{}); + @Inject(method = "begin", remap = false, at = @At( + value = "INVOKE", + target = "Lnet/minecraftforge/fml/ModLoader;gatherAndInitializeMods(Lnet/minecraftforge/fml/ModWorkManager$DrivenExecutor;Ljava/util/concurrent/Executor;Ljava/lang/Runnable;)V", + shift = At.Shift.AFTER + )) + private static void begin(final Set mods, final Path path, final Collection inputs, Collection existingPacks, + Set existingMods, final boolean serverGenerators, final boolean clientGenerators, final boolean devToolGenerators, final boolean reportsGenerator, + final boolean structureValidator, final boolean flat, final String assetIndex, final File assetsDir, CallbackInfo ci) { + if (!mods.contains("forge")) { // If we aren't generating data for forge, automatically add forge as an existing so mods can access forge's data existingMods.add("forge"); } - CompletableFuture lookupProvider = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor()); - dataGeneratorConfig = new GatherDataEvent.DataGeneratorConfig(mods, path, inputs, lookupProvider, serverGenerators, - clientGenerators, devToolGenerators, reportsGenerator, structureValidator, flat); - existingFileHelper = new ExistingFileHelper(existingPacks, existingMods, structureValidator, assetIndex, assetsDir); - ModLoader.get().runEventGenerator(mc -> new GatherDataEvent(mc, dataGeneratorConfig.makeGenerator(p -> dataGeneratorConfig.isFlat() ? p : p.resolve(mc.getModId()), - dataGeneratorConfig.getMods().contains(mc.getModId())), dataGeneratorConfig, existingFileHelper)); - dataGeneratorConfig.runAll(); } }