refactor: port multipart compatibility to java

Preserve the Scala Function4 singleton ABI and MCPC failure fallback.
This commit is contained in:
Algent committed 2026-08-30 15:40:47 +02:00
1 parent 53e5901360
commit b2bdf569e8
8 files changed
+183 -55

No files matched your search

+8
View File
@@ -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.
+38
View File
@@ -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.
+13 -8
View File
@@ -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'"' '/<testsuite /{t+=$4;f+=$8;e+=$10} END{print "tests="t" failures="f" e
grep -o 'tests="[0-9]*" skipped="[0-9]*" failures="[0-9]*" errors="[0-9]*"' run/server/junit-out/TEST-*.xml
```
Current baseline: **153 plain-JVM tests, 77 Forge server tests, all passing at their last completed runs.**
Current baseline: **156 plain-JVM tests, 79 Forge server tests, all passing at their last completed runs.**
### ABI diff against the reference
@@ -230,7 +230,7 @@ All eight load-bearing `$class` helpers from the inventory, both registries, and
`MultiPartRegistry`, `TileMultipart`, `TMultiPart`, `TickScheduler`, `BlockMultipart`, the complete
`IRedstonePart`/`RedstoneInteractions` unit, `MicroRecipe`, and the `TPartialOcclusionTile`, `TSlottedTile`, and
`TRedstoneTile`, `TTileChangeTile`, `TFluidHandlerTile`, `TIInventoryTile`/`JInventoryTile`, `TileMultipartClient`, and
`TRandomDisplayTickTile` Java-trait ports.
`TRandomDisplayTickTile` Java-trait ports, plus `MultipartCompatiblity`/`MCPCCompatModule`.
Plus the six marker interfaces: `TSlottedPart`, `IRandomDisplayTick`, `INeighborTileChange`, `TRandomUpdateTick`,
`ISidedHollowConnect`, `IMicroMaterialRender`, plus `MultipartHelper`, `TileCache`, `PacketScheduler` and the `ControlKeyModifer` pair.
@@ -245,7 +245,7 @@ across the port. It is also where the two shim constraints in the gotchas list w
`rayTraceAll`'s index production is now characterized, closing the gap the read-path cleanup left: the index written
into `ExtendedMOP.data` is what `reduceMOP` hands back to every click, activate, harvest and pick block.
91 Java files, 38 Scala files, ~5,328 Scala lines left (non-blank; that is the metric this figure has always used).
95 Java files, 37 Scala files, ~5,285 Scala lines left (non-blank; that is the metric this figure has always used).
## What is left, and in what order
@@ -327,6 +327,11 @@ shape guard pins the exact 16-method base interface, one-method child interface,
and class caching. GuideNH only loads `TileMultipartClient` by name for `isInstanceOf`; no audited consumer references
either removed `$class` helper. The true client rendering and particle paths remain on the manual checklist.
`MultipartCompatiblity` and `MCPCCompatModule` are now Java. Their two static facades, two companion singletons and
mutable Scala `Function4` callback retain their exact public descriptors. Three plain-JVM tests freeze the raw shape,
default allow behavior and shared setter identity; two Forge tests freeze non-MCPC loading and the logged missing-hook
fallback. The optional successful MCPC hook still needs a real patched `World` implementation to exercise end to end.
**Medium.** The `handler` packages on both sides, `ItemMicroPart`,
`MicroblockPlacement`, `PlacementGrids`, `BlockMicroMaterial`, `MissingMicroMaterial`, `ConfigContent`,
`DefaultContent`.
@@ -335,9 +340,9 @@ either removed `$class` helper. The true client rendering and particle paths rem
narrow generator relaxation: Java-trait parent linearization, explicit field-accessor recognition, and exclusion of
transient runtime caches from generated copying.
Take `multipart/handler/MultipartCompatiblity.scala` next as the smallest medium-risk Phase 6 handler unit. Preserve
the misspelled public singleton name and its Scala `Function4` accessor, characterize the default allow path and the
reflective MCPC hook failure path first, and keep the characterization/port commits separate.
Take `multipart/handler/MultipartMod.scala` next as the next small, independent handler unit. Freeze both singleton
types, the exact `@Mod` metadata and all five FML lifecycle annotations before changing it, then exercise pre/init/
post-init and server cleanup through the Forge harness. Keep the characterization and port commits separate.
**Phase 6/7, last.** `Microblock` and the microblock shape hierarchy, `MicroblockGenerator`, `MultipartGenerator`, and
all of `multipart/asm/`. The ASM subsystem should be last; freeze generated-class fixtures before touching it.
@@ -0,0 +1,49 @@
package codechicken.multipart.handler;
import java.lang.reflect.Method;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import scala.runtime.AbstractFunction4;
/** Scala-object-compatible implementation for the optional MCPC placement hook. */
public final class MCPCCompatModule$ {
public static final MCPCCompatModule$ MODULE$ = new MCPCCompatModule$();
private MCPCCompatModule$() {}
public void load() {
try {
Method canPlacePart = World.class
.getDeclaredMethod("canPlaceMultipart", Block.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
MultipartCompatiblity.canAddPart_$eq(new MCPCPlacement(canPlacePart));
} catch (Exception e) {
MultipartProxy.logger().error("Failed to integrate MCPC placement hooks", e);
}
}
private static final class MCPCPlacement extends AbstractFunction4<World, Object, Object, Object, Object> {
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 <E extends Throwable, R> R throwUnchecked(Throwable throwable) throws E {
throw (E) throwable;
}
}
}
@@ -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();
}
}
@@ -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<World, Object, Object, Object, Object> canAddPart = new AllowPlacement();
private MultipartCompatiblity$() {}
public Function4<World, Object, Object, Object, Object> canAddPart() {
return canAddPart;
}
public void canAddPart_$eq(Function4<World, Object, Object, Object, Object> callback) {
canAddPart = callback;
}
public void load() {
if (FMLCommonHandler.instance().getModName().contains("mcpc")) {
MCPCCompatModule.load();
}
}
private static final class AllowPlacement extends AbstractFunction4<World, Object, Object, Object, Object> {
AllowPlacement() {}
@Override
public Object apply(World world, Object x, Object y, Object z) {
return Boolean.TRUE;
}
}
}
@@ -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<World, Object, Object, Object, Object> canAddPart() {
return MultipartCompatiblity$.MODULE$.canAddPart();
}
public static void canAddPart_$eq(Function4<World, Object, Object, Object, Object> callback) {
MultipartCompatiblity$.MODULE$.canAddPart_$eq(callback);
}
public static void load() {
MultipartCompatiblity$.MODULE$.load();
}
}
@@ -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
)
}
}
}