diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index 03a269b..a9b5282 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -736,3 +736,11 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec The runtime trait surfaces remain exact; the raw dev-jar source-build limitation remains documented. - All 153 plain-JVM tests and all 77 Java 8 Forge dedicated-server tests pass. Actual static/dynamic rendering and particle appearance remain client-only manual checks. +- Characterized `MultipartCompatiblity` and `MCPCCompatModule` against untouched Scala. Three plain-JVM cases freeze + both static facades, both `MODULE$` companions, the private Scala `Function4` field, default allow behavior and + callback identity; two Forge cases freeze non-MCPC loading and the logged missing-hook fallback. +- Ported both singletons to four Java types with unchanged public names and descriptors. The callback still propagates + reflection and cast failures unchanged, while the two Scala anonymous-function artifacts become private named Java + callback classes. No frozen binary or audited source consumer names those implementation classes. +- All 156 plain-JVM tests and all 79 Java 8 Forge dedicated-server tests pass. This initialization-only hook is not a + meaningful target for the focused allocation benchmark; successful MCPC integration remains environment-dependent. diff --git a/JAVA_MIGRATION_DIVERGENCES.md b/JAVA_MIGRATION_DIVERGENCES.md index aa203f1..17a63e8 100644 --- a/JAVA_MIGRATION_DIVERGENCES.md +++ b/JAVA_MIGRATION_DIVERGENCES.md @@ -1748,3 +1748,41 @@ remain ordinary private fields. Trait registration moved before `BlockMultipart` - All seven tests passed against the untouched Scala implementation before the port; all 77 Forge tests pass after it. - Complete plain-JVM suite: 153 tests, 0 failures, 0 errors. - Actual block/TESR rendering and particle appearance require a client and remain on the manual checklist. + +## 2026-08-30 — MultipartCompatiblity/MCPCCompatModule Java port + +The intentionally misspelled `MultipartCompatiblity` singleton and its optional MCPC integration companion are now +Java. The in-repo placement gate still reads the same mutable callback, and no frozen binary or audited source consumer +names either singleton or its generated closure classes directly. + +### Observable behavior + +No known runtime divergence. The callback initially allows every placement. `load()` still performs a case-sensitive +`"mcpc"` check against FML's mod name and otherwise leaves the current callback untouched. MCPC loading still looks +for `World.canPlaceMultipart(Block, int, int, int)`, installs the reflective callback only after a successful lookup, +and logs `Failed to integrate MCPC placement hooks` without replacing the previous callback when lookup fails. + +The installed callback passes `MultipartProxy.block()` and the same boxed coordinates to `Method.invoke`, casts the +result to `Boolean`, and returns its primitive value. Java's checked-reflection restriction is bridged with a private +unchecked throw helper so invocation, access and target failures propagate as the same exception objects rather than +being wrapped in a new exception type. + +### ABI and emitted classes + +The public surface is descriptor-identical to the reference: static `load`, `canAddPart` and `canAddPart_$eq` remain on +`MultipartCompatiblity`; the companion retains `MODULE$`, the private `scala.Function4` field and the three matching +instance methods; `MCPCCompatModule` and `MCPCCompatModule$` retain their static and instance `load` methods. + +Accepted divergence: `MultipartCompatiblity$$anonfun$1` and `MCPCCompatModule$$anonfun$load$1` are replaced by the +private Java callback classes `MultipartCompatiblity$$AllowPlacement` and `MCPCCompatModule$$MCPCPlacement`. These are +closure implementation details with no consumer reference. The four public facade/companion class names are retained. + +### Validation + +- `MultipartCompatiblityCharacterizationTest`: 3 plain-JVM tests, unchanged from the Scala baseline. +- `MultipartCompatiblityFunctionalTest`: 2 Forge tests, unchanged from the Scala baseline. +- Complete plain-JVM suite: 156 tests, 0 failures, 0 errors. +- Java 8 Forge dedicated-server suite: 79 tests, 0 failures, 0 errors. +- Raw `javap` comparison confirms identical public names and descriptors for all four public types. +- The successful reflective path requires an MCPC-patched `World` and remains an environment-specific integration + check; the stock development server covers its failure fallback only. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index cec0670..6219cf3 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`. 85 commits including separate characterization and port commits for -`TileMultipartClient`/`TRandomDisplayTickTile`. +Branch: `algent/java`. Base: `master`. 87 commits including separate characterization and port commits for +`MultipartCompatiblity`/`MCPCCompatModule`. ## The one rule that matters @@ -67,7 +67,7 @@ awk -F'"' '/ { + + private final Method canPlacePart; + + MCPCPlacement(Method canPlacePart) { + this.canPlacePart = canPlacePart; + } + + @Override + public Object apply(World world, Object x, Object y, Object z) { + try { + return ((Boolean) canPlacePart.invoke(world, MultipartProxy.block(), x, y, z)).booleanValue(); + } catch (Exception e) { + return throwUnchecked(e); + } + } + + @SuppressWarnings("unchecked") + private static R throwUnchecked(Throwable throwable) throws E { + throw (E) throwable; + } + } +} diff --git a/src/main/scala/codechicken/multipart/handler/MCPCCompatModule.java b/src/main/scala/codechicken/multipart/handler/MCPCCompatModule.java new file mode 100644 index 0000000..064af80 --- /dev/null +++ b/src/main/scala/codechicken/multipart/handler/MCPCCompatModule.java @@ -0,0 +1,11 @@ +package codechicken.multipart.handler; + +/** Static facade for the optional MCPC placement hook. */ +public final class MCPCCompatModule { + + private MCPCCompatModule() {} + + public static void load() { + MCPCCompatModule$.MODULE$.load(); + } +} diff --git a/src/main/scala/codechicken/multipart/handler/MultipartCompatiblity$.java b/src/main/scala/codechicken/multipart/handler/MultipartCompatiblity$.java new file mode 100644 index 0000000..4e02b02 --- /dev/null +++ b/src/main/scala/codechicken/multipart/handler/MultipartCompatiblity$.java @@ -0,0 +1,41 @@ +package codechicken.multipart.handler; + +import net.minecraft.world.World; + +import cpw.mods.fml.common.FMLCommonHandler; +import scala.Function4; +import scala.runtime.AbstractFunction4; + +/** Scala-object-compatible implementation for the multipart placement compatibility hook. */ +public final class MultipartCompatiblity$ { + + public static final MultipartCompatiblity$ MODULE$ = new MultipartCompatiblity$(); + + private Function4 canAddPart = new AllowPlacement(); + + private MultipartCompatiblity$() {} + + public Function4 canAddPart() { + return canAddPart; + } + + public void canAddPart_$eq(Function4 callback) { + canAddPart = callback; + } + + public void load() { + if (FMLCommonHandler.instance().getModName().contains("mcpc")) { + MCPCCompatModule.load(); + } + } + + private static final class AllowPlacement extends AbstractFunction4 { + + AllowPlacement() {} + + @Override + public Object apply(World world, Object x, Object y, Object z) { + return Boolean.TRUE; + } + } +} diff --git a/src/main/scala/codechicken/multipart/handler/MultipartCompatiblity.java b/src/main/scala/codechicken/multipart/handler/MultipartCompatiblity.java new file mode 100644 index 0000000..e8ac2b4 --- /dev/null +++ b/src/main/scala/codechicken/multipart/handler/MultipartCompatiblity.java @@ -0,0 +1,23 @@ +package codechicken.multipart.handler; + +import net.minecraft.world.World; + +import scala.Function4; + +/** Static facade for the multipart placement compatibility hook. */ +public final class MultipartCompatiblity { + + private MultipartCompatiblity() {} + + public static Function4 canAddPart() { + return MultipartCompatiblity$.MODULE$.canAddPart(); + } + + public static void canAddPart_$eq(Function4 callback) { + MultipartCompatiblity$.MODULE$.canAddPart_$eq(callback); + } + + public static void load() { + MultipartCompatiblity$.MODULE$.load(); + } +} diff --git a/src/main/scala/codechicken/multipart/handler/MultipartCompatiblity.scala b/src/main/scala/codechicken/multipart/handler/MultipartCompatiblity.scala deleted file mode 100644 index 1b446f7..0000000 --- a/src/main/scala/codechicken/multipart/handler/MultipartCompatiblity.scala +++ /dev/null @@ -1,47 +0,0 @@ -package codechicken.multipart.handler - -import net.minecraft.world.World -import cpw.mods.fml.common.FMLCommonHandler -import net.minecraft.block.Block - -object MultipartCompatiblity { - var canAddPart = (world: World, x: Int, y: Int, z: Int) => true - - def load() { - if (FMLCommonHandler.instance().getModName.contains("mcpc")) - MCPCCompatModule.load() - } -} - -object MCPCCompatModule { - def load() { - try { - val m_canPlacePart = classOf[World].getDeclaredMethod( - "canPlaceMultipart", - classOf[Block], - classOf[Int], - classOf[Int], - classOf[Int] - ) - MultipartCompatiblity.canAddPart = - (world: World, x: Int, y: Int, z: Int) => { - m_canPlacePart - .invoke( - world, - MultipartProxy.block, - x: Integer, - y: Integer, - z: Integer - ) - .asInstanceOf[Boolean] - .booleanValue() - } - } catch { - case e: Exception => - MultipartProxy.logger.error( - "Failed to integrate MCPC placement hooks", - e - ) - } - } -}