Skip to content

Commit be83bb1

Browse files
committed
refactor: split version-specific code into multi-version source directories
- Move StackableToolsUtils.kt and ItemStackMixin.kt to src/mc-{1.20.4,1.20.5}/ - Add -PmcVersion build parameter for version selection - Update build.gradle.kts with version-specific sourceSets - Add gradle-mc-versions.properties as build reference - Update game tests with templateName and improved error handling - Expand fabric.mod.json version range to >=1.20.0
1 parent 316c6d8 commit be83bb1

11 files changed

Lines changed: 296 additions & 63 deletions

File tree

build.gradle.kts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ plugins {
66
id("org.jetbrains.kotlin.jvm") version "2.3.20"
77
}
88

9+
// Multi-version: use -PmcVersion=<version> (default: 1.20.6)
10+
// to select version-specific source dirs (src/mc-<version>/{kotlin,gametest}).
11+
val mcVersion: String = providers.gradleProperty("mcVersion").orElse("1.20.5").get()
12+
913
version = providers.gradleProperty("mod_version").get()
1014
group = providers.gradleProperty("maven_group").get()
1115

@@ -46,10 +50,20 @@ fabricApi {
4650
}
4751
}
4852

53+
// Add version-specific source directories
54+
sourceSets {
55+
named("main") {
56+
java.srcDir("src/mc-$mcVersion/kotlin")
57+
}
58+
named("gametest") {
59+
java.srcDir("src/mc-$mcVersion/gametest/kotlin")
60+
}
61+
}
62+
4963
dependencies {
5064
// To change the versions see the gradle.properties file
5165
minecraft("com.mojang:minecraft:${providers.gradleProperty("minecraft_version").get()}")
52-
mappings("net.fabricmc:yarn:1.20.5+build.1:v2")
66+
mappings("net.fabricmc:yarn:${providers.gradleProperty("yarn_mappings").get()}:v2")
5367
modImplementation("net.fabricmc:fabric-loader:${providers.gradleProperty("loader_version").get()}")
5468

5569
// Fabric API. This is technically optional, but you probably want it anyway.
@@ -61,8 +75,6 @@ dependencies {
6175
implementation("org.json:json:20240303")
6276
}
6377

64-
// Afin d'empaqueter toml4j dans le JAR, on inclut le runtime dans la tâche jar.
65-
6678
tasks.processResources {
6779
inputs.property("version", version)
6880

@@ -82,9 +94,6 @@ kotlin {
8294
}
8395

8496
java {
85-
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
86-
// if it is present.
87-
// If you remove this line, sources will not be generated.
8897
withSourcesJar()
8998

9099
sourceCompatibility = JavaVersion.VERSION_17
@@ -118,7 +127,6 @@ publishing {
118127
}
119128
}
120129

121-
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
122130
repositories {
123131
// Add repositories to publish to here.
124132
// Notice: This block does NOT have the same function as the block in the top level.

gradle-mc-versions.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Multi-version dependency reference
2+
# Usage: ./gradlew build -PmcVersion=<version> -Pminecraft_version=<mc_ver> ...
3+
#
4+
# 1.20.x defaults (from gradle.properties):
5+
# minecraft_version=1.20.6, yarn_mappings=1.20.5+build.1, fabric_api_version=0.97.3+1.20.5
6+
7+
# To build for 1.20.4:
8+
# ./gradlew build -PmcVersion=1.20.4 -Pminecraft_version=1.20.4 -Pyarn_mappings=1.20.4+build.3 -Pfabric_api_version=0.97.3+1.20.4

gradle.properties

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
# Done to increase the memory available to gradle.
21
org.gradle.jvmargs=-Xms1g -Xmx4g -XX:MaxMetaspaceSize=2g -Dfile.encoding=UTF-8
32
org.gradle.parallel=true
4-
5-
# IntelliJ IDEA is not yet fully compatible with configuration cache, see: https://github.com/FabricMC/fabric-loom/issues/1349
63
org.gradle.configuration-cache=false
74

85
# Fabric Properties
9-
# check these on https://fabricmc.net/develop
106
minecraft_version=1.20.5
117
loader_version=0.18.5
128
loom_version=1.15-SNAPSHOT
9+
yarn_mappings=1.20.5+build.1
1310
fabric_kotlin_version=1.13.10+kotlin.2.3.20
1411

1512
# Mod Properties
@@ -18,4 +15,4 @@ maven_group=stackabletools
1815
archives_base_name=stackabletools
1916

2017
# Dependencies
21-
fabric_api_version=0.97.3+1.20.5
18+
fabric_api_version=0.97.3+1.20.5

src/gametest/kotlin/stackabletools/StackableToolsGameTest.kt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class StackableToolsGameTest : FabricGameTest {
2323
/**
2424
* Test that two identical diamond pickaxes can be stacked.
2525
*/
26-
@GameTest
26+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
2727
public fun testIdenticalToolsCanStack(context: TestContext) {
2828
val pickaxe1 = ItemStack(Items.DIAMOND_PICKAXE, 1)
2929
val pickaxe2 = ItemStack(Items.DIAMOND_PICKAXE, 1)
@@ -38,7 +38,7 @@ public class StackableToolsGameTest : FabricGameTest {
3838
/**
3939
* Test that damaged tools cannot be stacked.
4040
*/
41-
@GameTest
41+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
4242
public fun testDamagedToolsCannotStack(context: TestContext) {
4343
val pickaxe1 = ItemStack(Items.DIAMOND_PICKAXE, 1)
4444
val pickaxe2 = ItemStack(Items.DIAMOND_PICKAXE, 1)
@@ -56,7 +56,7 @@ public class StackableToolsGameTest : FabricGameTest {
5656
/**
5757
* Test that different item types cannot be stacked.
5858
*/
59-
@GameTest
59+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
6060
public fun testDifferentItemsCannotStack(context: TestContext) {
6161
val pickaxe = ItemStack(Items.DIAMOND_PICKAXE, 1)
6262
val axe = ItemStack(Items.DIAMOND_AXE, 1)
@@ -71,7 +71,7 @@ public class StackableToolsGameTest : FabricGameTest {
7171
/**
7272
* Test that empty stacks cannot be stacked.
7373
*/
74-
@GameTest
74+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
7575
public fun testEmptyStacksCannotStack(context: TestContext) {
7676
val pickaxe = ItemStack(Items.DIAMOND_PICKAXE, 1)
7777
val empty = ItemStack.EMPTY
@@ -86,7 +86,7 @@ public class StackableToolsGameTest : FabricGameTest {
8686
/**
8787
* Test that diamond pickaxes are identified as stackable when tools category is active.
8888
*/
89-
@GameTest
89+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
9090
public fun testToolsAreStackableWhenCategoryActive(context: TestContext) {
9191
val pickaxe = ItemStack(Items.DIAMOND_PICKAXE, 1)
9292

@@ -100,7 +100,7 @@ public class StackableToolsGameTest : FabricGameTest {
100100
/**
101101
* Test that potions are identified as stackable when potions category is active.
102102
*/
103-
@GameTest
103+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
104104
public fun testPotionsAreStackableWhenCategoryActive(context: TestContext) {
105105
val potion = ItemStack(Items.POTION, 1)
106106

@@ -114,7 +114,7 @@ public class StackableToolsGameTest : FabricGameTest {
114114
/**
115115
* Test that enchanted books are identified as stackable when enchanted books category is active.
116116
*/
117-
@GameTest
117+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
118118
public fun testEnchantedBooksAreStackable(context: TestContext) {
119119
val enchantedBook = ItemStack(Items.ENCHANTED_BOOK, 1)
120120

@@ -128,7 +128,7 @@ public class StackableToolsGameTest : FabricGameTest {
128128
/**
129129
* Test that weapons (swords) are identified as stackable when weapons category is active.
130130
*/
131-
@GameTest
131+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
132132
public fun testWeaponsAreStackableWhenCategoryActive(context: TestContext) {
133133
val sword = ItemStack(Items.DIAMOND_SWORD, 1)
134134

@@ -142,7 +142,7 @@ public class StackableToolsGameTest : FabricGameTest {
142142
/**
143143
* Test that armor pieces are identified as stackable when armors category is active.
144144
*/
145-
@GameTest
145+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
146146
public fun testArmorIsStackableWhenCategoryActive(context: TestContext) {
147147
val helmet = ItemStack(Items.DIAMOND_HELMET, 1)
148148

@@ -156,7 +156,7 @@ public class StackableToolsGameTest : FabricGameTest {
156156
/**
157157
* Test that elytra is identified as stackable when elytra category is active.
158158
*/
159-
@GameTest
159+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
160160
public fun testElytraIsStackableWhenCategoryActive(context: TestContext) {
161161
val elytra = ItemStack(Items.ELYTRA, 1)
162162

@@ -170,7 +170,7 @@ public class StackableToolsGameTest : FabricGameTest {
170170
/**
171171
* Test that regular items (like dirt) are not stackable.
172172
*/
173-
@GameTest
173+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
174174
public fun testRegularItemsNotStackable(context: TestContext) {
175175
val dirt = ItemStack(Items.DIRT, 1)
176176

@@ -184,7 +184,7 @@ public class StackableToolsGameTest : FabricGameTest {
184184
/**
185185
* Test that empty stacks are not stackable.
186186
*/
187-
@GameTest
187+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
188188
public fun testEmptyStackNotStackable(context: TestContext) {
189189
val empty = ItemStack.EMPTY
190190

@@ -198,7 +198,7 @@ public class StackableToolsGameTest : FabricGameTest {
198198
/**
199199
* Test that two identical swords without damage can be stacked.
200200
*/
201-
@GameTest
201+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
202202
public fun testIdenticalSwordsCanStack(context: TestContext) {
203203
val sword1 = ItemStack(Items.DIAMOND_SWORD, 1)
204204
val sword2 = ItemStack(Items.DIAMOND_SWORD, 1)
@@ -213,7 +213,7 @@ public class StackableToolsGameTest : FabricGameTest {
213213
/**
214214
* Test that armor pieces with different damage levels cannot be stacked.
215215
*/
216-
@GameTest
216+
@GameTest(templateName = "fabric-gametest-api-v1:empty")
217217
public fun testDifferentlyDamagedArmorCannotStack(context: TestContext) {
218218
val helmet1 = ItemStack(Items.DIAMOND_HELMET, 1)
219219
val helmet2 = ItemStack(Items.DIAMOND_HELMET, 1)
@@ -232,13 +232,12 @@ public class StackableToolsGameTest : FabricGameTest {
232232
*/
233233
override fun invokeTestMethod(context: TestContext, method: Method) {
234234
try {
235-
// Ensure configuration is loaded before test
236235
ConfigManager.loadConfig()
237-
238-
// Run the test method
239236
method.invoke(this, context)
237+
} catch (e: java.lang.reflect.InvocationTargetException) {
238+
context.throwGameTestException("Test failed: ${e.cause?.message ?: e.cause?.javaClass?.simpleName ?: "Unknown error"}")
240239
} catch (e: Exception) {
241-
context.throwGameTestException("Test failed with exception: ${e.message}")
240+
context.throwGameTestException("Test failed: ${e.message ?: e.javaClass.simpleName}")
242241
}
243242
}
244243
}

0 commit comments

Comments
 (0)