refactor: port multipart mod to java

Preserve the Scala FML instance and packet-channel identity.
This commit is contained in:
Algent committed 2026-08-30 16:23:14 +02:00
1 parent 6dbdb74559
commit 3e6a7ce6f3
7 files changed
+172 -59

No files matched your search

+11
View File
@@ -744,3 +744,14 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
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.
- Characterized `MultipartMod` against untouched Scala. Two plain-JVM cases freeze both annotated singleton types,
all ten lifecycle methods and annotations, plus the `MultipartPH.channel` companion descriptor and identity; two
Forge cases freeze FML's companion mod instance, completed initialization and server-stop cleanup.
- Ported the singleton to an annotated Java facade/companion pair while retaining `modLanguage = "scala"`. The one
source use of the object as a value now names `MultipartMod$.MODULE$` explicitly, leaving the compiled packet-handler
field and accessor unchanged.
- Found that the inherited `MultipartProxy.postInit` static forwarder carries `@SideOnly(CLIENT)` and is stripped on a
dedicated server. The Java companion therefore invokes `MultipartProxy$.MODULE$` directly, matching the reference
Scala bytecode and allowing virtual resolution to reach the server implementation.
- All 158 plain-JVM tests and all 81 Java 8 Forge dedicated-server tests pass. Mod lifecycle dispatch is startup-only,
so it is not a meaningful focused throughput or allocation target.
+43
View File
@@ -1786,3 +1786,46 @@ closure implementation details with no consumer reference. The four public facad
- 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.
## 2026-08-30 — MultipartMod Java port
The ForgeMultipart FML entry point is now an annotated Java facade/companion pair. It deliberately remains a
`modLanguage = "scala"` mod: FML's Scala language adapter loads `MultipartMod$.MODULE$`, which is also the identity
CodeChickenLib uses for the multipart packet channel.
### Observable behavior
No known runtime divergence. Pre-initialization still passes the event's configuration directory and logger to the
proxy; initialization still delegates directly; post-initialization still finalizes the registry and proxy only when
multipart registration is required; server startup still rebuilds the part ID map; and server shutdown still clears
the loading-world reference and control-key map.
The proxy calls use `MultipartProxy$.MODULE$`, matching the original Scala bytecode. This is required on a dedicated
server: the raw `MultipartProxy.postInit()` static forwarder inherits `@SideOnly(CLIENT)` from the client override and
Forge strips it. Calling that facade from common Java compiles but fails at runtime with `NoSuchMethodError`; companion
dispatch survives stripping and resolves to the server superclass method.
### ABI, annotations and source compatibility
`MultipartMod` retains the exact five public static event methods. `MultipartMod$` retains `MODULE$` and the matching
five public instance methods. Both classes still carry the same `@Mod` values, and every method still carries
`@Mod.EventHandler`. Public names and descriptors are identical to the reference.
The in-repo Scala expression `val channel = MultipartMod` becomes `MultipartMod$.MODULE$`. The compiled
`MultipartPH.channel` field and accessor remain typed as `MultipartMod$`, so packet identity and binary compatibility
are unchanged. No frozen external consumer names either mod class.
Accepted divergence: the Scala signature/marker attributes disappear, and the static Java facade gains only a private
constructor. These do not change the runtime annotation data or callable public surface. The emitted class list remains
exactly `MultipartMod.class` and `MultipartMod$.class`.
### Validation
- `MultipartModCharacterizationTest`: 2 plain-JVM tests, unchanged from the Scala baseline.
- `MultipartModFunctionalTest`: 2 Forge tests, unchanged from the Scala baseline.
- Complete plain-JVM suite: 158 tests, 0 failures, 0 errors.
- Java 8 Forge dedicated-server suite: 81 tests, 0 failures, 0 errors.
- The Forge run loads all nine mods, identifies `MultipartMod$.MODULE$` as the ForgeMultipart instance, completes every
startup phase, reaches server-started tests, and shuts down cleanly.
- Raw `javap` comparison confirms identical public names/descriptors for `MultipartMod`, `MultipartMod$` and
`MultipartPH`; reflection confirms identical FML annotations.
+19 -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`. 87 commits including separate characterization and port commits for
`MultipartCompatiblity`/`MCPCCompatModule`.
Branch: `algent/java`. Base: `master`. 89 commits including separate characterization and port commits for
`MultipartMod`.
## 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: **156 plain-JVM tests, 79 Forge server tests, all passing at their last completed runs.**
Current baseline: **158 plain-JVM tests, 81 Forge server tests, all passing at their last completed runs.**
### ABI diff against the reference
@@ -151,6 +151,11 @@ not the whole test — check the reflective string constants too. `MultipartHelp
any consumer's constant pool as a type, but guidenh names it as a string, so it was kept. `IconHitEffects$` was in
neither and was dropped. Check both lists before deleting a companion.
**Do not call a side-only Scala object's static facade from common Java.** `MultipartProxy.postInit()` exists in the
raw jar but inherits `@SideOnly(CLIENT)` from the client override, so Forge strips that forwarder on a dedicated server
and a Java call fails with `NoSuchMethodError`. Call `MultipartProxy$.MODULE$.postInit()` as the Scala reference did;
after side stripping, virtual resolution reaches the server superclass implementation.
**Classes that cannot class-initialize headless make good probes.** `MultipartSaveLoad` reflects into `TileEntity`'s
static maps through `ObfMapping` and always throws under a plain JVM. That turns "did this branch reach the loader?"
into an assertion: returning normally proves the guard short-circuited, and `assertThrows(LinkageError.class, ...)`
@@ -230,7 +235,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, plus `MultipartCompatiblity`/`MCPCCompatModule`.
`TRandomDisplayTickTile` Java-trait ports, plus `MultipartCompatiblity`/`MCPCCompatModule` and `MultipartMod`.
Plus the six marker interfaces: `TSlottedPart`, `IRandomDisplayTick`, `INeighborTileChange`, `TRandomUpdateTick`,
`ISidedHollowConnect`, `IMicroMaterialRender`, plus `MultipartHelper`, `TileCache`, `PacketScheduler` and the `ControlKeyModifer` pair.
@@ -245,7 +250,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.
95 Java files, 37 Scala files, ~5,285 Scala lines left (non-blank; that is the metric this figure has always used).
97 Java files, 36 Scala files, ~5,241 Scala lines left (non-blank; that is the metric this figure has always used).
## What is left, and in what order
@@ -332,6 +337,11 @@ mutable Scala `Function4` callback retain their exact public descriptors. Three
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.
`MultipartMod` is now Java while remaining a Scala-language FML mod. Both annotated class names, all ten lifecycle
methods and `MultipartMod$.MODULE$` retain their exact public descriptors and annotations. FML still uses the companion
as the mod instance, and `MultipartPH.channel()` still returns that same companion with its original descriptor. Two
plain-JVM and two Forge tests freeze the shape, identity, completed lifecycle and server-stop cleanup.
**Medium.** The `handler` packages on both sides, `ItemMicroPart`,
`MicroblockPlacement`, `PlacementGrids`, `BlockMicroMaterial`, `MissingMicroMaterial`, `ConfigContent`,
`DefaultContent`.
@@ -340,9 +350,10 @@ fallback. The optional successful MCPC hook still needs a real patched `World` i
narrow generator relaxation: Java-trait parent linearization, explicit field-accessor recognition, and exclusion of
transient runtime caches from generated copying.
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.
Take `multipart/handler/MultipartEventHandler.scala` next. Preserve both singleton types and event-bus identity; freeze
every `@SubscribeEvent` priority plus the client-only highlight annotation before changing it. Exercise load/unload,
chunk watch/unwatch and end-of-server-tick dispatch where the Forge harness can observe them, and 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,53 @@
package codechicken.multipart.handler;
import codechicken.multipart.ControlKeyModifer;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.Tags;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
@Mod(
modid = "ForgeMultipart",
name = "Forge Multipart",
acceptedMinecraftVersions = "[1.7.10]",
version = Tags.VERSION,
modLanguage = "scala")
public final class MultipartMod$ {
public static final MultipartMod$ MODULE$ = new MultipartMod$();
private MultipartMod$() {}
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
MultipartProxy$.MODULE$.preInit(event.getModConfigurationDirectory(), event.getModLog());
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
MultipartProxy$.MODULE$.init();
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
if (MultiPartRegistry.required()) {
MultiPartRegistry.postInit();
MultipartProxy$.MODULE$.postInit();
}
}
@Mod.EventHandler
public void beforeServerStart(FMLServerAboutToStartEvent event) {
MultiPartRegistry.beforeServerStart();
}
@Mod.EventHandler
public void serverStopped(FMLServerStoppedEvent event) {
MultipartSaveLoad.loadingWorld_$eq(null);
ControlKeyModifer.map().clear();
}
}
@@ -0,0 +1,45 @@
package codechicken.multipart.handler;
import codechicken.multipart.Tags;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
@Mod(
modid = "ForgeMultipart",
name = "Forge Multipart",
acceptedMinecraftVersions = "[1.7.10]",
version = Tags.VERSION,
modLanguage = "scala")
public final class MultipartMod {
private MultipartMod() {}
@Mod.EventHandler
public static void preInit(FMLPreInitializationEvent event) {
MultipartMod$.MODULE$.preInit(event);
}
@Mod.EventHandler
public static void init(FMLInitializationEvent event) {
MultipartMod$.MODULE$.init(event);
}
@Mod.EventHandler
public static void postInit(FMLPostInitializationEvent event) {
MultipartMod$.MODULE$.postInit(event);
}
@Mod.EventHandler
public static void beforeServerStart(FMLServerAboutToStartEvent event) {
MultipartMod$.MODULE$.beforeServerStart(event);
}
@Mod.EventHandler
public static void serverStopped(FMLServerStoppedEvent event) {
MultipartMod$.MODULE$.serverStopped(event);
}
}
@@ -1,50 +0,0 @@
package codechicken.multipart.handler
import cpw.mods.fml.common.Mod
import cpw.mods.fml.common.event.{
FMLInitializationEvent,
FMLPostInitializationEvent,
FMLPreInitializationEvent,
FMLServerAboutToStartEvent,
FMLServerStoppedEvent
}
import cpw.mods.fml.common.Mod.EventHandler
import codechicken.multipart.{ControlKeyModifer, MultiPartRegistry, Tags}
@Mod(
modid = "ForgeMultipart",
name = "Forge Multipart",
acceptedMinecraftVersions = "[1.7.10]",
version = Tags.VERSION,
modLanguage = "scala"
)
object MultipartMod {
@EventHandler
def preInit(event: FMLPreInitializationEvent) {
MultipartProxy.preInit(event.getModConfigurationDirectory, event.getModLog)
}
@EventHandler
def init(event: FMLInitializationEvent) {
MultipartProxy.init()
}
@EventHandler
def postInit(event: FMLPostInitializationEvent) {
if (MultiPartRegistry.required) {
MultiPartRegistry.postInit()
MultipartProxy.postInit()
}
}
@EventHandler
def beforeServerStart(event: FMLServerAboutToStartEvent) {
MultiPartRegistry.beforeServerStart()
}
@EventHandler
def serverStopped(event: FMLServerStoppedEvent) {
MultipartSaveLoad.loadingWorld = null;
ControlKeyModifer.map.clear();
}
}
@@ -33,7 +33,7 @@ import net.minecraft.util.{ChatComponentText, ChatComponentTranslation}
import net.minecraft.network.NetHandlerPlayServer
class MultipartPH {
val channel = MultipartMod
val channel = MultipartMod$.MODULE$
val registryChannel = "ForgeMultipart"
}