Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only fire gather data events for the mods enabled #1806

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import net.neoforged.fml.event.IModBusEvent;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.resource.ResourcePackLoader;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

public abstract class GatherDataEvent extends Event implements IModBusEvent {
Expand Down Expand Up @@ -107,6 +108,7 @@ public Client(ModContainer mc, DataGenerator dataGenerator, DataGeneratorConfig
}
}

@ApiStatus.Internal
public static class DataGeneratorConfig {
private final Set<String> mods;
private final Path path;
Expand Down Expand Up @@ -155,10 +157,9 @@ public boolean isFlat() {
return flat || getMods().size() == 1;
}

public DataGenerator makeGenerator(final Function<Path, Path> pathEnhancer, final boolean shouldExecute) {
final DataGenerator generator = new DataGenerator(pathEnhancer.apply(path), DetectedVersion.tryDetectVersion(), shouldExecute);
if (shouldExecute)
generators.add(generator);
public DataGenerator makeGenerator(final Function<Path, Path> pathEnhancer) {
final DataGenerator generator = new DataGenerator(pathEnhancer.apply(path), DetectedVersion.tryDetectVersion(), true);
generators.add(generator);
return generator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import net.minecraft.data.DataGenerator;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.server.Bootstrap;
import net.neoforged.fml.ModLoader;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;
import net.neoforged.neoforge.data.event.GatherDataEvent;
import net.neoforged.neoforge.internal.CommonModLoader;
import net.neoforged.neoforge.internal.RegistrationEvents;
Expand Down Expand Up @@ -49,8 +50,16 @@ public static void begin(final Set<String> mods, final Path path, final Collecti
CompletableFuture<HolderLookup.Provider> lookupProvider = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor());
dataGeneratorConfig = new GatherDataEvent.DataGeneratorConfig(mods, path, inputs, lookupProvider, devToolGenerators, reportsGenerator, structureValidator, flat, vanillaGenerator, assetIndex, assetsDir, existingPacks);
setup.run();
ModLoader.runEventGenerator(mc -> eventGenerator.create(mc, dataGeneratorConfig.makeGenerator(p -> dataGeneratorConfig.isFlat() ? p : p.resolve(mc.getModId()),
dataGeneratorConfig.getMods().contains(mc.getModId())), dataGeneratorConfig));

// Only fire the event for mods that have their generators enabled
for (ModContainer mod : ModList.get().getSortedMods()) {
ApexModder marked this conversation as resolved.
Show resolved Hide resolved
if (dataGeneratorConfig.getMods().contains(mod.getModId())) {
var generator = dataGeneratorConfig.makeGenerator(p -> dataGeneratorConfig.isFlat() ? p : p.resolve(mod.getModId()));
var event = eventGenerator.create(mod, generator, dataGeneratorConfig);
mod.acceptEvent(event);
}
}

dataGeneratorConfig.runAll();
}
}
Loading