diff --git a/.github/workflows/modrinth.yml b/.github/workflows/modrinth.yml index b51029d..12e12cf 100644 --- a/.github/workflows/modrinth.yml +++ b/.github/workflows/modrinth.yml @@ -181,3 +181,19 @@ jobs: fabric-api modmenu yacl + + - name: Publish 26.3 + uses: BreadMoirai/mc-publish@master + with: + modrinth-token: ${{ secrets.M_TOKEN }} + files: build/libs/${{ env.MOD_VERSION }}/one-click-anvil-${{ env.MOD_VERSION }}+26.3*.jar + name: "${{ env.MOD_VERSION }}+26.3" + version: "${{ env.MOD_VERSION }}+26.3" + version-type: release + loaders: fabric + game-versions: "26.3" + java: 25 + dependencies: | + fabric-api + modmenu + yacl diff --git a/.gitignore b/.gitignore index eced6c8..f65fcaf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,120 +1,120 @@ -# User-specific stuff -.idea/ - -*.iml -*.ipr -*.iws - -# IntelliJ -out/ -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -.gradle -build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Cache of project -.gradletasknamecache - -**/build/ - -# Common working directory -run/ - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar -/remappedSrc/ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Cache of project +.gradletasknamecache + +**/build/ + +# Common working directory +run/ + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar +/remappedSrc/ /net/ \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md index f7ae31e..418300e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -23,10 +23,23 @@ Fabric mod that auto-applies the anvil rename (one-click anvil). Multi-version v ## Versions - **1.21.x line** (1.21.7, 1.21.8, 1.21.9, 1.21.10, 1.21.11): normal `fabric-loom-remap` + Mojang-mappings path, Java 21, `build.gradle.kts`, `transformUnnamedVars` on switch. -- **26.x line** (26.1, 26.1.1, 26.1.2, 26.2 — `26.2` is the `vcsVersion`; shared `src/` holds its code): un-obfuscated / JDK-25 toolchain. Registered in `settings.gradle.kts` via `versions("26.2", "26.1.2", "26.1.1", "26.1").buildscript("build.unobf.gradle.kts")` (plain `fabric-loom`, no Mojang mappings, `restoreUnnamedVars` on switch, `jar` not `remapJar`). The 26.1.x patches are API-identical to 26.1, so there is no source divergence between them — the `26.1` swap entry covers them all since `sc.current.parsed >= "26.1"`. +- **26.x line** (26.1, 26.1.1, 26.1.2, 26.2, 26.3 — `26.3` is the `vcsVersion`; shared `src/` holds its code): un-obfuscated / JDK-25 toolchain. Registered in `settings.gradle.kts` via `versions("26.3", "26.2", "26.1.2", "26.1.1", "26.1").buildscript("build.unobf.gradle.kts")` (plain `fabric-loom`, no Mojang mappings, `restoreUnnamedVars` on switch, `jar` not `remapJar`). The 26.1.x patches are API-identical to 26.1, so there is no source divergence between them — the `26.1` swap entry covers them all since `sc.current.parsed >= "26.1"`. - **26.2 API divergences** (handled inline because they are not single-token renames, so they can't be swaps): - `Minecraft.setScreen(Screen)` → `Minecraft.setScreenAndShow(Screen)` — inline `//? if >=26.2` block in `config/OneClickAnvilConfigScreen.java`. - The public `Minecraft.screen` field was removed; the current screen is now read via `Minecraft.gui.screen()` (`net.minecraft.client.gui.Gui`, with the public `Minecraft.gui` field). Routed through the version-conditional `ConfigHelper.currentScreen(Minecraft)` test helper (a bare `setScreen`/`screen` swap would collide with `ClientGameTestContext.setScreen` and local `screen` vars). +- **26.3 API divergences:** + - **GLFW is gone — MC 26.3 windows through SDL** (`org.lwjgl:lwjgl-sdl` replaces `lwjgl-glfw` in the + version manifest), so `org.lwjgl.glfw.GLFW` no longer resolves. The test code's key/mouse + constants now come from `com.mojang.blaze3d.platform.InputConstants` + (`KEY_ESCAPE`, `MOUSE_BUTTON_LEFT`), which exists unchanged on every supported version — plain + shared code, no condition or swap. + - **Fabric client-gametest API 6.x** (26.3's fabric-api pulls `fabric-client-gametest-api-v1 6.0.7`) + dropped `TestClientLevelContext`: `TestSingleplayerContext.getClientLevel()` became + `getConnection()` (`TestServerConnection`, which is what now carries `waitForChunksDownload()`, + `getClientLevel()`, `getServerLevel()`, ...). Handled by a `"26.3"` swap entry. + - The swap map is ordered **newest first** so the reverse chain unwinds correctly: `getClientWorld` + -> `getClientLevel` (26.1) -> `getConnection` (26.3) has to be undone newest-rename-first when + switching down to 1.21.x. - **Flat, non-versioned layout still holds:** no `vXX_Y` packages. The 26.1 API divergence is handled entirely by **simple identifier swaps** in `stonecutter-swaps.gradle.kts` (shared `src/` keeps the 1.21.x name; the swap promotes it when `current >= 26.1`): - `ClickType` → `ContainerInput` (`net.minecraft.world.inventory`) - `handleInventoryMouseClick` → `handleContainerInput` (`MultiPlayerGameMode`) @@ -46,6 +59,15 @@ cmd.exe /c gradlew.bat "Set active project to 26.1" - `:build` always FAILS (game tests use `runTestClient`, not JUnit) — expected. - Tests run via `::runTestClient` (client gametest API, MC >= 1.21.4). 26.1 runs on JDK 25, 1.21.x on JDK 21. +- Running **all** versions: `cmd.exe /c gradlew.bat runTestClient --max-workers=4`. **Cap at 4** — + each task launches a real Minecraft client, and beyond about four in parallel they contend for + GPU/window resources and some clients hang permanently (the build never finishes; the stuck JVMs + have to be killed with `taskkill /F /IM java.exe /T`, which also takes out the Gradle daemons). +- **26.x Windows JVM stack crash (fixed):** `build.unobf.gradle.kts` passes + `-XX:+UnlockDiagnosticVMOptions -XX:+AlwaysPreTouchStacks` to every loom run. Without it, 10–50% of + 26.x client launches die in the first resource reload (`NTSTATUS 0xC0000005`, no `hs_err`) from a + HotSpot-on-Windows stack-growth bug — not mod code. Do not remove the flag. Full write-up: `update` + skill → `references/api-divergences.md` → "26.x client startup crash on Windows". - A "Set active project" or compile occasionally dies with a transient WSL2 I/O error / quick `BUILD FAILED` — just retry (run `./gradlew --stop` first if it persists). ## Adding versions diff --git a/build.gradle.kts b/build.gradle.kts index 24727dc..6ff13c1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,145 +1,145 @@ -plugins { - id("net.fabricmc.fabric-loom-remap") - id("maven-publish") -} - -version = "${property("mod.version")}+${sc.current.version}" -group = property("mod.group") as String - -base.archivesName = property("mod.id") as String - -val requiredJava = when { - sc.current.parsed >= "26" -> 25 - sc.current.parsed >= "1.20.5" -> 21 - sc.current.parsed >= "1.18" -> 21 - sc.current.parsed >= "1.17" -> 21 - else -> 8 -} -java.toolchain.languageVersion.set(JavaLanguageVersion.of(requiredJava)) - -repositories { - maven("https://maven.gegy.dev") { - name = "Gegy" - } - maven("https://maven.terraformersmc.com/releases/") { - name = "TerraformersMC" - } - maven("https://maven.isxander.dev/releases") { - name = "Xander Maven" - } -} - -dependencies { - minecraft("com.mojang:minecraft:${property("minecraft_version")}") - mappings(loom.officialMojangMappings()) - - modImplementation("net.fabricmc:fabric-loader:${property("loader_version")}") - modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_version")}") - - modImplementation("com.terraformersmc:modmenu:${property("modmenu_version")}") - modImplementation("dev.isxander:yet-another-config-lib:${property("yacl_version")}") - - testImplementation(sourceSets.main.get().output) -} - -tasks { - processResources { - notCompatibleWithConfigurationCache("I don't know why...") - inputs.property("version", project.property("mod.version")) - inputs.property("minecraft", project.property("minecraft_version_range")) - inputs.property("yacl", project.property("yacl_version")) - inputs.property("modmenu", project.property("modmenu_version")) - - filesMatching("fabric.mod.json") { - expand( - mapOf( - "version" to project.property("mod.version"), - "minecraft" to project.property("minecraft_version_range"), - "yacl" to project.property("yacl_version").apply { this.toString().substringBefore('-') }, - "modmenu" to project.property("modmenu_version").apply { this.toString().substringBefore('-') })) - } - } - - withType { - options.encoding = "UTF-8" - } - - // Builds the version into a shared folder in `build/libs/${mod version}/` - register("buildAndCollect") { - group = "build" - from(remapJar.map { it.archiveFile }, remapSourcesJar.map { it.archiveFile }) - into(rootProject.layout.buildDirectory.file("libs/${project.property("mod.version")}")) - dependsOn("remapJar") - dependsOn("remapSourcesJar") - } -} - - -// When building old versions without switching first, transform _ in generated sources. -// Stonecutter generates sources from shared src/ (which may contain JDK 22+ unnamed _). -if (sc.current.parsed < "26") { - val transformForBuild = tasks.register("transformUnnamedVarsForBuild") { - group = "stonecutter" - description = "Replaces standalone _ with unused1, unused2, ... in Stonecutter generated sources" - notCompatibleWithConfigurationCache("transforms generated source files in place") - @Suppress("OPT_IN_USAGE") - dependsOn(sc.tasks.generate.values) - doLast { - val unnamedPattern = Regex("""\b_\b""") - val genDir = sc.tasks.generatedSourcesDir.get().asFile - genDir.walkTopDown().filter { it.isFile && it.extension == "java" }.forEach { file -> - val original = file.readText() - var counter = 0 - val transformed = unnamedPattern.replace(original) { "unused${++counter}" } - if (transformed != original) file.writeText(transformed) - } - } - } - tasks.withType().configureEach { dependsOn(transformForBuild) } -} - -// Use Stonecutter's semantic version parsing — a lexical String compare breaks on -// multi-digit patches (e.g. "1.21.10" < "1.21.4" as plain strings). -val hasClientGameTestApi = sc.current.parsed >= "1.21.4" - -sourceSets { - named("test") { - if (!hasClientGameTestApi) { - java.setSrcDirs(emptyList()) - resources.setSrcDirs(emptyList()) - } else { - compileClasspath += sourceSets.main.get().compileClasspath + sourceSets.test.get().compileClasspath - runtimeClasspath += sourceSets.main.get().runtimeClasspath + sourceSets.test.get().runtimeClasspath - } - } -} - -loom { - runs { - if (hasClientGameTestApi) { - register("TestClient") { - client() - name("Test Client") - source(sourceSets.test.get()) - vmArgs("-Dfabric.client.gametest", "-Dfabric.client.gametest.disableNetworkSynchronizer") - } - } - } - - createRemapConfigurations(sourceSets.test.get()) -} - -apply(from = "../../stonecutter-swaps.gradle.kts") -@Suppress("UNCHECKED_CAST") -val swapMap = extra["swaps"] as Map> -stonecutter { - replacements { - for ((version, swaps) in swapMap) { - string(sc.current.parsed >= version) { - for ((from, to) in swaps) { - replace(from, to) - } - } - } - } -} +plugins { + id("net.fabricmc.fabric-loom-remap") + id("maven-publish") +} + +version = "${property("mod.version")}+${sc.current.version}" +group = property("mod.group") as String + +base.archivesName = property("mod.id") as String + +val requiredJava = when { + sc.current.parsed >= "26" -> 25 + sc.current.parsed >= "1.20.5" -> 21 + sc.current.parsed >= "1.18" -> 21 + sc.current.parsed >= "1.17" -> 21 + else -> 8 +} +java.toolchain.languageVersion.set(JavaLanguageVersion.of(requiredJava)) + +repositories { + maven("https://maven.gegy.dev") { + name = "Gegy" + } + maven("https://maven.terraformersmc.com/releases/") { + name = "TerraformersMC" + } + maven("https://maven.isxander.dev/releases") { + name = "Xander Maven" + } +} + +dependencies { + minecraft("com.mojang:minecraft:${property("minecraft_version")}") + mappings(loom.officialMojangMappings()) + + modImplementation("net.fabricmc:fabric-loader:${property("loader_version")}") + modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_version")}") + + modImplementation("com.terraformersmc:modmenu:${property("modmenu_version")}") + modImplementation("dev.isxander:yet-another-config-lib:${property("yacl_version")}") + + testImplementation(sourceSets.main.get().output) +} + +tasks { + processResources { + notCompatibleWithConfigurationCache("I don't know why...") + inputs.property("version", project.property("mod.version")) + inputs.property("minecraft", project.property("minecraft_version_range")) + inputs.property("yacl", project.property("yacl_version")) + inputs.property("modmenu", project.property("modmenu_version")) + + filesMatching("fabric.mod.json") { + expand( + mapOf( + "version" to project.property("mod.version"), + "minecraft" to project.property("minecraft_version_range"), + "yacl" to project.property("yacl_version").apply { this.toString().substringBefore('-') }, + "modmenu" to project.property("modmenu_version").apply { this.toString().substringBefore('-') })) + } + } + + withType { + options.encoding = "UTF-8" + } + + // Builds the version into a shared folder in `build/libs/${mod version}/` + register("buildAndCollect") { + group = "build" + from(remapJar.map { it.archiveFile }, remapSourcesJar.map { it.archiveFile }) + into(rootProject.layout.buildDirectory.file("libs/${project.property("mod.version")}")) + dependsOn("remapJar") + dependsOn("remapSourcesJar") + } +} + + +// When building old versions without switching first, transform _ in generated sources. +// Stonecutter generates sources from shared src/ (which may contain JDK 22+ unnamed _). +if (sc.current.parsed < "26") { + val transformForBuild = tasks.register("transformUnnamedVarsForBuild") { + group = "stonecutter" + description = "Replaces standalone _ with unused1, unused2, ... in Stonecutter generated sources" + notCompatibleWithConfigurationCache("transforms generated source files in place") + @Suppress("OPT_IN_USAGE") + dependsOn(sc.tasks.generate.values) + doLast { + val unnamedPattern = Regex("""\b_\b""") + val genDir = sc.tasks.generatedSourcesDir.get().asFile + genDir.walkTopDown().filter { it.isFile && it.extension == "java" }.forEach { file -> + val original = file.readText() + var counter = 0 + val transformed = unnamedPattern.replace(original) { "unused${++counter}" } + if (transformed != original) file.writeText(transformed) + } + } + } + tasks.withType().configureEach { dependsOn(transformForBuild) } +} + +// Use Stonecutter's semantic version parsing — a lexical String compare breaks on +// multi-digit patches (e.g. "1.21.10" < "1.21.4" as plain strings). +val hasClientGameTestApi = sc.current.parsed >= "1.21.4" + +sourceSets { + named("test") { + if (!hasClientGameTestApi) { + java.setSrcDirs(emptyList()) + resources.setSrcDirs(emptyList()) + } else { + compileClasspath += sourceSets.main.get().compileClasspath + sourceSets.test.get().compileClasspath + runtimeClasspath += sourceSets.main.get().runtimeClasspath + sourceSets.test.get().runtimeClasspath + } + } +} + +loom { + runs { + if (hasClientGameTestApi) { + register("TestClient") { + client() + name("Test Client") + source(sourceSets.test.get()) + vmArgs("-Dfabric.client.gametest", "-Dfabric.client.gametest.disableNetworkSynchronizer") + } + } + } + + createRemapConfigurations(sourceSets.test.get()) +} + +apply(from = "../../stonecutter-swaps.gradle.kts") +@Suppress("UNCHECKED_CAST") +val swapMap = extra["swaps"] as Map> +stonecutter { + replacements { + for ((version, swaps) in swapMap) { + string(sc.current.parsed >= version) { + for ((from, to) in swaps) { + replace(from, to) + } + } + } + } +} diff --git a/build.unobf.gradle.kts b/build.unobf.gradle.kts index 04f9d24..f2556e1 100644 --- a/build.unobf.gradle.kts +++ b/build.unobf.gradle.kts @@ -103,6 +103,17 @@ sourceSets { loom { runs { + // MC 26.x on Windows (JDK 25+): pre-commit each thread's whole stack at thread start. + // Without this, ~10-50% of client launches die in the first resource reload with + // NTSTATUS 0xC0000005 / 0xC0000409 and no hs_err file: JIT-compiled code on a + // Worker-Main thread stack-bangs past the Windows guard page, HotSpot's Windows fault + // handler commits the stack range manually (leaving no guard page below it), and VM + // call-site resolution (SharedRuntime::find_callee_*) then runs off the committed + // region or corrupts its own frame. Pre-touching avoids that path entirely. + // Verified 0/40 crashes vs 5/40+ without; see the update skill api-divergences.md. + configureEach { + vmArgs("-XX:+UnlockDiagnosticVMOptions", "-XX:+AlwaysPreTouchStacks") + } register("TestClient") { client() name("Test Client") diff --git a/gradle.properties b/gradle.properties index 449fc27..0c65778 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,10 +1,10 @@ -# Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx4G -org.gradle.parallel=true -org.gradle.configuration-cache=false - -# Mod Properties -mod.name=One Click Anvil -mod.id=one-click-anvil -mod.group=com.github.breadmoirai -mod.version=1.1.1 +# Done to increase the memory available to gradle. +org.gradle.jvmargs=-Xmx4G +org.gradle.parallel=true +org.gradle.configuration-cache=false + +# Mod Properties +mod.name=One Click Anvil +mod.id=one-click-anvil +mod.group=com.github.breadmoirai +mod.version=1.1.1 diff --git a/settings.gradle.kts b/settings.gradle.kts index 8489632..9d3f716 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,8 +18,8 @@ stonecutter { versions("1.21.11", "1.21.10", "1.21.9", "1.21.8", "1.21.7") // MC 26.x is un-obfuscated and runs on the JDK-25 toolchain — it cannot use the // normal fabric-loom-remap + Mojang-mappings path, so it gets its own build script. - versions("26.2", "26.1.2", "26.1.1", "26.1").buildscript("build.unobf.gradle.kts") - vcsVersion = "26.2" + versions("26.3", "26.2", "26.1.2", "26.1.1", "26.1").buildscript("build.unobf.gradle.kts") + vcsVersion = "26.3" } } diff --git a/src/main/java/com/github/breadmoirai/oneclickanvil/client/OneClickAnvilClient.java b/src/main/java/com/github/breadmoirai/oneclickanvil/client/OneClickAnvilClient.java index 1b9a0af..eb25f0d 100644 --- a/src/main/java/com/github/breadmoirai/oneclickanvil/client/OneClickAnvilClient.java +++ b/src/main/java/com/github/breadmoirai/oneclickanvil/client/OneClickAnvilClient.java @@ -1,127 +1,127 @@ -package com.github.breadmoirai.oneclickanvil.client; - -import com.github.breadmoirai.oneclickanvil.config.OneClickAnvilConfig; -import com.github.breadmoirai.oneclickanvil.mixin.AnvilScreenAccessor; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.AnvilScreen; -import net.minecraft.client.multiplayer.MultiPlayerGameMode; -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.core.component.DataComponents; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.chat.Component; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.ContainerInput; -import net.minecraft.world.inventory.Slot; -import net.minecraft.world.item.ItemStack; - -import java.util.ArrayList; -import java.util.Optional; - -@Environment(EnvType.CLIENT) -public class OneClickAnvilClient implements ClientModInitializer, ClientTickEvents.StartTick, ScreenEvents.AfterInit, ScreenEvents.Remove { - - private static OneClickAnvilClient INSTANCE; - - public static OneClickAnvilClient getInstance() { - return INSTANCE; - } - - private OneClickAnvilConfig config; - private ArrayList ops; - - private String renaming; - - @Override - public void onInitializeClient() { - INSTANCE = this; - OneClickAnvilConfig.loadModConfig(); - config = OneClickAnvilConfig.getInstance(); - ops = new ArrayList<>(); - ScreenEvents.AFTER_INIT.register(this); - ClientTickEvents.START_CLIENT_TICK.register(this); - renaming = null; - } - - public void onAnvilScreenSlotUpdate(AnvilScreen anvil, AbstractContainerMenu handler, int slotId, ItemStack stack) { - LocalPlayer player = Minecraft.getInstance().player; - if (player == null) return; - MultiPlayerGameMode interactionManager = Minecraft.getInstance().gameMode; - if (interactionManager == null) return; - if (slotId == 0) { - if (stack.get(DataComponents.CUSTOM_NAME) != null) return; - if (stack.getCount() != stack.getMaxStackSize()) return; - getRename(stack).ifPresent(rename -> ops.add(() -> { - this.renaming = BuiltInRegistries.ITEM.getKey(stack.getItem()).toString(); - ((AnvilScreenAccessor) anvil).getName().setValue(rename); - })); - } - if (slotId == 2) { - if (this.renaming == null) { - return; - } - if (stack.isEmpty()) { - String to_rename = this.renaming; - ops.add(() -> { - // A slot-2-empty update can fire while the stack being renamed is still in input - // slot 0 (output not yet computed/pulled). Pulling the next stack now would shift- - // click it into input slot 1 — which this mod never processes — stranding it there. - // Only advance once slot 0 is clear; the in-progress rename re-triggers this later. - if (anvil.getMenu().getSlot(0).hasItem()) return; - for (Slot slot : anvil.getMenu().slots) { - if (slot.container != player.getInventory()) continue; - if (!slot.hasItem()) continue; - ItemStack nextStack = slot.getItem(); - if (!to_rename.equals(BuiltInRegistries.ITEM.getKey(nextStack.getItem()).toString())) continue; - if (nextStack.get(DataComponents.CUSTOM_NAME) != null) continue; - if (nextStack.getCount() != nextStack.getMaxStackSize()) continue; - interactionManager.handleContainerInput(anvil.getMenu().containerId, slot.index, 0, ContainerInput.QUICK_MOVE, - player); - return; - } - this.renaming = null; - }); - } else { - Component customName = stack.get(DataComponents.CUSTOM_NAME); - if (customName == null) return; - getRename(stack).ifPresent(rename -> { - if (rename.equals(customName.getString())) { - ops.add( - () -> interactionManager.handleContainerInput(handler.containerId, slotId, 0, ContainerInput.QUICK_MOVE, player)); - } - }); - } - } - } - - private Optional getRename(ItemStack stack) { - for (OneClickAnvilConfig.Entry entry : config.getEntries()) { - if (!entry.isEnabled()) continue; - if (BuiltInRegistries.ITEM.getKey(stack.getItem()).toString().equals(entry.getItem())) { - return Optional.of(entry.getRename()); - } - } - return Optional.empty(); - } - - @Override - public void onStartTick(Minecraft client) { - if (ops.isEmpty()) return; - ops.removeFirst().run(); - } - - @Override - public void afterInit(Minecraft client, Screen screen, int i, int i1) { - ScreenEvents.remove(screen).register(this); - } - - @Override - public void onRemove(Screen screen) { - ops.clear(); - } -} +package com.github.breadmoirai.oneclickanvil.client; + +import com.github.breadmoirai.oneclickanvil.config.OneClickAnvilConfig; +import com.github.breadmoirai.oneclickanvil.mixin.AnvilScreenAccessor; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AnvilScreen; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.component.DataComponents; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerInput; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; + +import java.util.ArrayList; +import java.util.Optional; + +@Environment(EnvType.CLIENT) +public class OneClickAnvilClient implements ClientModInitializer, ClientTickEvents.StartTick, ScreenEvents.AfterInit, ScreenEvents.Remove { + + private static OneClickAnvilClient INSTANCE; + + public static OneClickAnvilClient getInstance() { + return INSTANCE; + } + + private OneClickAnvilConfig config; + private ArrayList ops; + + private String renaming; + + @Override + public void onInitializeClient() { + INSTANCE = this; + OneClickAnvilConfig.loadModConfig(); + config = OneClickAnvilConfig.getInstance(); + ops = new ArrayList<>(); + ScreenEvents.AFTER_INIT.register(this); + ClientTickEvents.START_CLIENT_TICK.register(this); + renaming = null; + } + + public void onAnvilScreenSlotUpdate(AnvilScreen anvil, AbstractContainerMenu handler, int slotId, ItemStack stack) { + LocalPlayer player = Minecraft.getInstance().player; + if (player == null) return; + MultiPlayerGameMode interactionManager = Minecraft.getInstance().gameMode; + if (interactionManager == null) return; + if (slotId == 0) { + if (stack.get(DataComponents.CUSTOM_NAME) != null) return; + if (stack.getCount() != stack.getMaxStackSize()) return; + getRename(stack).ifPresent(rename -> ops.add(() -> { + this.renaming = BuiltInRegistries.ITEM.getKey(stack.getItem()).toString(); + ((AnvilScreenAccessor) anvil).getName().setValue(rename); + })); + } + if (slotId == 2) { + if (this.renaming == null) { + return; + } + if (stack.isEmpty()) { + String to_rename = this.renaming; + ops.add(() -> { + // A slot-2-empty update can fire while the stack being renamed is still in input + // slot 0 (output not yet computed/pulled). Pulling the next stack now would shift- + // click it into input slot 1 — which this mod never processes — stranding it there. + // Only advance once slot 0 is clear; the in-progress rename re-triggers this later. + if (anvil.getMenu().getSlot(0).hasItem()) return; + for (Slot slot : anvil.getMenu().slots) { + if (slot.container != player.getInventory()) continue; + if (!slot.hasItem()) continue; + ItemStack nextStack = slot.getItem(); + if (!to_rename.equals(BuiltInRegistries.ITEM.getKey(nextStack.getItem()).toString())) continue; + if (nextStack.get(DataComponents.CUSTOM_NAME) != null) continue; + if (nextStack.getCount() != nextStack.getMaxStackSize()) continue; + interactionManager.handleContainerInput(anvil.getMenu().containerId, slot.index, 0, ContainerInput.QUICK_MOVE, + player); + return; + } + this.renaming = null; + }); + } else { + Component customName = stack.get(DataComponents.CUSTOM_NAME); + if (customName == null) return; + getRename(stack).ifPresent(rename -> { + if (rename.equals(customName.getString())) { + ops.add( + () -> interactionManager.handleContainerInput(handler.containerId, slotId, 0, ContainerInput.QUICK_MOVE, player)); + } + }); + } + } + } + + private Optional getRename(ItemStack stack) { + for (OneClickAnvilConfig.Entry entry : config.getEntries()) { + if (!entry.isEnabled()) continue; + if (BuiltInRegistries.ITEM.getKey(stack.getItem()).toString().equals(entry.getItem())) { + return Optional.of(entry.getRename()); + } + } + return Optional.empty(); + } + + @Override + public void onStartTick(Minecraft client) { + if (ops.isEmpty()) return; + ops.removeFirst().run(); + } + + @Override + public void afterInit(Minecraft client, Screen screen, int i, int i1) { + ScreenEvents.remove(screen).register(this); + } + + @Override + public void onRemove(Screen screen) { + ops.clear(); + } +} diff --git a/src/main/java/com/github/breadmoirai/oneclickanvil/mixin/AnvilScreenMixin.java b/src/main/java/com/github/breadmoirai/oneclickanvil/mixin/AnvilScreenMixin.java index de404b8..805e786 100644 --- a/src/main/java/com/github/breadmoirai/oneclickanvil/mixin/AnvilScreenMixin.java +++ b/src/main/java/com/github/breadmoirai/oneclickanvil/mixin/AnvilScreenMixin.java @@ -1,18 +1,18 @@ -package com.github.breadmoirai.oneclickanvil.mixin; -import com.github.breadmoirai.oneclickanvil.client.OneClickAnvilClient; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; - -import net.minecraft.client.gui.screens.inventory.AnvilScreen; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(AnvilScreen.class) -public class AnvilScreenMixin { - @Inject(at = @At("TAIL"), method = "slotChanged(Lnet/minecraft/world/inventory/AbstractContainerMenu;ILnet/minecraft/world/item/ItemStack;)V") - private void onScreenHandlerSlotUpdate(AbstractContainerMenu handler, int slotId, ItemStack stack, CallbackInfo ci) { - OneClickAnvilClient.getInstance().onAnvilScreenSlotUpdate((AnvilScreen) (Object) this, handler, slotId, stack); - } -} +package com.github.breadmoirai.oneclickanvil.mixin; +import com.github.breadmoirai.oneclickanvil.client.OneClickAnvilClient; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; + +import net.minecraft.client.gui.screens.inventory.AnvilScreen; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(AnvilScreen.class) +public class AnvilScreenMixin { + @Inject(at = @At("TAIL"), method = "slotChanged(Lnet/minecraft/world/inventory/AbstractContainerMenu;ILnet/minecraft/world/item/ItemStack;)V") + private void onScreenHandlerSlotUpdate(AbstractContainerMenu handler, int slotId, ItemStack stack, CallbackInfo ci) { + OneClickAnvilClient.getInstance().onAnvilScreenSlotUpdate((AnvilScreen) (Object) this, handler, slotId, stack); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d8bcfde..88c0987 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,47 +1,47 @@ -{ - "schemaVersion": 1, - "id": "one-click-anvil", - "version": "${version}", - "name": "One Click Anvil", - "description": "Anvil faster using less clicks", - "authors": [ - "BreadMoirai" - ], - "contact": { - "homepage": "https://github.com/BreadMoirai/OneClickAnvil", - "issues": "https://github.com/BreadMoirai/OneClickAnvil/discussions", - "sources": "https://github.com/BreadMoirai/OneClickAnvil" - }, - "license": "MIT", - "icon": "assets/oneclickanvil/icon.png", - "environment": "client", - "entrypoints": { - "client": [ - "com.github.breadmoirai.oneclickanvil.client.OneClickAnvilClient" - ], - "modmenu": [ - "com.github.breadmoirai.oneclickanvil.config.OneClickAnvilModMenu" - ] - }, - "mixins": [ - "one-click-anvil.mixins.json" - ], - "depends": { - "fabricloader": ">=0.15.7", - "yet_another_config_lib_v3": ">=${yacl}" - }, - "recommends": { - "modmenu": ">=${modmenu}", - "minecraft": "${minecraft}" - }, - "custom": { - "mc-publish": { - "modrinth": "k3ZiREPD", - "dependencies": [ - "fabric-api(required)", - "modmenu(required)", - "yacl(required)" - ] - } - } -} +{ + "schemaVersion": 1, + "id": "one-click-anvil", + "version": "${version}", + "name": "One Click Anvil", + "description": "Anvil faster using less clicks", + "authors": [ + "BreadMoirai" + ], + "contact": { + "homepage": "https://github.com/BreadMoirai/OneClickAnvil", + "issues": "https://github.com/BreadMoirai/OneClickAnvil/discussions", + "sources": "https://github.com/BreadMoirai/OneClickAnvil" + }, + "license": "MIT", + "icon": "assets/oneclickanvil/icon.png", + "environment": "client", + "entrypoints": { + "client": [ + "com.github.breadmoirai.oneclickanvil.client.OneClickAnvilClient" + ], + "modmenu": [ + "com.github.breadmoirai.oneclickanvil.config.OneClickAnvilModMenu" + ] + }, + "mixins": [ + "one-click-anvil.mixins.json" + ], + "depends": { + "fabricloader": ">=0.15.7", + "yet_another_config_lib_v3": ">=${yacl}" + }, + "recommends": { + "modmenu": ">=${modmenu}", + "minecraft": "${minecraft}" + }, + "custom": { + "mc-publish": { + "modrinth": "k3ZiREPD", + "dependencies": [ + "fabric-api(required)", + "modmenu(required)", + "yacl(required)" + ] + } + } +} diff --git a/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/AnvilTests.java b/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/AnvilTests.java index 9848cbc..035c0f6 100644 --- a/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/AnvilTests.java +++ b/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/AnvilTests.java @@ -1,131 +1,131 @@ -package com.github.breadmoirai.oneclickanvil.testmod; - -import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext; -import net.fabricmc.fabric.api.client.gametest.v1.context.TestSingleplayerContext; - -/** - * OneClickAnvil behaviour tests. Each test seeds a config entry, then exercises the auto-rename - * feature by interacting with a real anvil screen through simulated clicks and server commands. - */ -@SuppressWarnings("UnstableApiUsage") -public class AnvilTests extends TestSuite { - - private final ConfigHelper config; - - public AnvilTests(ClientGameTestContext context, TestSingleplayerContext world) { - super(context, world); - this.config = new ConfigHelper(context); - } - - public void runAll() { - // Config UI first, before the behaviour tests start mutating the config singleton. - configPersistenceViaUi(); - - autoRenameHappyPath(); - repeatedRenameAllStacks(); - disabledEntryNoOp(); - nonMatchingItemNoOp(); - alreadyNamedSkipped(); - nonFullStackSkipped(); - } - - /** Suite 1 — add an entry through the YACL UI, save, reopen, verify it round-trips. */ - public void configPersistenceViaUi() { - clearConfigEntries(); - config.openConfigViaModMenu(); - config.clickYaclButton(ConfigHelper.LABEL_ADD_ENTRY); - config.setYaclString(ConfigHelper.LABEL_ITEM, "minecraft:diamond_sword"); - config.setYaclString(ConfigHelper.LABEL_RENAME, "Excalibur"); - config.setYaclBoolean(ConfigHelper.LABEL_ENABLED, true); - config.saveAndCloseYacl(); - - config.openConfigViaModMenu(); - check("minecraft:diamond_sword".equals(config.getYaclString(ConfigHelper.LABEL_ITEM)), - "Item field did not persist across save/reopen"); - check("Excalibur".equals(config.getYaclString(ConfigHelper.LABEL_RENAME)), - "Rename field did not persist across save/reopen"); - check(config.getYaclBoolean(ConfigHelper.LABEL_ENABLED), - "Enabled toggle did not persist across save/reopen"); - config.saveAndCloseYacl(); - config.closeModsScreen(); - } - - /** Suite 2 — enabled matching entry renames the item and pulls it into the inventory. */ - public void autoRenameHappyPath() { - setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", true); - clearInventory(); - giveItem("minecraft:diamond_sword"); - openAnvil(); - quickMoveFromInventory("minecraft:diamond_sword"); - wait(10); - assertInventoryContainsNamed("minecraft:diamond_sword", "Excalibur"); - closeScreen(); - } - - /** - * Suite 2b — moving one of many matching stacks into the input chains through them all. - * With 9 full stacks in the inventory, a single quick-move into the anvil should drive the - * mod's auto-pull loop until every stack has been renamed (covers the multi-stack feature). - */ - public void repeatedRenameAllStacks() { - setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", true); - clearInventory(); - giveItem("minecraft:diamond_sword 9"); // 9 swords spread across 9 slots, each a full stack - openAnvil(); - quickMoveFromInventory("minecraft:diamond_sword"); - assertInventoryCountNamed("minecraft:diamond_sword", "Excalibur", 9); - closeScreen(); - } - - /** Suite 3 — disabled entry leaves the item untouched. */ - public void disabledEntryNoOp() { - setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", false); - clearInventory(); - giveItem("minecraft:diamond_sword"); - openAnvil(); - quickMoveFromInventory("minecraft:diamond_sword"); - wait(10); - closeScreen(); // returns the input item to the inventory - assertInventoryNotNamed("minecraft:diamond_sword", "Excalibur"); - } - - /** Suite 4 — an item with no matching entry is left untouched. */ - public void nonMatchingItemNoOp() { - setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", true); - clearInventory(); - giveItem("minecraft:iron_ingot 64"); - openAnvil(); - quickMoveFromInventory("minecraft:iron_ingot"); - wait(10); - closeScreen(); - assertInventoryNotNamed("minecraft:iron_ingot", "Excalibur"); - } - - /** Suite 5 — an already-named item is skipped (the mod must not re-rename it). */ - public void alreadyNamedSkipped() { - setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", true); - clearInventory(); - giveItem("minecraft:diamond_sword[minecraft:custom_name='\"Old Sword\"']"); - openAnvil(); - quickMoveFromInventory("minecraft:diamond_sword"); - wait(10); - closeScreen(); - assertInventoryNotNamed("minecraft:diamond_sword", "Excalibur"); - } - - /** Suite 6 — a non-full stack is skipped (covers the "filter out non-full stacks" rule). */ - public void nonFullStackSkipped() { - setSingleConfigEntry("minecraft:dirt", "Fancy Dirt", true); - clearInventory(); - giveItem("minecraft:dirt 1"); - openAnvil(); - quickMoveFromInventory("minecraft:dirt"); - wait(10); - closeScreen(); - assertInventoryNotNamed("minecraft:dirt", "Fancy Dirt"); - } - - private static void check(boolean condition, String message) { - if (!condition) throw new AssertionError(message); - } -} +package com.github.breadmoirai.oneclickanvil.testmod; + +import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext; +import net.fabricmc.fabric.api.client.gametest.v1.context.TestSingleplayerContext; + +/** + * OneClickAnvil behaviour tests. Each test seeds a config entry, then exercises the auto-rename + * feature by interacting with a real anvil screen through simulated clicks and server commands. + */ +@SuppressWarnings("UnstableApiUsage") +public class AnvilTests extends TestSuite { + + private final ConfigHelper config; + + public AnvilTests(ClientGameTestContext context, TestSingleplayerContext world) { + super(context, world); + this.config = new ConfigHelper(context); + } + + public void runAll() { + // Config UI first, before the behaviour tests start mutating the config singleton. + configPersistenceViaUi(); + + autoRenameHappyPath(); + repeatedRenameAllStacks(); + disabledEntryNoOp(); + nonMatchingItemNoOp(); + alreadyNamedSkipped(); + nonFullStackSkipped(); + } + + /** Suite 1 — add an entry through the YACL UI, save, reopen, verify it round-trips. */ + public void configPersistenceViaUi() { + clearConfigEntries(); + config.openConfigViaModMenu(); + config.clickYaclButton(ConfigHelper.LABEL_ADD_ENTRY); + config.setYaclString(ConfigHelper.LABEL_ITEM, "minecraft:diamond_sword"); + config.setYaclString(ConfigHelper.LABEL_RENAME, "Excalibur"); + config.setYaclBoolean(ConfigHelper.LABEL_ENABLED, true); + config.saveAndCloseYacl(); + + config.openConfigViaModMenu(); + check("minecraft:diamond_sword".equals(config.getYaclString(ConfigHelper.LABEL_ITEM)), + "Item field did not persist across save/reopen"); + check("Excalibur".equals(config.getYaclString(ConfigHelper.LABEL_RENAME)), + "Rename field did not persist across save/reopen"); + check(config.getYaclBoolean(ConfigHelper.LABEL_ENABLED), + "Enabled toggle did not persist across save/reopen"); + config.saveAndCloseYacl(); + config.closeModsScreen(); + } + + /** Suite 2 — enabled matching entry renames the item and pulls it into the inventory. */ + public void autoRenameHappyPath() { + setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", true); + clearInventory(); + giveItem("minecraft:diamond_sword"); + openAnvil(); + quickMoveFromInventory("minecraft:diamond_sword"); + wait(10); + assertInventoryContainsNamed("minecraft:diamond_sword", "Excalibur"); + closeScreen(); + } + + /** + * Suite 2b — moving one of many matching stacks into the input chains through them all. + * With 9 full stacks in the inventory, a single quick-move into the anvil should drive the + * mod's auto-pull loop until every stack has been renamed (covers the multi-stack feature). + */ + public void repeatedRenameAllStacks() { + setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", true); + clearInventory(); + giveItem("minecraft:diamond_sword 9"); // 9 swords spread across 9 slots, each a full stack + openAnvil(); + quickMoveFromInventory("minecraft:diamond_sword"); + assertInventoryCountNamed("minecraft:diamond_sword", "Excalibur", 9); + closeScreen(); + } + + /** Suite 3 — disabled entry leaves the item untouched. */ + public void disabledEntryNoOp() { + setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", false); + clearInventory(); + giveItem("minecraft:diamond_sword"); + openAnvil(); + quickMoveFromInventory("minecraft:diamond_sword"); + wait(10); + closeScreen(); // returns the input item to the inventory + assertInventoryNotNamed("minecraft:diamond_sword", "Excalibur"); + } + + /** Suite 4 — an item with no matching entry is left untouched. */ + public void nonMatchingItemNoOp() { + setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", true); + clearInventory(); + giveItem("minecraft:iron_ingot 64"); + openAnvil(); + quickMoveFromInventory("minecraft:iron_ingot"); + wait(10); + closeScreen(); + assertInventoryNotNamed("minecraft:iron_ingot", "Excalibur"); + } + + /** Suite 5 — an already-named item is skipped (the mod must not re-rename it). */ + public void alreadyNamedSkipped() { + setSingleConfigEntry("minecraft:diamond_sword", "Excalibur", true); + clearInventory(); + giveItem("minecraft:diamond_sword[minecraft:custom_name='\"Old Sword\"']"); + openAnvil(); + quickMoveFromInventory("minecraft:diamond_sword"); + wait(10); + closeScreen(); + assertInventoryNotNamed("minecraft:diamond_sword", "Excalibur"); + } + + /** Suite 6 — a non-full stack is skipped (covers the "filter out non-full stacks" rule). */ + public void nonFullStackSkipped() { + setSingleConfigEntry("minecraft:dirt", "Fancy Dirt", true); + clearInventory(); + giveItem("minecraft:dirt 1"); + openAnvil(); + quickMoveFromInventory("minecraft:dirt"); + wait(10); + closeScreen(); + assertInventoryNotNamed("minecraft:dirt", "Fancy Dirt"); + } + + private static void check(boolean condition, String message) { + if (!condition) throw new AssertionError(message); + } +} diff --git a/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/ConfigHelper.java b/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/ConfigHelper.java index ee7bbd3..d76e1f6 100644 --- a/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/ConfigHelper.java +++ b/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/ConfigHelper.java @@ -11,7 +11,7 @@ import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.TitleScreen; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.lang.reflect.Field; import java.util.List; @@ -92,7 +92,7 @@ public void openConfigViaModMenu() { }); context.getInput().setCursorPos(entryCenter[0], entryCenter[1]); - context.getInput().pressMouse(GLFW.GLFW_MOUSE_BUTTON_LEFT); + context.getInput().pressMouse(InputConstants.MOUSE_BUTTON_LEFT); context.waitTick(); context.runOnClient(mc -> { @@ -108,9 +108,9 @@ public void openConfigViaModMenu() { double cy = btn.getY() + btn.getHeight() / 2.0; //? if >=1.21.9 { btn.mouseClicked(new net.minecraft.client.input.MouseButtonEvent(cx, cy, - new net.minecraft.client.input.MouseButtonInfo(GLFW.GLFW_MOUSE_BUTTON_LEFT, 0)), false); + new net.minecraft.client.input.MouseButtonInfo(InputConstants.MOUSE_BUTTON_LEFT, 0)), false); //? } else { - /*btn.mouseClicked(cx, cy, GLFW.GLFW_MOUSE_BUTTON_LEFT); + /*btn.mouseClicked(cx, cy, InputConstants.MOUSE_BUTTON_LEFT); *///? } } catch (ReflectiveOperationException e) { throw new RuntimeException(e); @@ -127,7 +127,7 @@ public void saveAndCloseYacl() { } public void closeModsScreen() { - context.getInput().pressKey(GLFW.GLFW_KEY_ESCAPE); + context.getInput().pressKey(InputConstants.KEY_ESCAPE); context.waitFor(mc -> currentScreen(mc) == null || currentScreen(mc) instanceof TitleScreen); } diff --git a/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/OneClickAnvilGameTests.java b/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/OneClickAnvilGameTests.java index 6024538..f444e18 100644 --- a/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/OneClickAnvilGameTests.java +++ b/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/OneClickAnvilGameTests.java @@ -1,20 +1,20 @@ -package com.github.breadmoirai.oneclickanvil.testmod; - -import net.fabricmc.fabric.api.client.gametest.v1.FabricClientGameTest; -import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext; -import net.fabricmc.fabric.api.client.gametest.v1.context.TestSingleplayerContext; - -/** - * Entry point for all OneClickAnvil client gametests. - * Registered via the "fabric-client-gametest" entrypoint in the testmod's fabric.mod.json. - */ -@SuppressWarnings("UnstableApiUsage") -public class OneClickAnvilGameTests implements FabricClientGameTest { - - @Override - public void runTest(ClientGameTestContext context) { - try (TestSingleplayerContext world = TestSuite.createTestWorld(context)) { - new AnvilTests(context, world).runAll(); - } - } -} +package com.github.breadmoirai.oneclickanvil.testmod; + +import net.fabricmc.fabric.api.client.gametest.v1.FabricClientGameTest; +import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext; +import net.fabricmc.fabric.api.client.gametest.v1.context.TestSingleplayerContext; + +/** + * Entry point for all OneClickAnvil client gametests. + * Registered via the "fabric-client-gametest" entrypoint in the testmod's fabric.mod.json. + */ +@SuppressWarnings("UnstableApiUsage") +public class OneClickAnvilGameTests implements FabricClientGameTest { + + @Override + public void runTest(ClientGameTestContext context) { + try (TestSingleplayerContext world = TestSuite.createTestWorld(context)) { + new AnvilTests(context, world).runAll(); + } + } +} diff --git a/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/TestSuite.java b/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/TestSuite.java index 107b405..336cc23 100644 --- a/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/TestSuite.java +++ b/src/test/java/com/github/breadmoirai/oneclickanvil/testmod/TestSuite.java @@ -19,7 +19,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; -import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; import java.util.LinkedHashMap; import java.util.Map; @@ -45,7 +45,7 @@ public static TestSingleplayerContext createTestWorld(ClientGameTestContext cont TestSingleplayerContext world = context.worldBuilder() .setUseConsistentSettings(true) .create(); - world.getClientLevel().waitForChunksDownload(); + world.getConnection().waitForChunksDownload(); // @a required — runCommand runs as the server console (@s = server, not player) world.getServer().runCommand("time set day"); // Creative so anvil renames are free (no XP cost) and items are unlimited. @@ -97,7 +97,7 @@ protected void openAnvil() { } protected void closeScreen() { - context.getInput().pressKey(GLFW.GLFW_KEY_ESCAPE); + context.getInput().pressKey(InputConstants.KEY_ESCAPE); context.waitFor(mc -> ConfigHelper.currentScreen(mc) == null); } diff --git a/src/test/resources/fabric.mod.json b/src/test/resources/fabric.mod.json index 4b59d16..095cb44 100644 --- a/src/test/resources/fabric.mod.json +++ b/src/test/resources/fabric.mod.json @@ -1,15 +1,15 @@ -{ - "schemaVersion": 1, - "id": "one-click-anvil-testmod", - "version": "1.0.0", - "name": "One Click Anvil Testmod", - "environment": "client", - "entrypoints": { - "fabric-client-gametest": [ - "com.github.breadmoirai.oneclickanvil.testmod.OneClickAnvilGameTests" - ] - }, - "depends": { - "one-click-anvil": "*" - } -} +{ + "schemaVersion": 1, + "id": "one-click-anvil-testmod", + "version": "1.0.0", + "name": "One Click Anvil Testmod", + "environment": "client", + "entrypoints": { + "fabric-client-gametest": [ + "com.github.breadmoirai.oneclickanvil.testmod.OneClickAnvilGameTests" + ] + }, + "depends": { + "one-click-anvil": "*" + } +} diff --git a/stonecutter-swaps.gradle.kts b/stonecutter-swaps.gradle.kts index 17629e4..59070b8 100644 --- a/stonecutter-swaps.gradle.kts +++ b/stonecutter-swaps.gradle.kts @@ -6,12 +6,24 @@ // MultiPlayerGameMode.handleInventoryMouseClick(...) -> handleContainerInput(...) // Fabric's client-gametest API (5.x, used by 26.1) renamed (test code only): // TestSingleplayerContext.getClientWorld() -> getClientLevel() +// The client-gametest API jumped to 6.x for MC 26.3 and moved the chunk-load/level accessors off +// TestSingleplayerContext onto a new TestServerConnection (test code only): +// TestSingleplayerContext.getClientLevel() -> getConnection() +// MC 26.3 also dropped GLFW for SDL, so org.lwjgl.glfw.GLFW is gone from the client classpath; key +// and mouse-button constants now come from com.mojang.blaze3d.platform.InputConstants, which exists +// on every supported version (plain shared code, no swap needed). +// +// Entries are ordered NEWEST FIRST: switching down unwinds the chain in order, so a symbol renamed +// twice (getClientWorld -> getClientLevel -> getConnection) must undo the newest rename first. // // MC 26.2 API changes are handled inline (they are not single-token renames, so they can't be // expressed as swaps): Minecraft.setScreen -> Minecraft.setScreenAndShow (OneClickAnvilConfigScreen), // and the removed public Minecraft.screen field, now read via Minecraft.gui.screen() // (net.minecraft.client.gui.Gui), routed through ConfigHelper.currentScreen(Minecraft). extra["swaps"] = mapOf( + "26.3" to mapOf( + "getClientLevel" to "getConnection", + ), "26.1" to mapOf( "handleInventoryMouseClick" to "handleContainerInput", "ClickType" to "ContainerInput", diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index e050a34..b2e5b16 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -4,7 +4,7 @@ plugins { id("net.fabricmc.fabric-loom-remap") version "1.15-SNAPSHOT" apply false } -stonecutter active "26.2" +stonecutter active "26.3" // Transforms JDK 22+ unnamed variables (_) in the shared src/ when switching versions. // Forward (toUnnamed=false): replaces standalone _ with unused1, unused2, ... (per file) @@ -43,6 +43,7 @@ tasks.register("restoreUnnamedVars") { } afterEvaluate { + tasks.findByName("stonecutterSwitchTo26.3")?.finalizedBy("restoreUnnamedVars") tasks.findByName("stonecutterSwitchTo26.2")?.finalizedBy("restoreUnnamedVars") tasks.findByName("stonecutterSwitchTo26.1.2")?.finalizedBy("restoreUnnamedVars") tasks.findByName("stonecutterSwitchTo26.1.1")?.finalizedBy("restoreUnnamedVars") diff --git a/versions/1.21.10/src/main/resources/one-click-anvil.mixins.json b/versions/1.21.10/src/main/resources/one-click-anvil.mixins.json index cbd86f3..6118b43 100644 --- a/versions/1.21.10/src/main/resources/one-click-anvil.mixins.json +++ b/versions/1.21.10/src/main/resources/one-click-anvil.mixins.json @@ -1,15 +1,15 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.breadmoirai.oneclickanvil.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "AnvilScreenMixin", - "AnvilScreenAccessor" - ], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.breadmoirai.oneclickanvil.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "AnvilScreenMixin", + "AnvilScreenAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/versions/1.21.11/src/main/resources/one-click-anvil.mixins.json b/versions/1.21.11/src/main/resources/one-click-anvil.mixins.json index cbd86f3..6118b43 100644 --- a/versions/1.21.11/src/main/resources/one-click-anvil.mixins.json +++ b/versions/1.21.11/src/main/resources/one-click-anvil.mixins.json @@ -1,15 +1,15 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.breadmoirai.oneclickanvil.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "AnvilScreenMixin", - "AnvilScreenAccessor" - ], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.breadmoirai.oneclickanvil.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "AnvilScreenMixin", + "AnvilScreenAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/versions/1.21.7/gradle.properties b/versions/1.21.7/gradle.properties index 209aabd..75e06b5 100644 --- a/versions/1.21.7/gradle.properties +++ b/versions/1.21.7/gradle.properties @@ -1,13 +1,13 @@ -# Fabric Properties -# check these on https://fabricmc.net/develop/ -minecraft_version=1.21.7 -minecraft_version_range=>=1.21.7 <1.21.8 -loader_version=0.19.1 - -# Dependencies -# check this on https://fabricmc.net/develop/ -fabric_version=0.129.0+1.21.7 -# https://modrinth.com/mod/yacl/versions -yacl_version=3.8.2+1.21.6-fabric -# https://modrinth.com/mod/modmenu/versions -modmenu_version=15.0.2 +# Fabric Properties +# check these on https://fabricmc.net/develop/ +minecraft_version=1.21.7 +minecraft_version_range=>=1.21.7 <1.21.8 +loader_version=0.19.1 + +# Dependencies +# check this on https://fabricmc.net/develop/ +fabric_version=0.129.0+1.21.7 +# https://modrinth.com/mod/yacl/versions +yacl_version=3.8.2+1.21.6-fabric +# https://modrinth.com/mod/modmenu/versions +modmenu_version=15.0.2 diff --git a/versions/1.21.7/src/main/resources/one-click-anvil.mixins.json b/versions/1.21.7/src/main/resources/one-click-anvil.mixins.json index cbd86f3..6118b43 100644 --- a/versions/1.21.7/src/main/resources/one-click-anvil.mixins.json +++ b/versions/1.21.7/src/main/resources/one-click-anvil.mixins.json @@ -1,15 +1,15 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.breadmoirai.oneclickanvil.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "AnvilScreenMixin", - "AnvilScreenAccessor" - ], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.breadmoirai.oneclickanvil.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "AnvilScreenMixin", + "AnvilScreenAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/versions/1.21.8/src/main/resources/one-click-anvil.mixins.json b/versions/1.21.8/src/main/resources/one-click-anvil.mixins.json index cbd86f3..6118b43 100644 --- a/versions/1.21.8/src/main/resources/one-click-anvil.mixins.json +++ b/versions/1.21.8/src/main/resources/one-click-anvil.mixins.json @@ -1,15 +1,15 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.breadmoirai.oneclickanvil.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "AnvilScreenMixin", - "AnvilScreenAccessor" - ], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.breadmoirai.oneclickanvil.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "AnvilScreenMixin", + "AnvilScreenAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/versions/1.21.9/src/main/resources/one-click-anvil.mixins.json b/versions/1.21.9/src/main/resources/one-click-anvil.mixins.json index cbd86f3..6118b43 100644 --- a/versions/1.21.9/src/main/resources/one-click-anvil.mixins.json +++ b/versions/1.21.9/src/main/resources/one-click-anvil.mixins.json @@ -1,15 +1,15 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.breadmoirai.oneclickanvil.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "AnvilScreenMixin", - "AnvilScreenAccessor" - ], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.breadmoirai.oneclickanvil.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "AnvilScreenMixin", + "AnvilScreenAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/versions/26.1.1/src/main/resources/one-click-anvil.mixins.json b/versions/26.1.1/src/main/resources/one-click-anvil.mixins.json index cbd86f3..6118b43 100644 --- a/versions/26.1.1/src/main/resources/one-click-anvil.mixins.json +++ b/versions/26.1.1/src/main/resources/one-click-anvil.mixins.json @@ -1,15 +1,15 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.breadmoirai.oneclickanvil.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "AnvilScreenMixin", - "AnvilScreenAccessor" - ], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.breadmoirai.oneclickanvil.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "AnvilScreenMixin", + "AnvilScreenAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/versions/26.1.2/src/main/resources/one-click-anvil.mixins.json b/versions/26.1.2/src/main/resources/one-click-anvil.mixins.json index cbd86f3..6118b43 100644 --- a/versions/26.1.2/src/main/resources/one-click-anvil.mixins.json +++ b/versions/26.1.2/src/main/resources/one-click-anvil.mixins.json @@ -1,15 +1,15 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.breadmoirai.oneclickanvil.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "AnvilScreenMixin", - "AnvilScreenAccessor" - ], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.breadmoirai.oneclickanvil.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "AnvilScreenMixin", + "AnvilScreenAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/versions/26.1/src/main/resources/one-click-anvil.mixins.json b/versions/26.1/src/main/resources/one-click-anvil.mixins.json index cbd86f3..6118b43 100644 --- a/versions/26.1/src/main/resources/one-click-anvil.mixins.json +++ b/versions/26.1/src/main/resources/one-click-anvil.mixins.json @@ -1,15 +1,15 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.breadmoirai.oneclickanvil.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "AnvilScreenMixin", - "AnvilScreenAccessor" - ], - "injectors": { - "defaultRequire": 1 - } -} +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.breadmoirai.oneclickanvil.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "AnvilScreenMixin", + "AnvilScreenAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/versions/26.3/gradle.properties b/versions/26.3/gradle.properties new file mode 100644 index 0000000..5b05151 --- /dev/null +++ b/versions/26.3/gradle.properties @@ -0,0 +1,13 @@ +# Fabric Properties +# check these on https://fabricmc.net/develop/ +minecraft_version=26.3 +minecraft_version_range=>=26.3 <26.4 +loader_version=0.19.5 + +# Dependencies +# check this on https://fabricmc.net/develop/ +fabric_version=0.160.5+26.3 +# https://modrinth.com/mod/yacl/versions +yacl_version=3.9.6+26.3-fabric +# https://modrinth.com/mod/modmenu/versions +modmenu_version=21.0.0-beta.1 diff --git a/versions/26.3/src/main/resources/one-click-anvil.mixins.json b/versions/26.3/src/main/resources/one-click-anvil.mixins.json new file mode 100644 index 0000000..cbd86f3 --- /dev/null +++ b/versions/26.3/src/main/resources/one-click-anvil.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.breadmoirai.oneclickanvil.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + "AnvilScreenMixin", + "AnvilScreenAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +}