From 7c4c87ec083481f6b9fe883230b0e70d7f565caf Mon Sep 17 00:00:00 2001 From: Algent Date: Thu, 3 Sep 2026 22:13:24 +0200 Subject: [PATCH] refactor: port edge microblock logic to Java Retain Scala trait metadata and helper bridges for generated mixins. --- JAVA_MIGRATION.md | 11 +++---- JAVA_MIGRATION_CONSUMER_AUDIT.md | 4 ++- JAVA_MIGRATION_HANDOFF.md | 30 ++++++++++--------- docs/migration/HISTORY.md | 20 +++++++++++++ .../microblock/EdgeMicroblockTraitLogic.java | 21 +++++++++++++ .../microblock/EdgeMicroblockTraits.scala | 10 +++---- 6 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 src/main/scala/codechicken/microblock/EdgeMicroblockTraitLogic.java diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index a302166..17c9260 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -26,10 +26,10 @@ No trustworthy tool will produce a maintainable Java port automatically. A decom 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. 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, +face, corner and edge traits 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 +`PostMicroblock` in `microblock/EdgeMicroblockTraits.scala`, followed separately by its client trait. 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 @@ -366,10 +366,11 @@ 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/corner microblock trait behavior are Java. Three files +Status: core code, factories, ordinary helpers and common/face/corner/edge 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. +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. - [ ] Convert the central tile, part, registry, placement, rendering, networking, scheduler, and microblock code in dependency order. diff --git a/JAVA_MIGRATION_CONSUMER_AUDIT.md b/JAVA_MIGRATION_CONSUMER_AUDIT.md index 2ee9c80..a899673 100644 --- a/JAVA_MIGRATION_CONSUMER_AUDIT.md +++ b/JAVA_MIGRATION_CONSUMER_AUDIT.md @@ -517,7 +517,9 @@ and checks every emitted face for all masks/slots, including material reuse and opaque draws. Its Forge companion pins generated face bounds and solidity. The `FaceMicroblockClient` interface 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. +name contracts. The edge-trait tests cover the corresponding fifteen-slot mapping, all 84 supported bounds, +generated NBT/descriptions and the inherited `TEdgePart.conductsRedstone` default used by redstone tile dispatch. +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 bec2831..ff697e4 100644 --- a/JAVA_MIGRATION_HANDOFF.md +++ b/JAVA_MIGRATION_HANDOFF.md @@ -16,21 +16,22 @@ migration checkout; `codex/tile-compatibility-fixes` was deleted after its fixes ## Current state and next target -**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. +**351 plain-JVM tests and 222 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **218 Java +files and 9 Scala files / 1,144 nonblank Scala lines**. The packaged inventory has 441 classes. -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. +Latest bounded target: `EdgeMicroblock` in `EdgeMicroblockTraits.scala` delegates shape packing, bounds lookup and +slot decoding to `EdgeMicroblockTraitLogic.java`. Its Scala declaration, inheritance metadata, `$class` bridge, +singleton accessor and inherited `TEdgePart` conduction remain. Characterization was committed first as `5e020e5`, +with a frozen Scala implementor that observes virtual shape access. Tests cover the fifteen-slot offset, byte +truncation/integer overflow, all 84 supported edge bounds, live/null array replacement, signed-index failures and +generated NBT/description round-trips. Clean verification after stopping Gradle matches all 440 original class/member +APIs, all 17 ScalaSignature payloads, 3,696 non-target method bodies and all 116 generated dump names/hashes. Only the +package-private helper is added. Local evidence is in `run/migration-edge-trait-reference/`; `clean` preserves it. -**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. +**Next: port `PostMicroblock` in `microblock/EdgeMicroblockTraits.scala`.** Characterize its axis/shape bounds, +occlusion boxes and special-case ordering (posts, aligned face covers, normal box test and superclass fallback), +item/class identity, torch support and generated state/dispatch before conversion. Leave `PostMicroblockClient` +rendering and lifecycle behavior for a subsequent bounded target. Retain the Scala declarations where inheritance metadata is required, the external ProjectRed Scala-trait fixture and the ScalaSignature model bridges; compiler changes stay separate. @@ -42,7 +43,8 @@ Remaining Scala units: | `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`, `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 | +| `microblock/EdgeMicroblockTraits.scala` | Retained `EdgeMicroblock` shell over Java behavior; post/server and post/client implementations remain | +| `microblock/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 9051669..8151006 100644 --- a/docs/migration/HISTORY.md +++ b/docs/migration/HISTORY.md @@ -1099,3 +1099,23 @@ differences belong in the [divergence ledger](../../JAVA_MIGRATION_DIVERGENCES.m 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. + +### 2026-09-03 — Edge microblock trait implementation + +- Committed three JVM and three Forge characterization tests first as `5e020e5`. A frozen Scala 2.11.5 implementor, + compiled under Java 8 against the untouched jar, pins virtual shape access, byte truncation/integer overflow and the + fifteen-slot offset. Generated tests cover all 84 edge bounds and NBT/description round-trips, singleton/type + identity, inherited redstone non-conduction, signed-index failures and live/null/replaced bounds arrays. +- Moved only `EdgeMicroblock` shape packing, bounds lookup and slot decoding to package-private + `EdgeMicroblockTraitLogic.java`. Retained the Scala declaration, inheritance metadata, `$class` bridge, singleton + accessor and `TEdgePart` default. Both post traits in the same file are untouched. No compiler algorithm or existing + behavior changed; no new divergence entry is needed. +- Saved the reference jar/source, reports and 116 generated dumps in ignored `run/migration-edge-trait-reference/`. + Clean verification preserves all 440 original class/member APIs, all 17 ScalaSignature payloads and 3,696 non-target + method bodies. All 116 generated dump names and hashes match; only the helper raises the inventory to 441 classes. + Formatting, checkstyle, build and Forge pass normally and after stopping Gradle for a clean rebuild: 351 JVM / + 222 Forge tests, zero failures/errors/skips. The forced Scala-compilation guard and all five packaged `@Mod` versions + remain verified. Sources total 218 Java files and 9 Scala files / 1,144 nonblank Scala lines. +- Next: `PostMicroblock` in the same file; characterize its occlusion ordering, axis bounds, item identity, torch + support and generated state before extraction. `PostMicroblockClient` follows separately. The existing manual + Stone Strip / ProjectRed Red Alloy Wire and illuminated-strip checks cover the remaining client/full-pack gate. diff --git a/src/main/scala/codechicken/microblock/EdgeMicroblockTraitLogic.java b/src/main/scala/codechicken/microblock/EdgeMicroblockTraitLogic.java new file mode 100644 index 0000000..bf75c33 --- /dev/null +++ b/src/main/scala/codechicken/microblock/EdgeMicroblockTraitLogic.java @@ -0,0 +1,21 @@ +package codechicken.microblock; + +import codechicken.lib.vec.Cuboid6; + +/** Edge behavior behind the retained Scala inheritance metadata and helper bridges. */ +final class EdgeMicroblockTraitLogic { + + private EdgeMicroblockTraitLogic() {} + + static void setShape(EdgeMicroblock part, int size, int slot) { + ((Microblock) part).shape_$eq((byte) (size << 4 | (slot - 15))); + } + + static Cuboid6 getBounds(EdgeMicroblock part) { + return EdgeMicroClass.aBounds()[((Microblock) part).shape()]; + } + + static int getSlot(EdgeMicroblock part) { + return ((Microblock) part).getShape() + 15; + } +} diff --git a/src/main/scala/codechicken/microblock/EdgeMicroblockTraits.scala b/src/main/scala/codechicken/microblock/EdgeMicroblockTraits.scala index c917edc..52a1fda 100644 --- a/src/main/scala/codechicken/microblock/EdgeMicroblockTraits.scala +++ b/src/main/scala/codechicken/microblock/EdgeMicroblockTraits.scala @@ -11,16 +11,16 @@ import codechicken.multipart.{ } import scala.collection.JavaConversions._ +// Retain Scala inheritance metadata and helper bridges for generated and external mixins. trait EdgeMicroblock extends CommonMicroblock with TEdgePart { - override def setShape(size: Int, slot: Int) = shape_$eq( - (size << 4 | (slot - 15)).toByte - ) + override def setShape(size: Int, slot: Int) = + EdgeMicroblockTraitLogic.setShape(this, size, slot) def microClass = EdgeMicroClass$.MODULE$ - def getBounds = EdgeMicroClass.aBounds()(shape) + def getBounds = EdgeMicroblockTraitLogic.getBounds(this) - override def getSlot = getShape + 15 + override def getSlot = EdgeMicroblockTraitLogic.getSlot(this) } trait PostMicroblockClient extends PostMicroblock with MicroblockClient {