Skip to content

Commit

Permalink
Add extra_datagen_resources folder for runtime datagen (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored May 7, 2023
1 parent d48e120 commit 7f9c717
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
21 changes: 21 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ MI can generate most of these resources for you if you ask it to.
- This will make sure that MI will automatically load the resources generated in the previous step.
- Profit!

#### More info regarding runtime datagen
Runtime datagen works by running the data generators during the end of MI startup.
- It uses `modern_industrialization/runtime_datagen` to produce all the files that are automatically generated.
- These files include loot tables, most recipes, or material textures, for example.
- The files that are **different** from those in the jar then get copied to `modern_industrialization/generated_resources`.
- Finally, MI injects a hidden data and resource pack with maximum priority to load these resources into the game.

Runtime datagen will only use the resources from the MI jar and the base vanilla assets.
**It will not use any resource pack, as it runs too early.**

However, files can be placed in the `modern_industrialization/extra_datagen_resources` folder if they are needed during datagen,
and they take precedence over the files in the MI jar.
At the moment, this only works for textures.
Here are some examples to get you started:
- Placing a texture in `modern_industrialization/extra_datagen_resources/assets/modern_industrialization/textures/materialsets/common/plate.png`
will change the texture of most plates.
- The `datagen_texture_overrides` exists to manually override textures produced by datagen, for example specific material textures.
Placing a texture in `modern_industrialization/extra_datagen_resources/assets/modern_industrialization/datagen_texture_overrides/item/aluminum_plate.png`
will change the texture of the aluminum plate only.
- Refer to the contents of the MI .jar for more details on the file structure.

### Adding new machines
Refer to [ADDING_MACHINES.md](ADDING_MACHINES.md) for more information on how to add machines via KubeJS.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
Expand All @@ -63,19 +64,24 @@ public record TexturesProvider(FabricDataGenerator dataGenerator, boolean runtim

@Override
public void run(CachedOutput cache) {
PackResources miResources;
var packs = new ArrayList<PackResources>();

packs.add(new DefaultClientPackResources(ClientPackSource.BUILT_IN, new AssetIndex(new File(""), "")));

if (runtimeDatagen) {
// MI jar
ModContainer container = FabricLoader.getInstance().getModContainer(ModernIndustrialization.MOD_ID).get();
miResources = ModNioResourcePack.create(new ResourceLocation("fabric", container.getMetadata().getId()),
container.getMetadata().getName(), container, null, PackType.CLIENT_RESOURCES, ResourcePackActivationType.ALWAYS_ENABLED);
packs.add(ModNioResourcePack.create(new ResourceLocation("fabric", container.getMetadata().getId()),
container.getMetadata().getName(), container, null, PackType.CLIENT_RESOURCES, ResourcePackActivationType.ALWAYS_ENABLED));

// extra_datagen_resources folder
var extra = FabricLoader.getInstance().getGameDir().resolve("modern_industrialization").resolve("extra_datagen_resources");
packs.add(new FolderPackResources(extra.toFile()));
} else {
var nonGeneratedResources = dataGenerator.getOutputFolder().resolve("../../main/resources").toFile();
miResources = new FolderPackResources(nonGeneratedResources);
packs.add(new FolderPackResources(nonGeneratedResources));
}

var packs = List.of(
new DefaultClientPackResources(ClientPackSource.BUILT_IN, new AssetIndex(new File(""), "")),
miResources);
try (var fallbackProvider = new MultiPackResourceManager(PackType.CLIENT_RESOURCES, packs)) {
generateTextures(cache, fallbackProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ public static void run(Consumer<FabricDataGenerator> config) {

private static void runInner(Consumer<FabricDataGenerator> config) throws Exception {
var miFolder = FabricLoader.getInstance().getGameDir().resolve("modern_industrialization");

// Create some relevant texture folders because I'm sure some people will forget it
var datagenOverridesFolder = miFolder.resolve("extra_datagen_resources");
Files.createDirectories(datagenOverridesFolder
.resolve("assets")
.resolve("modern_industrialization")
.resolve("textures"));
Files.createDirectories(datagenOverridesFolder
.resolve("assets")
.resolve("modern_industrialization")
.resolve("datagen_texture_overrides"));

var dataOutput = miFolder.resolve("runtime_datagen");

ModernIndustrialization.LOGGER.info("Starting MI runtime data generation");
Expand Down

0 comments on commit 7f9c717

Please sign in to comment.