mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Add support for referencing forge's resources and specifying existing mods to data generators (#7456)
This commit is contained in:
1 parent
47e076071b
commit
fd045d4628
7 files changed
+43
-10
No files matched your search
@@ -47,7 +47,7 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements IDataP
|
||||
private final ExistingFileHelper delegate;
|
||||
|
||||
public ExistingFileHelperIncludingGenerated(ExistingFileHelper delegate) {
|
||||
super(Collections.emptyList(), true);
|
||||
super(Collections.emptyList(), Collections.emptySet(), true);
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.util.Collection;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import net.minecraft.resources.FilePack;
|
||||
import net.minecraft.resources.FolderPack;
|
||||
import net.minecraft.resources.IResource;
|
||||
@@ -35,20 +37,29 @@ import net.minecraft.resources.ResourcePackType;
|
||||
import net.minecraft.resources.SimpleReloadableResourceManager;
|
||||
import net.minecraft.resources.VanillaPack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
|
||||
import net.minecraftforge.fml.packs.ModFileResourcePack;
|
||||
|
||||
/**
|
||||
* Enables data providers to check if other data files currently exist. The
|
||||
* instance provided in the {@link GatherDataEvent} utilizes the standard
|
||||
* resources (via {@link VanillaPack}), as well as any extra resource packs
|
||||
* passed in via the {@code --existing} argument.
|
||||
* resources (via {@link VanillaPack}), forge's resources, as well as any
|
||||
* extra resource packs passed in via the {@code --existing} argument,
|
||||
* or mod resources via the {@code --existing-mod} argument.
|
||||
*/
|
||||
public class ExistingFileHelper {
|
||||
|
||||
private final SimpleReloadableResourceManager clientResources, serverData;
|
||||
private final boolean enable;
|
||||
|
||||
@Deprecated//TODO: Remove in 1.17
|
||||
public ExistingFileHelper(Collection<Path> existingPacks, boolean enable) {
|
||||
this(existingPacks, Collections.emptySet(), enable);
|
||||
}
|
||||
|
||||
public ExistingFileHelper(Collection<Path> existingPacks, Set<String> existingMods, boolean enable) {
|
||||
this.clientResources = new SimpleReloadableResourceManager(ResourcePackType.CLIENT_RESOURCES);
|
||||
this.serverData = new SimpleReloadableResourceManager(ResourcePackType.SERVER_DATA);
|
||||
this.clientResources.addResourcePack(new VanillaPack("minecraft", "realms"));
|
||||
@@ -58,7 +69,15 @@ public class ExistingFileHelper {
|
||||
IResourcePack pack = file.isDirectory() ? new FolderPack(file) : new FilePack(file);
|
||||
this.clientResources.addResourcePack(pack);
|
||||
this.serverData.addResourcePack(pack);
|
||||
};
|
||||
}
|
||||
for (String existingMod : existingMods) {
|
||||
ModFileInfo modFileInfo = ModList.get().getModFileById(existingMod);
|
||||
if (modFileInfo != null) {
|
||||
IResourcePack pack = new ModFileResourcePack(modFileInfo.getFile());
|
||||
this.clientResources.addResourcePack(pack);
|
||||
this.serverData.addResourcePack(pack);
|
||||
}
|
||||
}
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package net.minecraftforge.fml;
|
||||
|
||||
import java.util.Collections;
|
||||
import net.minecraft.util.registry.Bootstrap;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
|
||||
@@ -39,14 +40,23 @@ public class DatagenModLoader {
|
||||
return runningDataGen;
|
||||
}
|
||||
|
||||
public static void begin(final Set<String> mods, final Path path, final java.util.Collection<Path> inputs, Collection<Path> existingPacks, final boolean serverGenerators, final boolean clientGenerators, final boolean devToolGenerators, final boolean reportsGenerator, final boolean structureValidator, final boolean flat) {
|
||||
@Deprecated //TODO: Remove in 1.17
|
||||
public static void begin(final Set<String> mods, final Path path, final Collection<Path> inputs, Collection<Path> existingPacks, final boolean serverGenerators, final boolean clientGenerators, final boolean devToolGenerators, final boolean reportsGenerator, final boolean structureValidator, final boolean flat) {
|
||||
begin(mods, path, inputs, existingPacks, Collections.emptySet(), serverGenerators, clientGenerators, devToolGenerators, reportsGenerator, structureValidator, flat);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (mods.contains("minecraft") && mods.size() == 1) return;
|
||||
LOGGER.info("Initializing Data Gatherer for mods {}", mods);
|
||||
runningDataGen = true;
|
||||
Bootstrap.register();
|
||||
dataGeneratorConfig = new GatherDataEvent.DataGeneratorConfig(mods, path, inputs, serverGenerators, clientGenerators, devToolGenerators, reportsGenerator, structureValidator, flat);
|
||||
existingFileHelper = new ExistingFileHelper(existingPacks, structureValidator);
|
||||
ModLoader.get().gatherAndInitializeMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), ()->{});
|
||||
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");
|
||||
}
|
||||
existingFileHelper = new ExistingFileHelper(existingPacks, existingMods, structureValidator);
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user