From d9ecf087adc91ff85c536fd7994104e7fd56d776 Mon Sep 17 00:00:00 2001 From: Algent Date: Wed, 2 Sep 2026 00:33:54 +0200 Subject: [PATCH] refactor: port corner microblock factory --- JAVA_MIGRATION.md | 9 +++ JAVA_MIGRATION_DIVERGENCES.md | 48 ++++++++++++ JAVA_MIGRATION_HANDOFF.md | 26 ++++--- JAVA_MIGRATION_MANUAL_CHECKS.md | 2 +- .../microblock/CornerMicroClass$.java | 66 ++++++++++++++++ .../microblock/CornerMicroClass.java | 76 +++++++++++++++++++ .../microblock/CornerMicroblock.scala | 53 ------------- .../microblock/CornerMicroblockTraits.scala | 13 ++++ .../microblock/CornerPlacement$.java | 23 ++++++ .../microblock/CornerPlacement.java | 30 ++++++++ 10 files changed, 283 insertions(+), 63 deletions(-) create mode 100644 src/main/scala/codechicken/microblock/CornerMicroClass$.java create mode 100644 src/main/scala/codechicken/microblock/CornerMicroClass.java delete mode 100644 src/main/scala/codechicken/microblock/CornerMicroblock.scala create mode 100644 src/main/scala/codechicken/microblock/CornerMicroblockTraits.scala create mode 100644 src/main/scala/codechicken/microblock/CornerPlacement$.java create mode 100644 src/main/scala/codechicken/microblock/CornerPlacement.java diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index e7cad86..4a01ffe 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -1164,3 +1164,12 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec - A clean build passes all 246 plain-JVM tests and the Java 8 Forge server passes all 104 tests. Recompiled Scala must spell the Java array getter as `FaceMicroClass.aBounds()(index)`; existing binaries still link to the unchanged `aBounds(): Cuboid6[]` descriptor. `microblock/CornerMicroblock.scala` is next. +- Characterized the corner factory, placement singleton and generated trait against untouched Scala. Two plain-JVM + cases freeze all six retained public surfaces and all 48 slot/side placement mappings; one Forge case freezes + factory metadata, all 56 populated bounds and generated shape/slot behavior. +- Ported the four concrete facade/companion types directly to Java while retaining `CornerMicroblock` in + `CornerMicroblockTraits.scala`. ProjectRed's load-bearing `CornerMicroClass$.MODULE$.getClassId()` linkage and every + callable public descriptor remain exact; the two private Scala bounds-initializer closures disappear. +- A clean build passes all 248 plain-JVM tests and the Java 8 Forge server passes all 105 tests. Recompiled Scala must + spell the Java array getter as `CornerMicroClass.aBounds()(index)`; existing binaries still link unchanged. + `microblock/EdgeMicroblock.scala` is next as one Edge/Post source unit. diff --git a/JAVA_MIGRATION_DIVERGENCES.md b/JAVA_MIGRATION_DIVERGENCES.md index ac14007..de0c794 100644 --- a/JAVA_MIGRATION_DIVERGENCES.md +++ b/JAVA_MIGRATION_DIVERGENCES.md @@ -2797,3 +2797,51 @@ The eight supported runtime types remain. - Raw `javap` comparison confirms identical callable public names/descriptors for both facades, both companions, both traits and both `$class` helpers. - Actual face rendering and highlight geometry remain covered by the existing manual checklist entries. + +## 2026-09-02 — CornerMicroblock factory Java port + +The corner placement and factory facades/companions are now Java. The generated `CornerMicroblock` trait remains +Scala in `CornerMicroblockTraits.scala`, avoiding any generator expansion for a port that only needs concrete state. + +### Observable behavior + +No known runtime divergence. Placement still toggles the corner bit for the clicked axis with +`1 << (side >> 1)`, uses the same corner grid, and inherits the same always-true expand/sneak defaults. Factory name, +item slot, resistance and trait classes remain unchanged. + +The bounds table remains a mutable 256-entry array. The same 56 entries (`size` 1 through 7, `corner` 0 through 7) +are populated with the same centre-relative axis mirrors; all other entries remain null. Generated parts still encode +`slot - 7` in the shape nibble, recover the slot with `getShape + 7`, and return the table entry by identity. + +### ABI and reflection compatibility + +All six retained facade, companion, trait and `$class` types keep their hierarchy and callable public +names/descriptors. ProjectRed's load-bearing `CornerMicroClass$.MODULE$.getClassId()` call is unchanged, as are the +static facade and both singleton fields. The stable `"mcr_cnr"` ID used by BuildCraft and MatterManipulator is also +unchanged. + +Recompiled Scala source must write `CornerMicroClass.aBounds()(index)` rather than +`CornerMicroClass.aBounds(index)`, because the Java facade does not carry Scala property metadata. This is source-only; +existing bytecode still performs the unchanged zero-argument getter followed by an array load. The companion's +`baseTrait` generic signature is necessarily `Class` in Java rather than Scala's +`Class`; its raw JVM descriptor remains `()Ljava/lang/Class;`, and the static facade retains the +consumer-facing `Class` signature. + +Accepted classfile-only differences also include the ordinary Java companion class-initializer flag and removed +Scala signature/marker attributes. + +### Compiler artifacts + +`CornerMicroClass$$anonfun$1` and `CornerMicroClass$$anonfun$1$$anonfun$apply$mcVI$sp$1` disappear. Direct nested Java +loops need neither private bounds-initializer closure, and the downstream inventory contains no reference to them. +The six supported runtime types remain. + +### Validation + +- `CornerMicroblockCharacterizationTest`: 2 plain-JVM tests, unchanged from the Scala baseline. +- Clean complete plain-JVM suite: 248 tests, 0 failures, 0 errors. +- Java 8 Forge dedicated-server suite: 105 tests, 0 failures, 0 errors, including all 56 bounds and a runtime-generated + corner part. +- Raw `javap` comparison confirms identical callable public names/descriptors for both facades, both companions, the + trait and its `$class` helper. +- Actual corner rendering and highlight geometry remain covered by the existing manual checklist entries. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index 915b343..06464ee 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`. 138 commits including the API-cleanup plan and separate characterization and -port commits through the face-microblock factory. +Branch: `algent/java`. Base: `master`. 140 commits including the API-cleanup plan and separate characterization and +port commits through the corner-microblock factory. ## The one rule that matters @@ -67,7 +67,7 @@ awk -F'"' '/ ... }` needs an explicit `AbstractFunction1`. A Java static array getter -also loses Scala property/indexing composition: `FaceMicroClass.aBounds(index)` becomes -`FaceMicroClass.aBounds()(index)` when recompiling, while existing bytecode remains compatible. +also loses Scala property/indexing composition: `FaceMicroClass.aBounds(index)` and +`CornerMicroClass.aBounds(index)` need an extra empty argument list before the index when recompiling, while existing +bytecode remains compatible. **A companion object can be load-bearing without a single bytecode reference.** The inventory's 17 `MODULE$` list is not the whole test — check the reflective string constants too. `MultipartHelper$` is in neither the `MODULE$` list nor @@ -272,7 +273,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. -171 Java files, 16 Scala files, ~3,111 Scala lines left (non-blank; that is the metric this figure has always used). +175 Java files, 16 Scala files, ~3,083 Scala lines left (non-blank; that is the metric this figure has always used). ## What is left, and in what order @@ -499,9 +500,16 @@ bounds, factory identity and generated `FaceMicroblock`/`TFacePart` behavior. `F trait and `$class` surfaces. Existing binaries retain the same `aBounds(): Cuboid6[]` call; recompiled Scala source must use `FaceMicroClass.aBounds()(index)`. Only the two private bounds-initializer closures disappear. -**Medium.** `CornerMicroblock.scala` is next. Apply the same narrow split: characterize its factory/facade, placement -singleton, 56 populated bounds and generated trait, then port the concrete/singleton code while retaining the trait -unless an exact Java representation is proven first. Do not combine it with another shape family. +The corner factory and placement singleton are now four Java facade/companion types. Two plain-JVM cases freeze all +six retained surfaces and all placement mappings; one Forge case freezes the 256-entry table's exact 56 populated +bounds, factory identity and generated shape/slot behavior. `CornerMicroblock` deliberately remains Scala in +`CornerMicroblockTraits.scala`, preserving its exact generated trait and `$class` surfaces. ProjectRed's load-bearing +`CornerMicroClass$.MODULE$.getClassId()` call remains exact. Existing binaries retain the same bounds getter; only the +two private bounds-initializer closures disappear. + +**Medium/high.** `EdgeMicroblock.scala` is next. Treat its Edge and Post families as one source unit: characterize both +factories, placement/custom-post behavior, both bounds tables and all three generated traits before splitting concrete +facade/companion code from retained Scala traits. Do not combine it with `TMicroOcclusion` or generator work. **Phase 5 is complete.** There are no Scala files left in `multipart/scalatraits/`. The client pair required the first narrow generator relaxation: Java-trait parent linearization, explicit field-accessor recognition, and exclusion of diff --git a/JAVA_MIGRATION_MANUAL_CHECKS.md b/JAVA_MIGRATION_MANUAL_CHECKS.md index 6f67867..20dbb05 100644 --- a/JAVA_MIGRATION_MANUAL_CHECKS.md +++ b/JAVA_MIGRATION_MANUAL_CHECKS.md @@ -47,7 +47,7 @@ below its table. | Done | Check | Expected | From | | --- | --- | --- | --- | -| [ ] | Load the pack with ProjRed installed and place illumar lamp microblocks | The lamps generate, use the correct face bounds, render and light correctly | `MicroblockGenerator.registerTrait` Scala trait path / `FaceMicroClass.aBounds` facade | +| [ ] | Load the pack with ProjRed installed and place face and corner illumar lamp microblocks | The lamps generate, use the correct bounds, render and light correctly | `MicroblockGenerator.registerTrait` Scala trait path / `FaceMicroClass` and `CornerMicroClass` facades | | [ ] | Place and break OpenComputers, ProjectBlue and AE2 parts | No `NoSuchMethodError` or `AbstractMethodError` in the log | retained `$class` bridges | | [ ] | Load and render a schematic containing an ordered mixed multipart tile | Every part appears in the preview in the saved order; the integration does not silently disable itself | Schematica private registry-map reflection, `MicroblockClass.create`, and tile NBT reconstruction | | [ ] | Open a GuideNH scene containing a multipart tile and export its part/material data | The preview, material data and part statistics are complete | companion reflection, `MicroblockGenerator$.create`, `Microblock.microClass/material/shape`, `partList_$eq`, and `BlockMicroMaterial` mixin fields | diff --git a/src/main/scala/codechicken/microblock/CornerMicroClass$.java b/src/main/scala/codechicken/microblock/CornerMicroClass$.java new file mode 100644 index 0000000..d727cbc --- /dev/null +++ b/src/main/scala/codechicken/microblock/CornerMicroClass$.java @@ -0,0 +1,66 @@ +package codechicken.microblock; + +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Scale; +import codechicken.lib.vec.Transformation; +import codechicken.lib.vec.Vector3; + +public final class CornerMicroClass$ extends CommonMicroClass { + + public static final CornerMicroClass$ MODULE$ = new CornerMicroClass$(); + + private Cuboid6[] aBounds = new Cuboid6[256]; + + private CornerMicroClass$() { + for (int corner = 0; corner < 8; corner++) { + int scaleX = (corner & 4) == 0 ? 1 : -1; + int scaleY = (corner & 1) == 0 ? 1 : -1; + int scaleZ = (corner & 2) == 0 ? 1 : -1; + Transformation transform = new Scale(new Vector3(scaleX, scaleY, scaleZ)).at(Vector3.center); + + for (int size = 1; size < 8; size++) { + double distance = size / 8D; + aBounds[size << 4 | corner] = new Cuboid6(0, 0, 0, distance, distance, distance).apply(transform); + } + } + } + + public Cuboid6[] aBounds() { + return aBounds; + } + + public void aBounds_$eq(Cuboid6[] bounds) { + aBounds = bounds; + } + + @Override + public String getName() { + return "mcr_cnr"; + } + + @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Class baseTrait() { + return (Class) CornerMicroblock.class; + } + + @Override + public Class clientTrait() { + return CommonMicroblockClient.class; + } + + @Override + public int itemSlot() { + return 7; + } + + @Override + public CornerPlacement$ placementProperties() { + return CornerPlacement$.MODULE$; + } + + @Override + public float getResistanceFactor() { + return 1; + } +} diff --git a/src/main/scala/codechicken/microblock/CornerMicroClass.java b/src/main/scala/codechicken/microblock/CornerMicroClass.java new file mode 100644 index 0000000..a3ba3ac --- /dev/null +++ b/src/main/scala/codechicken/microblock/CornerMicroClass.java @@ -0,0 +1,76 @@ +package codechicken.microblock; + +import net.minecraft.nbt.NBTTagCompound; + +import codechicken.lib.data.MCDataInput; +import codechicken.lib.vec.Cuboid6; + +public final class CornerMicroClass { + + private CornerMicroClass() {} + + public static int baseTraitId() { + return CornerMicroClass$.MODULE$.baseTraitId(); + } + + public static int clientTraitId() { + return CornerMicroClass$.MODULE$.clientTraitId(); + } + + public static void register() { + CornerMicroClass$.MODULE$.register(); + } + + public static Microblock create(boolean client, int material) { + return CornerMicroClass$.MODULE$.create(client, material); + } + + public static Microblock createPart(String name, MCDataInput packet) { + return CornerMicroClass$.MODULE$.createPart(name, packet); + } + + public static Microblock createPart(String name, NBTTagCompound nbt) { + return CornerMicroClass$.MODULE$.createPart(name, nbt); + } + + public static int getClassId() { + return CornerMicroClass$.MODULE$.getClassId(); + } + + public static void register(int id) { + CornerMicroClass$.MODULE$.register(id); + } + + public static Cuboid6[] aBounds() { + return CornerMicroClass$.MODULE$.aBounds(); + } + + public static void aBounds_$eq(Cuboid6[] bounds) { + CornerMicroClass$.MODULE$.aBounds_$eq(bounds); + } + + public static String getName() { + return CornerMicroClass$.MODULE$.getName(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static Class baseTrait() { + return (Class) CornerMicroClass$.MODULE$.baseTrait(); + } + + public static Class clientTrait() { + return CornerMicroClass$.MODULE$.clientTrait(); + } + + public static int itemSlot() { + return CornerMicroClass$.MODULE$.itemSlot(); + } + + public static CornerPlacement$ placementProperties() { + return CornerMicroClass$.MODULE$.placementProperties(); + } + + public static float getResistanceFactor() { + return CornerMicroClass$.MODULE$.getResistanceFactor(); + } +} diff --git a/src/main/scala/codechicken/microblock/CornerMicroblock.scala b/src/main/scala/codechicken/microblock/CornerMicroblock.scala deleted file mode 100644 index 46f5a8e..0000000 --- a/src/main/scala/codechicken/microblock/CornerMicroblock.scala +++ /dev/null @@ -1,53 +0,0 @@ -package codechicken.microblock - -import codechicken.lib.vec.Cuboid6 -import codechicken.lib.vec.Scale -import codechicken.lib.vec.Vector3 -import Vector3._ - -object CornerPlacement extends PlacementProperties { - def microClass = CornerMicroClass - - def placementGrid = CornerPlacementGrid$.MODULE$ - - def opposite(slot: Int, side: Int) = ((slot - 7) ^ (1 << (side >> 1))) + 7 -} - -object CornerMicroClass extends CommonMicroClass { - var aBounds: Array[Cuboid6] = new Array(256) - - for (s <- 0 until 8) { - val rx = if ((s & 4) != 0) -1 else 1 - val ry = if ((s & 1) != 0) -1 else 1 - val rz = if ((s & 2) != 0) -1 else 1 - val transform = new Scale(new Vector3(rx, ry, rz)).at(center) - - for (t <- 1 until 8) { - val d = t / 8d - aBounds(t << 4 | s) = new Cuboid6(0, 0, 0, d, d, d).apply(transform) - } - } - - def getName = "mcr_cnr" - - def baseTrait = classOf[CornerMicroblock] - def clientTrait = classOf[CommonMicroblockClient] - - override def itemSlot = 7 - - def placementProperties = CornerPlacement - - def getResistanceFactor = 1 -} - -trait CornerMicroblock extends CommonMicroblock { - override def setShape(size: Int, slot: Int) = shape_$eq( - (size << 4 | (slot - 7)).toByte - ) - - def microClass = CornerMicroClass - - def getBounds = CornerMicroClass.aBounds(shape) - - override def getSlot = getShape + 7 -} diff --git a/src/main/scala/codechicken/microblock/CornerMicroblockTraits.scala b/src/main/scala/codechicken/microblock/CornerMicroblockTraits.scala new file mode 100644 index 0000000..4e5649f --- /dev/null +++ b/src/main/scala/codechicken/microblock/CornerMicroblockTraits.scala @@ -0,0 +1,13 @@ +package codechicken.microblock + +trait CornerMicroblock extends CommonMicroblock { + override def setShape(size: Int, slot: Int) = shape_$eq( + (size << 4 | (slot - 7)).toByte + ) + + def microClass = CornerMicroClass$.MODULE$ + + def getBounds = CornerMicroClass.aBounds()(shape) + + override def getSlot = getShape + 7 +} diff --git a/src/main/scala/codechicken/microblock/CornerPlacement$.java b/src/main/scala/codechicken/microblock/CornerPlacement$.java new file mode 100644 index 0000000..ba59a59 --- /dev/null +++ b/src/main/scala/codechicken/microblock/CornerPlacement$.java @@ -0,0 +1,23 @@ +package codechicken.microblock; + +public final class CornerPlacement$ extends PlacementProperties { + + public static final CornerPlacement$ MODULE$ = new CornerPlacement$(); + + private CornerPlacement$() {} + + @Override + public CornerMicroClass$ microClass() { + return CornerMicroClass$.MODULE$; + } + + @Override + public CornerPlacementGrid$ placementGrid() { + return CornerPlacementGrid$.MODULE$; + } + + @Override + public int opposite(int slot, int side) { + return ((slot - 7) ^ (1 << (side >> 1))) + 7; + } +} diff --git a/src/main/scala/codechicken/microblock/CornerPlacement.java b/src/main/scala/codechicken/microblock/CornerPlacement.java new file mode 100644 index 0000000..303f899 --- /dev/null +++ b/src/main/scala/codechicken/microblock/CornerPlacement.java @@ -0,0 +1,30 @@ +package codechicken.microblock; + +public final class CornerPlacement { + + private CornerPlacement() {} + + public static ExecutablePlacement customPlacement(MicroblockPlacement placement) { + return CornerPlacement$.MODULE$.customPlacement(placement); + } + + public static CornerMicroClass$ microClass() { + return CornerPlacement$.MODULE$.microClass(); + } + + public static CornerPlacementGrid$ placementGrid() { + return CornerPlacement$.MODULE$.placementGrid(); + } + + public static int opposite(int slot, int side) { + return CornerPlacement$.MODULE$.opposite(slot, side); + } + + public static boolean expand(int slot, int side) { + return CornerPlacement$.MODULE$.expand(slot, side); + } + + public static boolean sneakOpposite(int slot, int side) { + return CornerPlacement$.MODULE$.sneakOpposite(slot, side); + } +}