From 1c91fbb4c966f6ead0a0576cc08e7c9b29407be4 Mon Sep 17 00:00:00 2001 From: Algent Date: Sun, 30 Aug 2026 22:02:48 +0200 Subject: [PATCH] refactor: port microblock event handler Preserve the client-only ABI and dedicated-server side stripping. --- JAVA_MIGRATION.md | 12 +++++ JAVA_MIGRATION_DIVERGENCES.md | 40 +++++++++++++++++ JAVA_MIGRATION_HANDOFF.md | 29 +++++++----- JAVA_MIGRATION_MANUAL_CHECKS.md | 3 +- .../handler/MicroblockEventHandler$.java | 44 +++++++++++++++++++ .../handler/MicroblockEventHandler.java | 25 +++++++++++ .../handler/MicroblockEventHandler.scala | 44 ------------------- .../microblock/handler/proxies.scala | 2 +- 8 files changed, 143 insertions(+), 56 deletions(-) create mode 100644 src/main/scala/codechicken/microblock/handler/MicroblockEventHandler$.java create mode 100644 src/main/scala/codechicken/microblock/handler/MicroblockEventHandler.java delete mode 100644 src/main/scala/codechicken/microblock/handler/MicroblockEventHandler.scala diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index 6246a89..b620d24 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -772,3 +772,15 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec Scala cannot apply property-assignment syntax to a Java-authored setter. The compiled accessor ABI is unchanged. - All 162 plain-JVM and all 85 Java 8 Forge dedicated-server tests pass. Startup and lifecycle dispatch are not a meaningful focused throughput or allocation target; `MicroblockEventHandler.scala` is the next target. +- Reproduced the reported stale incremental `@Mod(version)` failure immediately after a commit. Gradle reran + `compileScala`, but Zinc retained the joint-compiled Java classes that had inlined the previous `Tags.VERSION`. +- Configured `compileScala` to force Zinc recompilation whenever Gradle schedules the task. The focused version test + passes without cleaning both before and after a commit changes the generated version, so the assertion remains. +- Characterized `MicroblockEventHandler` against untouched Scala. Two plain-JVM cases freeze both singleton types, all + four public event methods, normal event metadata and both client-only boundaries. One Forge case freezes companion + registration and complete method stripping on a dedicated server. +- Ported the handler to a Java facade/companion pair and changed the one Scala registration to name `MODULE$` + explicitly. Texture-atlas filtering, highlight guards, matrix/render sequence and cancellation behavior are + unchanged; their actual rendering remains on the client manual checklist. +- All 164 plain-JVM and all 86 Java 8 Forge dedicated-server tests pass. This event-only adapter is not a meaningful + focused performance target; `microblock/handler/packethandlers.scala` is next. diff --git a/JAVA_MIGRATION_DIVERGENCES.md b/JAVA_MIGRATION_DIVERGENCES.md index d2f2b86..b7968e1 100644 --- a/JAVA_MIGRATION_DIVERGENCES.md +++ b/JAVA_MIGRATION_DIVERGENCES.md @@ -1917,3 +1917,43 @@ constructor. Neither changes runtime annotation data or the callable public surf lifecycle, initializes every proxy item and builds a usable material ID map before shutting down cleanly. - Raw `javap` comparison confirms identical callable public names/descriptors; reflection confirms identical FML annotations, and the emitted class list is unchanged. + +## 2026-08-30 — MicroblockEventHandler Java port + +The ForgeMicroblock client event handler is now a Java facade/companion pair. The server proxy explicitly registers +`MicroblockEventHandler$.MODULE$`, preserving the Scala object's identity. + +### Observable behavior + +No known runtime divergence. Post-stitch handling still reloads material icons only for texture-map type zero. +Highlight handling retains the same ordered guards for a non-null current stack, the microblock item, a non-null hit +and a block hit. It then pushes the GL matrix, translates to world coordinates, delegates to the item renderer, cancels +only when that renderer succeeds, and pops the matrix in the same sequence. + +Both handlers remain client-only. On a dedicated server Forge strips both methods from both singleton types before +the proxy registers the companion. Registration still reaches the event bus and records the same companion owner, but +there are correctly no server-side subscribers. + +### ABI, annotations and source compatibility + +`MicroblockEventHandler` retains the exact two public static methods. `MicroblockEventHandler$` retains `MODULE$` and +the matching two public instance methods. Every method still carries `@SubscribeEvent` with `NORMAL` priority and +`receiveCanceled = false`, plus `@SideOnly(CLIENT)`; neither class is itself side-only. Public names and descriptors are +identical to the reference, and both jars emit exactly `MicroblockEventHandler.class` and +`MicroblockEventHandler$.class`. + +The in-repo Scala registration now spells the object value as `MicroblockEventHandler$.MODULE$`. Compiled external +callers and event-bus identity are unchanged, and no frozen binary or audited source consumer names either type. + +Accepted divergence: Scala signature/marker attributes disappear, and the static Java facade gains only a private +constructor. Neither changes runtime annotations or the callable public surface. + +### Validation + +- `MicroblockEventHandlerCharacterizationTest`: 2 plain-JVM tests, unchanged from the Scala baseline. +- `MicroblockEventHandlerFunctionalTest`: 1 Forge test, unchanged from the Scala baseline. +- Complete plain-JVM suite: 164 tests, 0 failures, 0 errors. +- Java 8 Forge dedicated-server suite: 86 tests, 0 failures, 0 errors. +- Raw `javap` comparison confirms identical callable public members, reflection confirms identical annotations, and + the emitted class list is unchanged. +- Texture stitching and placement-highlight rendering require a client and remain on the manual checklist. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index 4c7253b..156724a 100644 --- a/JAVA_MIGRATION_HANDOFF.md +++ b/JAVA_MIGRATION_HANDOFF.md @@ -12,8 +12,8 @@ what breaks, and what is left. The other documents hold the reasoning. | `JAVA_MIGRATION_MANUAL_CHECKS.md` | What no automated test can cover, and must be checked by hand in a client | | `JAVA_MIGRATION_PROFILE.md` | The focused baseline, first measured result, findings, and exact rerun command | -Branch: `algent/java`. Base: `master`. 93 commits including separate characterization and port commits for -`MicroblockMod`. +Branch: `algent/java`. Base: `master`. 96 commits including the incremental-version build fix and separate +characterization and port commits for `MicroblockEventHandler`. ## The one rule that matters @@ -67,7 +67,7 @@ awk -F'"' '/