Skip to content

Commit

Permalink
More mdg-related stuff (broken ATM)
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Nov 25, 2024
1 parent 4320b7b commit e21e15e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 67 deletions.
135 changes: 75 additions & 60 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.165'
id 'net.neoforged.moddev' version '2.0.47-beta'
id "me.modmuss50.mod-publish-plugin" version "0.5.1"
}

Expand All @@ -14,15 +14,10 @@ ext.isAlpha = ext.releaseTag.contains("alpha")
ext.isBeta = ext.releaseTag.contains("beta")
def relType = ext.isAlpha ? "alpha" : (ext.isBeta ? "beta" : "release")

// All jar files from this folder will be added automatically as runtime-only mod dependencies
def extraModsDir = "extra-mods-${minecraft_version}"
version = mod_version

repositories {
mavenLocal()
flatDir {
name "extra-mods"
dir file(extraModsDir)
}
maven {
name "K-4u Mod maven"
url "https://modmaven.dev/"
Expand Down Expand Up @@ -54,11 +49,7 @@ repositories {
}

sourceSets {
test {
runs {
modIdentifier 'modularrouterstest'
}
}
test
}

group = project.mod_group_id
Expand All @@ -77,62 +68,86 @@ java {
}
}

minecraft {
accessTransformers.file(project.file('src/main/resources/META-INF/accesstransformer.cfg'))
}
neoForge {
version = "${neo_version}"

runs {
// applies to all the run configs below
configureEach {
// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
systemProperty 'forge.logging.markers', 'REGISTRIES'

// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
systemProperty 'forge.logging.console.level', 'debug'

jvmArguments.addAll '-Xmx4G'

modSource project.sourceSets.test
modSource project.sourceSets.main
parchment {
mappingsVersion = project.parchment_mappings_version
minecraftVersion = project.parchment_minecraft_version
}

client {
systemProperty 'neoforge.enableGameTest', 'true'
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}
addModdingDependenciesTo(sourceSets.test)

server {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
argument '--nogui'
}
validateAccessTransformers = true

runs {
// applies to all the run configs below
configureEach {
// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
systemProperty 'forge.logging.markers', 'REGISTRIES'

// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
systemProperty 'forge.logging.console.level', 'debug'

jvmArguments.addAll '-Xmx4G'
}

client {
client()
systemProperty 'neoforge.enableGameTest', 'true'
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
loadedMods = [mods.modularrouters, mods.modularrouterstest]
}

server {
server()
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
programArgument '--nogui'
}

// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
type = "gameTestServer"
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}

data {
data()
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}
}

data {
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
arguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
mods {
"${mod_id}" {
sourceSet sourceSets.main
sourceSet sourceSets.test
}
}
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

configurations {
runtimeClasspath.extendsFrom localRuntime
}

dependencies {
implementation "net.neoforged:neoforge:${neo_version}"
// implementation "net.neoforged:neoforge:${neo_version}"
localRuntime(testImplementation("net.neoforged:testframework:${neo_version}"))

// implementation sourceSets.test.output

compileOnly("mcjty.theoneprobe:theoneprobe:${top_version}") {
transitive = false
}
Expand All @@ -150,14 +165,14 @@ dependencies {
// runtimeOnly "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}"

// Locally sourced extra mods for runtime (i.e. testing) - thanks AE2 for this idea
for (extraModJar in fileTree(dir: extraModsDir, include: '*.jar')) {
def basename = extraModJar.name.substring(0, extraModJar.name.length() - ".jar".length())
def versionSep = basename.lastIndexOf('-')
assert versionSep != -1
def artifactId = basename.substring(0, versionSep)
def version = basename.substring(versionSep + 1)
runtimeOnly "extra-mods:$artifactId:$version"
}
// for (extraModJar in fileTree(dir: extraModsDir, include: '*.jar')) {
// def basename = extraModJar.name.substring(0, extraModJar.name.length() - ".jar".length())
// def versionSep = basename.lastIndexOf('-')
// assert versionSep != -1
// def artifactId = basename.substring(0, versionSep)
// def version = basename.substring(versionSep + 1)
// runtimeOnly "extra-mods:$artifactId:$version"
// }
}

tasks.withType(ProcessResources).configureEach {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ curse_project_id=250294
# Minecraft/Forge
minecraft_version=1.21.3
minecraft_version_range=[1.21.3,)
neo_version=21.3.34-beta
neo_version=21.3.40-beta
neo_version_range=[21.3.0,)
loader_version_range=[4,)
pack_format_number=18
neogradle.subsystems.parchment.minecraftVersion=1.21
neogradle.subsystems.parchment.mappingsVersion=2024.07.28
parchment_minecraft_version=1.21.1
parchment_mappings_version=2024.11.17

# Dependencies
top_version=1.21_neo-12.0.3-5
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pluginManagement {
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}

rootProject.name = 'modular-routers'
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.neoforged.testframework.conf.ClientConfiguration;
import net.neoforged.testframework.conf.Feature;
import net.neoforged.testframework.conf.FrameworkConfiguration;
import net.neoforged.testframework.conf.MissingDescriptionAction;
import net.neoforged.testframework.impl.MutableTestFramework;
import net.neoforged.testframework.summary.GitHubActionsStepSummaryDumper;
import org.lwjgl.glfw.GLFW;
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/me/desht/modularrouters/test/RouterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import me.desht.modularrouters.core.ModItems;
import me.desht.modularrouters.item.module.ModuleItem;
import me.desht.modularrouters.logic.compiled.CompiledModule;
import net.minecraft.core.registries.Registries;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.attachment.AttachmentType;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
Expand All @@ -17,6 +21,10 @@
import org.jetbrains.annotations.NotNull;

public class RouterTest {
private static final ResourceKey<Item> TEST_ID = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modularrouterstest:testmodule"));

private static final Item.Properties TEST_PROPS = new Item.Properties().setId(TEST_ID);

@GameTest
@TestHolder
@EmptyTemplate
Expand All @@ -25,7 +33,7 @@ static void testRouterSpeed(DynamicTest test, RegistrationHelper reg) {
.register("counter", () -> AttachmentType.builder(() -> 0)
.serialize(Codec.INT).build());

var module = reg.items().register("test_module", () -> new ModuleItem(ModItems.moduleProps(), (r, s) -> new CompiledModule(r, s) {
var module = reg.items().register("test_module", () -> new ModuleItem(TEST_PROPS, (r, s) -> new CompiledModule(r, s) {
@Override
public boolean execute(@NotNull ModularRouterBlockEntity router) {
router.setData(counter, router.getData(counter.get()) + 1);
Expand Down

0 comments on commit e21e15e

Please sign in to comment.