Skip to content

Commit

Permalink
Remove unnecessary mixin overwrite and turn it into an injection with…
Browse files Browse the repository at this point in the history
… the same result for more compatibility.
  • Loading branch information
karelmikie3 authored and Talia-12 committed Mar 11, 2024
1 parent da751d7 commit a2c1a4d
Showing 1 changed file with 12 additions and 39 deletions.
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();
}
}

0 comments on commit a2c1a4d

Please sign in to comment.