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

Open
wants to merge 1 commit into
base: 1.21.x
Choose a base branch
from
Open
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 @@ -29,6 +29,7 @@
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.event.IModBusEvent;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import org.jetbrains.annotations.ApiStatus;

public abstract class GatherDataEvent extends Event implements IModBusEvent {
private final DataGenerator dataGenerator;
Expand Down Expand Up @@ -87,6 +88,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 @@ -125,10 +127,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.common.data.ExistingFileHelper;
import net.neoforged.neoforge.data.event.GatherDataEvent;
import net.neoforged.neoforge.internal.CommonModLoader;
Expand Down Expand Up @@ -55,8 +56,16 @@ public static void begin(final Set<String> mods, final Path path, final Collecti
}
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));

// 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, existingFileHelper);
mod.acceptEvent(event);
}
}

dataGeneratorConfig.runAll();
}
}
Loading