diff --git a/REUSE.toml b/REUSE.toml index 401bf6c60e..0c43beba15 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -40,8 +40,8 @@ path = [ "projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/.ignoreme", "projects/core/src/main/resources/data/computercraft/lua/rom/modules/turtle/.ignoreme", "projects/core/src/main/resources/data/computercraft/lua/rom/motd.txt", - "projects/fabric-api/src/main/modJson/fabric.mod.json", "projects/fabric/src/client/resources/computercraft-client.fabric.mixins.json", + "projects/fabric/src/datagen/resources/fabric.mod.json", "projects/fabric/src/main/resources/computercraft.fabric.mixins.json", "projects/fabric/src/main/resources/fabric.mod.json", "projects/fabric/src/testMod/resources/computercraft-gametest.fabric.mixins.json", diff --git a/buildSrc/src/main/kotlin/cc-tweaked.gametest.gradle.kts b/buildSrc/src/main/kotlin/cc-tweaked.mod.gradle.kts similarity index 67% rename from buildSrc/src/main/kotlin/cc-tweaked.gametest.gradle.kts rename to buildSrc/src/main/kotlin/cc-tweaked.mod.gradle.kts index 712b5e857b..fb12f8120f 100644 --- a/buildSrc/src/main/kotlin/cc-tweaked.gametest.gradle.kts +++ b/buildSrc/src/main/kotlin/cc-tweaked.mod.gradle.kts @@ -19,26 +19,32 @@ plugins { val main = sourceSets["main"] val client = sourceSets["client"] -// Both testMod and testFixtures inherit from the main and client classpath, just so we have access to Minecraft classes. +// datagen and testMod inherit from the main and client classpath, just so we have access to Minecraft classes. +val datagen by sourceSets.creating { + compileClasspath += main.compileClasspath + client.compileClasspath + runtimeClasspath += main.runtimeClasspath + client.runtimeClasspath +} + val testMod by sourceSets.creating { compileClasspath += main.compileClasspath + client.compileClasspath runtimeClasspath += main.runtimeClasspath + client.runtimeClasspath } -configurations { - named(testMod.compileClasspathConfigurationName) { - shouldResolveConsistentlyWith(compileClasspath.get()) - } +val extraConfigurations = listOf(datagen, testMod) - named(testMod.runtimeClasspathConfigurationName) { - shouldResolveConsistentlyWith(runtimeClasspath.get()) +configurations { + for (config in extraConfigurations) { + named(config.compileClasspathConfigurationName) { shouldResolveConsistentlyWith(compileClasspath.get()) } + named(config.runtimeClasspathConfigurationName) { shouldResolveConsistentlyWith(runtimeClasspath.get()) } } } // Like the main test configurations, we're safe to depend on source set outputs. dependencies { - add(testMod.implementationConfigurationName, main.output) - add(testMod.implementationConfigurationName, client.output) + for (config in extraConfigurations) { + add(config.implementationConfigurationName, main.output) + add(config.implementationConfigurationName, client.output) + } } // Similar to java-test-fixtures, but tries to avoid putting the obfuscated jar on the classpath. diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedExtension.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedExtension.kt index 70b3d1f3e9..0124fee5ce 100644 --- a/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedExtension.kt +++ b/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedExtension.kt @@ -109,14 +109,13 @@ abstract class CCTweakedExtension( val otherJava = otherProject.extensions.getByType(JavaPluginExtension::class.java) val main = otherJava.sourceSets.getByName("main") val client = otherJava.sourceSets.getByName("client") - val testMod = otherJava.sourceSets.findByName("testMod") - val testFixtures = otherJava.sourceSets.findByName("testFixtures") // Pull in sources from the other project. extendSourceSet(otherProject, main) extendSourceSet(otherProject, client) - if (testMod != null) extendSourceSet(otherProject, testMod) - if (testFixtures != null) extendSourceSet(otherProject, testFixtures) + for (sourceSet in listOf("datagen", "testMod", "testFixtures")) { + otherJava.sourceSets.findByName(sourceSet)?.let { extendSourceSet(otherProject, it) } + } // The extra source-processing tasks should include these files too. project.tasks.named(main.javadocTaskName, Javadoc::class.java) { source(main.allJava, client.allJava) } diff --git a/projects/common/build.gradle.kts b/projects/common/build.gradle.kts index 6599ee140a..7826e59daf 100644 --- a/projects/common/build.gradle.kts +++ b/projects/common/build.gradle.kts @@ -6,8 +6,8 @@ import cc.tweaked.gradle.* plugins { id("cc-tweaked.vanilla") - id("cc-tweaked.gametest") id("cc-tweaked.illuaminate") + id("cc-tweaked.mod") id("cc-tweaked.publishing") } diff --git a/projects/common/src/client/java/dan200/computercraft/client/gui/GuiSprites.java b/projects/common/src/client/java/dan200/computercraft/client/gui/GuiSprites.java index 63b152dfef..ffed5a1af4 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/gui/GuiSprites.java +++ b/projects/common/src/client/java/dan200/computercraft/client/gui/GuiSprites.java @@ -6,7 +6,6 @@ import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.client.render.ComputerBorderRenderer; -import dan200.computercraft.data.client.ClientDataProviders; import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureManager; @@ -113,7 +112,6 @@ public Stream textures() { * @param pocketBottom The texture for the bottom of a pocket computer. * @param sidebar The texture for the computer sidebar. * @see ComputerBorderRenderer - * @see ClientDataProviders */ public record ComputerTextures( ResourceLocation border, diff --git a/projects/common/src/client/java/dan200/computercraft/data/client/ClientDataProviders.java b/projects/common/src/client/java/dan200/computercraft/data/client/ClientDataProviders.java deleted file mode 100644 index b318826d0e..0000000000 --- a/projects/common/src/client/java/dan200/computercraft/data/client/ClientDataProviders.java +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.data.client; - -import dan200.computercraft.client.gui.GuiSprites; -import dan200.computercraft.client.model.LecternPrintoutModel; -import dan200.computercraft.data.DataProviders; -import dan200.computercraft.shared.turtle.inventory.UpgradeSlot; -import net.minecraft.client.renderer.texture.atlas.SpriteSource; -import net.minecraft.client.renderer.texture.atlas.SpriteSources; -import net.minecraft.client.renderer.texture.atlas.sources.SingleFile; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.PackType; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -/** - * A version of {@link DataProviders} which relies on client-side classes. - *

- * This is called from {@link DataProviders#add(DataProviders.GeneratorSink)}. - */ -public final class ClientDataProviders { - private ClientDataProviders() { - } - - public static void add(DataProviders.GeneratorSink generator) { - generator.addFromCodec("Block atlases", PackType.CLIENT_RESOURCES, "atlases", SpriteSources.FILE_CODEC, out -> { - out.accept(new ResourceLocation("blocks"), List.of( - new SingleFile(UpgradeSlot.LEFT_UPGRADE, Optional.empty()), - new SingleFile(UpgradeSlot.RIGHT_UPGRADE, Optional.empty()), - new SingleFile(LecternPrintoutModel.TEXTURE, Optional.empty()) - )); - out.accept(GuiSprites.SPRITE_SHEET, Stream.of( - // Buttons - GuiSprites.TURNED_OFF.textures(), - GuiSprites.TURNED_ON.textures(), - GuiSprites.TERMINATE.textures(), - // Computers - GuiSprites.COMPUTER_NORMAL.textures(), - GuiSprites.COMPUTER_ADVANCED.textures(), - GuiSprites.COMPUTER_COMMAND.textures(), - GuiSprites.COMPUTER_COLOUR.textures() - ).flatMap(x -> x).map(x -> new SingleFile(x, Optional.empty())).toList()); - }); - } -} diff --git a/projects/common/src/main/java/dan200/computercraft/data/BlockModelProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/BlockModelProvider.java similarity index 100% rename from projects/common/src/main/java/dan200/computercraft/data/BlockModelProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/BlockModelProvider.java diff --git a/projects/common/src/main/java/dan200/computercraft/data/DataProviders.java b/projects/common/src/datagen/java/dan200/computercraft/data/DataProviders.java similarity index 55% rename from projects/common/src/main/java/dan200/computercraft/data/DataProviders.java rename to projects/common/src/datagen/java/dan200/computercraft/data/DataProviders.java index a68f15e61d..d58aeaf9b4 100644 --- a/projects/common/src/main/java/dan200/computercraft/data/DataProviders.java +++ b/projects/common/src/datagen/java/dan200/computercraft/data/DataProviders.java @@ -5,6 +5,12 @@ package dan200.computercraft.data; import com.mojang.serialization.Codec; +import dan200.computercraft.client.gui.GuiSprites; +import dan200.computercraft.client.model.LecternPrintoutModel; +import dan200.computercraft.shared.turtle.inventory.UpgradeSlot; +import net.minecraft.client.renderer.texture.atlas.SpriteSource; +import net.minecraft.client.renderer.texture.atlas.SpriteSources; +import net.minecraft.client.renderer.texture.atlas.sources.SingleFile; import net.minecraft.data.DataProvider; import net.minecraft.data.PackOutput; import net.minecraft.data.tags.TagsProvider; @@ -13,9 +19,14 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Stream; /** * All data providers for ComputerCraft. We require a mod-loader abstraction {@link GeneratorSink} (instead of @@ -39,14 +50,30 @@ public static void add(GeneratorSink generator) { generator.add(out -> new LanguageProvider(out, turtleUpgrades, pocketUpgrades)); - // Unfortunately we rely on some client-side classes in this code. We just load in the client side data provider - // and invoke that. - try { - Class.forName("dan200.computercraft.data.client.ClientDataProviders") - .getMethod("add", GeneratorSink.class).invoke(null, generator); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + generator.addFromCodec("Block atlases", PackType.CLIENT_RESOURCES, "atlases", SpriteSources.FILE_CODEC, out -> { + out.accept(new ResourceLocation("blocks"), makeSprites(Stream.of( + UpgradeSlot.LEFT_UPGRADE, + UpgradeSlot.RIGHT_UPGRADE, + LecternPrintoutModel.TEXTURE + ))); + out.accept(GuiSprites.SPRITE_SHEET, makeSprites( + // Buttons + GuiSprites.TURNED_OFF.textures(), + GuiSprites.TURNED_ON.textures(), + GuiSprites.TERMINATE.textures(), + // Computers + GuiSprites.COMPUTER_NORMAL.textures(), + GuiSprites.COMPUTER_ADVANCED.textures(), + GuiSprites.COMPUTER_COMMAND.textures(), + GuiSprites.COMPUTER_COLOUR.textures() + )); + }); + } + + @SafeVarargs + @SuppressWarnings("varargs") + private static List makeSprites(final Stream... files) { + return Arrays.stream(files).flatMap(Function.identity()).map(x -> new SingleFile(x, Optional.empty())).toList(); } public interface GeneratorSink { diff --git a/projects/common/src/main/java/dan200/computercraft/data/ItemModelProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/ItemModelProvider.java similarity index 100% rename from projects/common/src/main/java/dan200/computercraft/data/ItemModelProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/ItemModelProvider.java diff --git a/projects/common/src/main/java/dan200/computercraft/data/LanguageProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/LanguageProvider.java similarity index 100% rename from projects/common/src/main/java/dan200/computercraft/data/LanguageProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/LanguageProvider.java diff --git a/projects/common/src/main/java/dan200/computercraft/data/LootTableProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/LootTableProvider.java similarity index 100% rename from projects/common/src/main/java/dan200/computercraft/data/LootTableProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/LootTableProvider.java diff --git a/projects/common/src/main/java/dan200/computercraft/data/ModelProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/ModelProvider.java similarity index 100% rename from projects/common/src/main/java/dan200/computercraft/data/ModelProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/ModelProvider.java diff --git a/projects/common/src/main/java/dan200/computercraft/data/PocketUpgradeProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/PocketUpgradeProvider.java similarity index 100% rename from projects/common/src/main/java/dan200/computercraft/data/PocketUpgradeProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/PocketUpgradeProvider.java diff --git a/projects/common/src/main/java/dan200/computercraft/data/PrettyDataProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/PrettyDataProvider.java similarity index 96% rename from projects/common/src/main/java/dan200/computercraft/data/PrettyDataProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/PrettyDataProvider.java index 9c78e245ca..fc2ef47e3a 100644 --- a/projects/common/src/main/java/dan200/computercraft/data/PrettyDataProvider.java +++ b/projects/common/src/datagen/java/dan200/computercraft/data/PrettyDataProvider.java @@ -7,6 +7,7 @@ import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; +import dan200.computercraft.shared.util.PrettyJsonWriter; import net.minecraft.data.CachedOutput; import net.minecraft.data.DataProvider; diff --git a/projects/common/src/main/java/dan200/computercraft/data/RecipeProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/RecipeProvider.java similarity index 100% rename from projects/common/src/main/java/dan200/computercraft/data/RecipeProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/RecipeProvider.java diff --git a/projects/common/src/main/java/dan200/computercraft/data/RecipeWrapper.java b/projects/common/src/datagen/java/dan200/computercraft/data/RecipeWrapper.java similarity index 100% rename from projects/common/src/main/java/dan200/computercraft/data/RecipeWrapper.java rename to projects/common/src/datagen/java/dan200/computercraft/data/RecipeWrapper.java diff --git a/projects/common/src/main/java/dan200/computercraft/data/TagProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/TagProvider.java similarity index 98% rename from projects/common/src/main/java/dan200/computercraft/data/TagProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/TagProvider.java index 04cf493da4..4250f6a644 100644 --- a/projects/common/src/main/java/dan200/computercraft/data/TagProvider.java +++ b/projects/common/src/datagen/java/dan200/computercraft/data/TagProvider.java @@ -148,7 +148,7 @@ public TagAppender addTag(TagKey tag) { /** * A wrapper over {@link ItemTagsProvider}. */ - interface ItemTagConsumer extends TagConsumer { + public interface ItemTagConsumer extends TagConsumer { void copy(TagKey block, TagKey item); } } diff --git a/projects/common/src/main/java/dan200/computercraft/data/TurtleUpgradeProvider.java b/projects/common/src/datagen/java/dan200/computercraft/data/TurtleUpgradeProvider.java similarity index 100% rename from projects/common/src/main/java/dan200/computercraft/data/TurtleUpgradeProvider.java rename to projects/common/src/datagen/java/dan200/computercraft/data/TurtleUpgradeProvider.java diff --git a/projects/common/src/main/java/dan200/computercraft/data/PrettyJsonWriter.java b/projects/common/src/main/java/dan200/computercraft/shared/util/PrettyJsonWriter.java similarity index 99% rename from projects/common/src/main/java/dan200/computercraft/data/PrettyJsonWriter.java rename to projects/common/src/main/java/dan200/computercraft/shared/util/PrettyJsonWriter.java index 38ee71e852..d52459accc 100644 --- a/projects/common/src/main/java/dan200/computercraft/data/PrettyJsonWriter.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/util/PrettyJsonWriter.java @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MPL-2.0 -package dan200.computercraft.data; +package dan200.computercraft.shared.util; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -23,7 +23,7 @@ /** * Alternative version of {@link JsonWriter} which attempts to lay out the JSON in a more compact format. * - * @see PrettyDataProvider + * @see dan200.computercraft.data.PrettyDataProvider */ public class PrettyJsonWriter extends JsonWriter { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); diff --git a/projects/common/src/testMod/java/dan200/computercraft/export/Exporter.java b/projects/common/src/testMod/java/dan200/computercraft/export/Exporter.java index d852c8774d..56d7e32e4d 100644 --- a/projects/common/src/testMod/java/dan200/computercraft/export/Exporter.java +++ b/projects/common/src/testMod/java/dan200/computercraft/export/Exporter.java @@ -14,9 +14,9 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import dan200.computercraft.api.ComputerCraftAPI; -import dan200.computercraft.data.PrettyJsonWriter; import dan200.computercraft.gametest.core.TestHooks; import dan200.computercraft.shared.platform.RegistryWrappers; +import dan200.computercraft.shared.util.PrettyJsonWriter; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; diff --git a/projects/fabric/build.gradle.kts b/projects/fabric/build.gradle.kts index 69bc0d041a..4896ef955b 100644 --- a/projects/fabric/build.gradle.kts +++ b/projects/fabric/build.gradle.kts @@ -8,7 +8,7 @@ import java.util.* plugins { id("cc-tweaked.fabric") - id("cc-tweaked.gametest") + id("cc-tweaked.mod") id("cc-tweaked.mod-publishing") } @@ -146,6 +146,8 @@ loom { configName = "Datagen" client() + source(sourceSets.datagen.get()) + runDir("run/dataGen") property("fabric-api.datagen") property("fabric-api.datagen.output-dir", layout.buildDirectory.dir("generatedResources").getAbsolutePath()) diff --git a/projects/fabric/src/main/java/dan200/computercraft/data/FabricDataGenerators.java b/projects/fabric/src/datagen/java/dan200/computercraft/data/FabricDataProviders.java similarity index 98% rename from projects/fabric/src/main/java/dan200/computercraft/data/FabricDataGenerators.java rename to projects/fabric/src/datagen/java/dan200/computercraft/data/FabricDataProviders.java index 48983dbda3..881b9eda3b 100644 --- a/projects/fabric/src/main/java/dan200/computercraft/data/FabricDataGenerators.java +++ b/projects/fabric/src/datagen/java/dan200/computercraft/data/FabricDataProviders.java @@ -26,7 +26,7 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; -public class FabricDataGenerators implements DataGeneratorEntrypoint { +public class FabricDataProviders implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator generator) { var pack = new PlatformGeneratorsImpl(generator.createPack()); diff --git a/projects/fabric/src/main/java/dan200/computercraft/data/MoreConventionalTagsProvider.java b/projects/fabric/src/datagen/java/dan200/computercraft/data/MoreConventionalTagsProvider.java similarity index 100% rename from projects/fabric/src/main/java/dan200/computercraft/data/MoreConventionalTagsProvider.java rename to projects/fabric/src/datagen/java/dan200/computercraft/data/MoreConventionalTagsProvider.java diff --git a/projects/fabric/src/datagen/resources/fabric.mod.json b/projects/fabric/src/datagen/resources/fabric.mod.json new file mode 100644 index 0000000000..1daa9ec5f5 --- /dev/null +++ b/projects/fabric/src/datagen/resources/fabric.mod.json @@ -0,0 +1,13 @@ +{ + "schemaVersion": 1, + "id": "cc-datagen", + "version": "1.0.0", + "entrypoints": { + "fabric-datagen": [ + "dan200.computercraft.data.FabricDataProviders" + ] + }, + "depends": { + "computercraft": "*" + } +} diff --git a/projects/fabric/src/main/resources/fabric.mod.json b/projects/fabric/src/main/resources/fabric.mod.json index 89ab2882d0..7a48156a17 100644 --- a/projects/fabric/src/main/resources/fabric.mod.json +++ b/projects/fabric/src/main/resources/fabric.mod.json @@ -23,9 +23,6 @@ "client": [ "dan200.computercraft.client.ComputerCraftClient::init" ], - "fabric-datagen": [ - "dan200.computercraft.data.FabricDataGenerators" - ], "jei_mod_plugin": [ "dan200.computercraft.client.integration.jei.JEIComputerCraft" ], diff --git a/projects/fabric/src/testMod/resources/fabric.mod.json b/projects/fabric/src/testMod/resources/fabric.mod.json index 9b8648888e..ffc442bec6 100644 --- a/projects/fabric/src/testMod/resources/fabric.mod.json +++ b/projects/fabric/src/testMod/resources/fabric.mod.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "id": "cctest", + "id": "cc-datagen", "version": "1.0.0", "entrypoints": { "main": [ diff --git a/projects/forge/build.gradle.kts b/projects/forge/build.gradle.kts index 1457aae787..7caf8de4a3 100644 --- a/projects/forge/build.gradle.kts +++ b/projects/forge/build.gradle.kts @@ -7,7 +7,7 @@ import net.minecraftforge.gradle.common.util.RunConfig plugins { id("cc-tweaked.forge") - id("cc-tweaked.gametest") + id("cc-tweaked.mod") id("cc-tweaked.mod-publishing") } @@ -57,6 +57,10 @@ minecraft { "--existing", project(":common").file("src/main/resources/"), "--existing", file("src/main/resources/"), ) + + mods.named("computercraft") { + source(sourceSets["datagen"]) + } } fun RunConfig.configureForGameTest() { diff --git a/projects/forge/src/main/java/dan200/computercraft/data/Generators.java b/projects/forge/src/datagen/java/dan200/computercraft/data/ForgeDataProviders.java similarity index 99% rename from projects/forge/src/main/java/dan200/computercraft/data/Generators.java rename to projects/forge/src/datagen/java/dan200/computercraft/data/ForgeDataProviders.java index 3a003ca093..6ea8480f58 100644 --- a/projects/forge/src/main/java/dan200/computercraft/data/Generators.java +++ b/projects/forge/src/datagen/java/dan200/computercraft/data/ForgeDataProviders.java @@ -32,7 +32,7 @@ import java.util.function.Consumer; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) -public class Generators { +public class ForgeDataProviders { @SubscribeEvent public static void gather(GatherDataEvent event) { var generator = event.getGenerator();