-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unnecessary mixin overwrite and turn it into an injection with…
… the same result for more compatibility.
- Loading branch information
1 parent
da751d7
commit a2c1a4d
Showing
1 changed file
with
12 additions
and
39 deletions.
There are no files selected for viewing
51 changes: 12 additions & 39 deletions
51
Forge/src/main/java/at/petrak/hexcasting/forge/mixin/ForgeMixinDatagenModLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> mods, final Path path, final Collection<Path> inputs, Collection<Path> existingPacks, | ||
Set<String> 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<String> mods, final Path path, final Collection<Path> inputs, Collection<Path> existingPacks, | ||
Set<String> 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<HolderLookup.Provider> 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(); | ||
} | ||
} |