From 33e0bc2ad34e37bf7fa98a0e9399cdb5f0f4d1ef Mon Sep 17 00:00:00 2001 From: Algent Date: Thu, 3 Sep 2026 22:01:12 +0200 Subject: [PATCH] refactor: port corner microblock logic to Java Retain Scala trait declarations and helper bridges for inherited mixin registration and existing consumers. --- JAVA_MIGRATION.md | 19 +++++----- JAVA_MIGRATION_CONSUMER_AUDIT.md | 5 +-- JAVA_MIGRATION_HANDOFF.md | 35 +++++++++---------- docs/migration/HISTORY.md | 19 ++++++++++ .../CornerMicroblockTraitLogic.java | 21 +++++++++++ .../microblock/CornerMicroblockTraits.scala | 10 +++--- 6 files changed, 75 insertions(+), 34 deletions(-) create mode 100644 src/main/scala/codechicken/microblock/CornerMicroblockTraitLogic.java diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index 09c486d..a302166 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -24,12 +24,13 @@ No trustworthy tool will produce a maintainable Java port automatically. A decom ## Current status Work continues on `algent/java`. The low-coupling queue, core part/tile types, registries, handlers, factories, -placement/render helpers, both generators and all built-in tile traits are Java. Four generated microblock trait -implementations and the compiler/signature/analyser compatibility shells remain Scala. `MicroblockTraits.scala` and -`FaceMicroblockTraits.scala` retain inheritance/bridge declarations over Java behavior. Composite generation, -Java-trait rewriting and compiler startup also delegate to Java helpers. Abstract Java mixins and Java-path side-only filtering are complete; -multiple Scala-trait inheritance still needs its metadata. The next bounded target is the implementation in -`microblock/CornerMicroblockTraits.scala`. Retain the ScalaSignature path-dependent model bridges. +placement/render helpers, both generators and all built-in tile traits are Java. Three files still contain generated +microblock implementations in Scala, alongside the compiler/signature/analyser compatibility shells. The common, +face and corner trait files retain inheritance/bridge declarations over Java behavior. Composite generation, +Java-trait rewriting and compiler startup also delegate to Java helpers. Abstract Java mixins and Java-path side-only +filtering are complete; multiple Scala-trait inheritance still needs its metadata. The next bounded target is +`EdgeMicroblock` in `microblock/EdgeMicroblockTraits.scala`, followed separately by the post traits. Retain the +ScalaSignature path-dependent model bridges. Start with [JAVA_MIGRATION_HANDOFF.md](JAVA_MIGRATION_HANDOFF.md) for the exact source/test baseline, workflow and Java-source limitations. Read both the [ABI inventory](JAVA_MIGRATION_ABI_INVENTORY.md) and @@ -365,9 +366,9 @@ cache remain reference-identical; pass-through-interface coverage remains green. ### Phase 6 — Convert multipart core and microblocks -Status: core code, factories, ordinary helpers and common/face microblock trait behavior are Java. Four generated trait -implementations remain. Extract their behavior while retaining Scala declarations where multiple-trait inheritance -still needs signature metadata; abstract Java mixins and side filtering alone do not replace that metadata. The +Status: core code, factories, ordinary helpers and common/face/corner microblock trait behavior are Java. Three files +still contain generated trait implementations. Extract their behavior while retaining Scala declarations where +multiple-trait inheritance still needs signature metadata; abstract Java mixins and side filtering alone do not replace that metadata. The following gates continue to apply to those remaining units; completed per-type evidence is in the history. - [ ] Add characterization coverage for each subsystem immediately before its conversion. diff --git a/JAVA_MIGRATION_CONSUMER_AUDIT.md b/JAVA_MIGRATION_CONSUMER_AUDIT.md index 79450f3..2ee9c80 100644 --- a/JAVA_MIGRATION_CONSUMER_AUDIT.md +++ b/JAVA_MIGRATION_CONSUMER_AUDIT.md @@ -515,8 +515,9 @@ covers generated common microblocks; the runtime interfaces used by Extra Utilit remain intact. `FaceMicroblockTraitsCharacterizationTest` additionally executes a frozen Scala face-client forwarder and checks every emitted face for all masks/slots, including material reuse and repeated virtual slot lookup between opaque draws. Its Forge companion pins generated face bounds and solidity. The `FaceMicroblockClient` interface -tested by Extra Utilities' connected-texture renderer remains intact. Full downstream mixed tiles and client-side -selection remain Phase 7 integration cases. +tested by Extra Utilities' connected-texture renderer remains intact. The corner-trait tests add a frozen Scala +implementor for virtual shape access, generated geometry and NBT/description checks for the packed shape and material +name contracts. Full downstream mixed tiles and client-side selection remain Phase 7 integration cases. With these gates, the source audit is actionable: the port can simplify internals freely where no listed observation changes, while each externally observed behavior has a named consumer and a focused way to prove compatibility. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index 7e7ee43..bec2831 100644 --- a/JAVA_MIGRATION_HANDOFF.md +++ b/JAVA_MIGRATION_HANDOFF.md @@ -16,23 +16,23 @@ migration checkout; `codex/tile-compatibility-fixes` was deleted after its fixes ## Current state and next target -**345 plain-JVM tests and 216 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **216 Java -files and 9 Scala files / 1,144 nonblank Scala lines**. The packaged inventory has 439 classes. +**348 plain-JVM tests and 219 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **217 Java +files and 9 Scala files / 1,144 nonblank Scala lines**. The packaged inventory has 440 classes. -Latest bounded target: `FaceMicroblockTraits.scala` delegates rendering, bounds lookup and solidity to -`FaceMicroblockTraitLogic.java`. The two Scala trait declarations, inheritance metadata, `$class` bridges and existing -singleton accessor remain. Characterization was committed first as `dc845bc`, including a frozen Scala -face-client consumer. It pins exact emitted faces for all six slots/64 masks, negative passes, repeated slot lookup, -material caching and missing-material failure timing. Forge covers all 42 supported face shapes, signed-index errors, -null/live-replaced bounds and solidity dispatch. Clean verification after stopping Gradle matches all 438 original -class/member APIs, all 17 ScalaSignature payloads, 3,688 non-target method bodies and all 116 generated dump names/hashes. -Only the package-private helper is added. Local evidence is in `run/migration-face-traits-reference/`; `clean` -preserves this ignored directory. +Latest bounded target: `CornerMicroblockTraits.scala` delegates shape packing, bounds lookup and slot decoding to +`CornerMicroblockTraitLogic.java`. Its Scala declaration, inheritance metadata, `$class` bridge and singleton +accessor remain. Characterization was committed first as `82da452`, with a frozen Scala implementor that observes +virtual shape access. Tests cover the seven-slot offset, byte truncation/integer overflow, all 56 supported corner +bounds, live array replacement, signed-index failures and generated NBT/description round-trips. Clean verification +after stopping Gradle matches all 439 original class/member APIs, all 17 ScalaSignature payloads, 3,692 non-target +method bodies and all 116 generated dump names/hashes. Only the package-private helper is added. Local evidence is +in `run/migration-corner-traits-reference/`; `clean` preserves this ignored directory. -**Next: port the implementation in `microblock/CornerMicroblockTraits.scala`.** Characterize shape packing with the -seven-slot offset, signed byte/index behavior, live bounds lookup, class identity and generated dispatch before -conversion. Retain the Scala declarations where inheritance metadata is still required. Keep the external ProjectRed -Scala-trait fixture green and retain the ScalaSignature path-dependent model bridges; compiler changes stay separate. +**Next: port the `EdgeMicroblock` implementation in `microblock/EdgeMicroblockTraits.scala`.** Characterize its +fifteen-slot offset, signed shape/bounds behavior, class identity, inherited redstone-conduction default and generated +state/dispatch before conversion. Leave `PostMicroblock` and `PostMicroblockClient` for subsequent bounded targets. +Retain the Scala declarations where inheritance metadata is required, the external ProjectRed Scala-trait fixture +and the ScalaSignature model bridges; compiler changes stay separate. Remaining Scala units: @@ -41,9 +41,8 @@ Remaining Scala units: | `multipart/asm/ASMMixinCompiler.scala` | Retained nested models, construction callbacks and Scala entry-point shell | | `multipart/asm/ScalaSignature.scala` | Named models, primitive/erased bridges and five generic inner-construction branches | | `multipart/asm/StackAnalyser.scala` | Class/companion/model shell over Java `StackAnalyserLogic` | -| `microblock/MicroblockTraits.scala` | Three retained inheritance/bridge shells over Java implementation | -| `microblock/FaceMicroblockTraits.scala` | Two retained inheritance/bridge shells over Java implementation | -| `microblock/CornerMicroblockTraits.scala`, `EdgeMicroblockTraits.scala`, `HollowMicroblockTraits.scala`, `TMicroOcclusion.scala` | Generated trait implementations; port in dependency order while preserving inheritance metadata | +| `microblock/MicroblockTraits.scala`, `FaceMicroblockTraits.scala`, `CornerMicroblockTraits.scala` | Six retained inheritance/bridge shells over Java implementation | +| `microblock/EdgeMicroblockTraits.scala`, `HollowMicroblockTraits.scala`, `TMicroOcclusion.scala` | Generated trait implementations; port in bounded groups while preserving inheritance metadata | Both generators, both registries, core tile/part classes, ordinary microblock helpers/factories, handlers, networking, placement/render helpers and built-in tile traits are Java. The low-risk queue and immediate consumer gate are diff --git a/docs/migration/HISTORY.md b/docs/migration/HISTORY.md index b23bfe6..9051669 100644 --- a/docs/migration/HISTORY.md +++ b/docs/migration/HISTORY.md @@ -1080,3 +1080,22 @@ differences belong in the [divergence ledger](../../JAVA_MIGRATION_DIVERGENCES.m - Added a manual face-cover check using Stone, Glass and ProjectRed Inverted White Lamp materials. Headless tests prove per-face dispatch, not GPU output. Next: `microblock/CornerMicroblockTraits.scala` implementation, characterized before conversion. + +### 2026-09-03 — Corner microblock trait implementation + +- Committed three JVM and three Forge characterization tests first as `82da452`. A frozen Scala 2.11.5 corner + implementor, compiled under Java 8 against the untouched jar, pins the virtual shape setter/getter and seven-slot + offset, including byte truncation and out-of-range integer behavior. Forge covers all 56 supported corner bounds, + singleton/type identity, signed-index failures, null/live-replaced bounds arrays and generated NBT/description + round-trips for the packed shape and material name. +- Moved shape packing, bounds lookup and slot decoding to package-private `CornerMicroblockTraitLogic.java`. + The Scala trait declaration, inheritance metadata, `$class` helper and singleton accessor remain. No compiler + algorithm, validation or existing behavior changed; no new divergence entry is needed. +- Saved reference jar/source, reports and 116 generated dumps under ignored `run/migration-corner-traits-reference/`. + Clean verification preserves all 439 original class/member APIs, all 17 ScalaSignature payloads and 3,692 non-target + method bodies. All 116 generated names and SHA-256 hashes match; only the helper raises the inventory to 440 classes. + Formatting, checkstyle, build and Forge pass normally and after stopping Gradle for a clean rebuild: 348 JVM / + 219 Forge tests, zero failures/errors/skips. The forced Scala-compilation guard and all five packaged `@Mod` versions + remain verified. Sources total 217 Java files and 9 Scala files / 1,144 nonblank Scala lines. +- Next: `EdgeMicroblock` in `microblock/EdgeMicroblockTraits.scala`; characterize and port the post traits separately. + Client/GPU and full-pack validation remain on the existing manual checklist. diff --git a/src/main/scala/codechicken/microblock/CornerMicroblockTraitLogic.java b/src/main/scala/codechicken/microblock/CornerMicroblockTraitLogic.java new file mode 100644 index 0000000..cd8761c --- /dev/null +++ b/src/main/scala/codechicken/microblock/CornerMicroblockTraitLogic.java @@ -0,0 +1,21 @@ +package codechicken.microblock; + +import codechicken.lib.vec.Cuboid6; + +/** Corner behavior behind the retained Scala inheritance metadata and helper bridges. */ +final class CornerMicroblockTraitLogic { + + private CornerMicroblockTraitLogic() {} + + static void setShape(CornerMicroblock part, int size, int slot) { + ((Microblock) part).shape_$eq((byte) (size << 4 | (slot - 7))); + } + + static Cuboid6 getBounds(CornerMicroblock part) { + return CornerMicroClass.aBounds()[((Microblock) part).shape()]; + } + + static int getSlot(CornerMicroblock part) { + return ((Microblock) part).getShape() + 7; + } +} diff --git a/src/main/scala/codechicken/microblock/CornerMicroblockTraits.scala b/src/main/scala/codechicken/microblock/CornerMicroblockTraits.scala index 4e5649f..c4bc9bb 100644 --- a/src/main/scala/codechicken/microblock/CornerMicroblockTraits.scala +++ b/src/main/scala/codechicken/microblock/CornerMicroblockTraits.scala @@ -1,13 +1,13 @@ package codechicken.microblock +// Retain Scala inheritance metadata and helper bridges for generated and external mixins. trait CornerMicroblock extends CommonMicroblock { - override def setShape(size: Int, slot: Int) = shape_$eq( - (size << 4 | (slot - 7)).toByte - ) + override def setShape(size: Int, slot: Int) = + CornerMicroblockTraitLogic.setShape(this, size, slot) def microClass = CornerMicroClass$.MODULE$ - def getBounds = CornerMicroClass.aBounds()(shape) + def getBounds = CornerMicroblockTraitLogic.getBounds(this) - override def getSlot = getShape + 7 + override def getSlot = CornerMicroblockTraitLogic.getSlot(this) }