From 33510e74bd8fd5c29bdce7582d07027ff073a11f Mon Sep 17 00:00:00 2001 From: Algent Date: Wed, 2 Sep 2026 01:23:47 +0200 Subject: [PATCH] refactor: port hollow microblock factory --- JAVA_MIGRATION.md | 11 +++ JAVA_MIGRATION_DIVERGENCES.md | 57 ++++++++++++ JAVA_MIGRATION_HANDOFF.md | 21 +++-- JAVA_MIGRATION_MANUAL_CHECKS.md | 1 + .../microblock/HollowMicroClass$.java | 88 +++++++++++++++++++ .../microblock/HollowMicroClass.java | 85 ++++++++++++++++++ ...ock.scala => HollowMicroblockTraits.scala} | 54 +----------- .../microblock/HollowPlacement$.java | 33 +++++++ .../microblock/HollowPlacement.java | 39 ++++++++ 9 files changed, 332 insertions(+), 57 deletions(-) create mode 100644 src/main/scala/codechicken/microblock/HollowMicroClass$.java create mode 100644 src/main/scala/codechicken/microblock/HollowMicroClass.java rename src/main/scala/codechicken/microblock/{HollowMicroblock.scala => HollowMicroblockTraits.scala} (86%) create mode 100644 src/main/scala/codechicken/microblock/HollowPlacement$.java create mode 100644 src/main/scala/codechicken/microblock/HollowPlacement.java diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index eb2ca18..bd7cf0e 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -1182,3 +1182,14 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec - A clean build passes all 250 plain-JVM tests and the Java 8 Forge server passes all 108 tests. All callable public descriptors match the reference; only four private bounds-initializer closures disappear. `microblock/HollowMicroblock.scala` is next. +- Characterized the Hollow unit against untouched Scala. Two plain-JVM cases freeze all nine retained public + surfaces, including the source-visible nested placement-grid relationship and both generated traits. Two Forge + cases freeze both 42-entry tables, generated server behavior, every face, connected hollow sizes 1 through 11, + and all collision, occlusion and subpart geometry. +- Ported the four concrete placement/factory facade and companion sources directly to Java while retaining + `HollowMicroblock` and the large stateful `HollowMicroblockClient` in `HollowMicroblockTraits.scala`. The nested + `HollowPlacement.HollowPlacementGrid$` remains a real public static nested class rather than merely keeping its + binary name. +- A clean build passes all 252 plain-JVM tests and the Java 8 Forge server passes all 110 tests. All nine supported + public surfaces match the reference; both retained trait helpers and all seven trait closures are bytecode-identical. + Only three private factory table-initializer closures disappear. `microblock/TMicroOcclusion.scala` is next. diff --git a/JAVA_MIGRATION_DIVERGENCES.md b/JAVA_MIGRATION_DIVERGENCES.md index facca1c..3f2613b 100644 --- a/JAVA_MIGRATION_DIVERGENCES.md +++ b/JAVA_MIGRATION_DIVERGENCES.md @@ -2897,3 +2897,60 @@ Direct nested Java loops need none of them, and the downstream inventory contain - Raw `javap` comparison confirms identical callable public names/descriptors for all twelve supported types and an exact private-surface match for the retained Post client traversal closure. - Actual Edge/Post rendering and neighbour-driven Post shrink geometry remain on the manual checklist. + +## 2026-09-02 — Hollow microblock factory Java port + +The Hollow placement and factory facades/companions are now Java. `HollowMicroblock` and the stateful +`HollowMicroblockClient` remain Scala in `HollowMicroblockTraits.scala`; their generated multiple-inheritance, +mutable render state and super-accessor surfaces require no generator change for this concrete port. + +### Observable behavior + +No known runtime divergence. Placement still uses the nested `FaceEdgeGrid` at exactly `3 / 8D`, flips face slots +with `slot ^ 1`, and expands only when the selected slot is opposite the clicked side. Factory name, item slot, +resistance and both trait classes remain unchanged. + +The partial-occlusion and central-occlusion tables remain mutable 256-entry arrays with the same 42 populated shapes +(`size` 1 through 7 over six faces). Every partial entry remains a Scala immutable sequence of the same four +transformed rim boxes. Generated Hollow parts retain Face bounds, normal and partial occlusion, complete-occlusion +permission, false face solidity and the `0x10` redstone conduction map. + +With no tile or no compatible centre part, the opening remains eight pixels. An `ISidedHollowConnect` centre part +still supplies the face-specific opening size. All collision, occlusion and raytrace subpart boxes retain their exact +orientation and dimensions for all six faces and supported connector sizes 1 through 11. The client render, +breaking-overlay and highlight implementations remain the original Scala bytecode; actual OpenGL output stays on the +manual checklist. + +### ABI and reflection compatibility + +All nine supported facade, companion, nested-grid, trait and `$class` types keep their hierarchy and callable public +names/descriptors. `HollowPlacement.HollowPlacementGrid$` remains a real public static nested class in the +`InnerClasses` attribute as well as retaining the binary name +`codechicken.microblock.HollowPlacement$HollowPlacementGrid$`. This preserves both Java source and existing binary +linkage. + +ProjectRed's static `HollowMicroClass.getClassId()` call and `HollowMicroblock` type checks remain exact. Extra +Utilities' `HollowMicroblockClient` type checks remain exact. The stable `"mcr_hllw"` ID used by BuildCraft and +MatterManipulator is unchanged. + +The companion's `baseTrait` generic signature necessarily widens to `Class` in Java rather +than Scala's `Class`; its raw descriptor remains `()Ljava/lang/Class;`, while the static facade +retains the consumer-facing trait type. Accepted classfile-only differences also include ordinary Java companion +class-initializer flags and removed Scala signature/marker attributes from the concrete Java types. + +### Compiler artifacts + +`HollowMicroClass$$anonfun$1` and its two nested bounds-table initializer closures disappear. Direct Java loops need +none of them, and the downstream inventory contains no references. Both retained trait helpers and all seven private +trait closures (`getCollisionBoxes`, `getSubParts`, `drawBreaking`, and the four render callbacks) have bytecode- +identical `javap -c -p -s` output after the port. + +### Validation + +- `HollowMicroblockCharacterizationTest`: 2 plain-JVM tests, unchanged from the Scala baseline. +- Clean complete plain-JVM suite: 252 tests, 0 failures, 0 errors. +- Java 8 Forge dedicated-server suite: 110 tests, 0 failures, 0 errors, including both 42-entry tables, a generated + Hollow part and every side across connected opening sizes 1 through 11. +- Raw `javap` comparison confirms identical callable public names/descriptors for all nine supported types, the exact + nested-grid relationship, and bytecode-identical retained trait helpers and closures. +- Actual client rendering, breaking overlay and hollow highlight geometry remain on the manual checklist. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index db78fd4..47e9d2a 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`. 142 commits including the API-cleanup plan and separate characterization and -port commits through the Edge/Post microblock factories. +Branch: `algent/java`. Base: `master`. 144 commits including the API-cleanup plan and separate characterization and +port commits through the Hollow microblock factory. ## The one rule that matters @@ -67,7 +67,7 @@ awk -F'"' '/[] pBoxes; + private Cuboid6[] occBounds; + + @SuppressWarnings("unchecked") + private HollowMicroClass$() { + pBoxes = (Seq[]) new Seq[256]; + occBounds = new Cuboid6[256]; + for (int side = 0; side < 6; side++) { + Transformation transform = Rotation.sideRotations[side].at(Vector3.center); + for (int size = 1; size < 8; size++) { + double thickness = size / 8D; + double width = 1 / 8D; + int shape = size << 4 | side; + pBoxes[shape] = JavaConversions + .asScalaBuffer( + Arrays.asList( + new Cuboid6(0, 0, 0, width, thickness, 1).apply(transform), + new Cuboid6(1 - width, 0, 0, 1, thickness, 1).apply(transform), + new Cuboid6(width, 0, 0, 1 - width, thickness, width).apply(transform), + new Cuboid6(width, 0, 1 - width, 1 - width, thickness, 1).apply(transform))) + .toList(); + occBounds[shape] = new Cuboid6(1 / 8D, 0, 1 / 8D, 7 / 8D, thickness, 7 / 8D).apply(transform); + } + } + } + + public Seq[] pBoxes() { + return pBoxes; + } + + public void pBoxes_$eq(Seq[] bounds) { + pBoxes = bounds; + } + + public Cuboid6[] occBounds() { + return occBounds; + } + + public void occBounds_$eq(Cuboid6[] bounds) { + occBounds = bounds; + } + + @Override + public String getName() { + return "mcr_hllw"; + } + + @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Class baseTrait() { + return (Class) HollowMicroblock.class; + } + + @Override + public Class clientTrait() { + return HollowMicroblockClient.class; + } + + @Override + public int itemSlot() { + return 3; + } + + @Override + public HollowPlacement$ placementProperties() { + return HollowPlacement$.MODULE$; + } + + @Override + public float getResistanceFactor() { + return 1; + } +} diff --git a/src/main/scala/codechicken/microblock/HollowMicroClass.java b/src/main/scala/codechicken/microblock/HollowMicroClass.java new file mode 100644 index 0000000..2ed1497 --- /dev/null +++ b/src/main/scala/codechicken/microblock/HollowMicroClass.java @@ -0,0 +1,85 @@ +package codechicken.microblock; + +import net.minecraft.nbt.NBTTagCompound; + +import codechicken.lib.data.MCDataInput; +import codechicken.lib.vec.Cuboid6; +import scala.collection.Seq; + +public final class HollowMicroClass { + + private HollowMicroClass() {} + + public static int baseTraitId() { + return HollowMicroClass$.MODULE$.baseTraitId(); + } + + public static int clientTraitId() { + return HollowMicroClass$.MODULE$.clientTraitId(); + } + + public static void register() { + HollowMicroClass$.MODULE$.register(); + } + + public static Microblock create(boolean client, int material) { + return HollowMicroClass$.MODULE$.create(client, material); + } + + public static Microblock createPart(String name, MCDataInput packet) { + return HollowMicroClass$.MODULE$.createPart(name, packet); + } + + public static Microblock createPart(String name, NBTTagCompound nbt) { + return HollowMicroClass$.MODULE$.createPart(name, nbt); + } + + public static int getClassId() { + return HollowMicroClass$.MODULE$.getClassId(); + } + + public static void register(int id) { + HollowMicroClass$.MODULE$.register(id); + } + + public static Seq[] pBoxes() { + return HollowMicroClass$.MODULE$.pBoxes(); + } + + public static void pBoxes_$eq(Seq[] bounds) { + HollowMicroClass$.MODULE$.pBoxes_$eq(bounds); + } + + public static Cuboid6[] occBounds() { + return HollowMicroClass$.MODULE$.occBounds(); + } + + public static void occBounds_$eq(Cuboid6[] bounds) { + HollowMicroClass$.MODULE$.occBounds_$eq(bounds); + } + + public static String getName() { + return HollowMicroClass$.MODULE$.getName(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static Class baseTrait() { + return (Class) HollowMicroClass$.MODULE$.baseTrait(); + } + + public static Class clientTrait() { + return HollowMicroClass$.MODULE$.clientTrait(); + } + + public static int itemSlot() { + return HollowMicroClass$.MODULE$.itemSlot(); + } + + public static HollowPlacement$ placementProperties() { + return HollowMicroClass$.MODULE$.placementProperties(); + } + + public static float getResistanceFactor() { + return HollowMicroClass$.MODULE$.getResistanceFactor(); + } +} diff --git a/src/main/scala/codechicken/microblock/HollowMicroblock.scala b/src/main/scala/codechicken/microblock/HollowMicroblockTraits.scala similarity index 86% rename from src/main/scala/codechicken/microblock/HollowMicroblock.scala rename to src/main/scala/codechicken/microblock/HollowMicroblockTraits.scala index 6ce9c45..dcfb6be 100644 --- a/src/main/scala/codechicken/microblock/HollowMicroblock.scala +++ b/src/main/scala/codechicken/microblock/HollowMicroblockTraits.scala @@ -17,53 +17,6 @@ import codechicken.lib.raytracer.IndexedCuboid6 import org.lwjgl.opengl.GL11 import codechicken.lib.render.uv.IconTransformation -object HollowPlacement extends PlacementProperties { - object HollowPlacementGrid extends FaceEdgeGrid(3 / 8d) - - def microClass = HollowMicroClass - - def placementGrid = HollowPlacementGrid - - def opposite(slot: Int, side: Int) = slot ^ 1 - - override def expand(slot: Int, side: Int) = sneakOpposite(slot, side) - - override def sneakOpposite(slot: Int, side: Int) = slot == (side ^ 1) -} - -object HollowMicroClass extends CommonMicroClass { - var pBoxes: Array[Seq[Cuboid6]] = new Array(256) - var occBounds: Array[Cuboid6] = new Array(256) - for (s <- 0 until 6) { - val transform = sideRotations(s).at(center) - for (t <- 1 until 8) { - val d = t / 8d - val w1 = 1 / 8d - val w2 = 3 / 16d - pBoxes(t << 4 | s) = Seq( - new Cuboid6(0, 0, 0, w1, d, 1), - new Cuboid6(1 - w1, 0, 0, 1, d, 1), - new Cuboid6(w1, 0, 0, 1 - w1, d, w1), - new Cuboid6(w1, 0, 1 - w1, 1 - w1, d, 1) - ) - .map(_.apply(transform)) - occBounds(t << 4 | s) = - new Cuboid6(1 / 8d, 0, 1 / 8d, 7 / 8d, d, 7 / 8d).apply(transform) - } - } - - def getName = "mcr_hllw" - - def baseTrait = classOf[HollowMicroblock] - def clientTrait = classOf[HollowMicroblockClient] - - def itemSlot = 3 - - def placementProperties = HollowPlacement - - def getResistanceFactor = 1 -} - trait HollowMicroblockClient extends HollowMicroblock with CommonMicroblockClient { @@ -339,7 +292,7 @@ trait HollowMicroblock extends CommonMicroblock with TFacePart with TNormalOcclusion { - def microClass = HollowMicroClass + def microClass = HollowMicroClass$.MODULE$ def getBounds: Cuboid6 = FaceMicroClass.aBounds()(shape) @@ -347,7 +300,8 @@ trait HollowMicroblock override def occlusionTest(npart: TMultiPart): Boolean = NormalOcclusionTest.apply(this, npart) && super.occlusionTest(npart) - override def getPartialOcclusionBoxes = HollowMicroClass.pBoxes(shape) + override def getPartialOcclusionBoxes = + HollowMicroClass$.MODULE$.pBoxes()(shape) def getHollowSize = tile match { case null => 8 @@ -360,7 +314,7 @@ trait HollowMicroblock def getOcclusionBoxes = { val size = getHollowSize - val c = HollowMicroClass.occBounds(shape) + val c = HollowMicroClass$.MODULE$.occBounds()(shape) val d1 = 0.5 - size / 32d val d2 = 0.5 + size / 32d val x1 = c.min.x diff --git a/src/main/scala/codechicken/microblock/HollowPlacement$.java b/src/main/scala/codechicken/microblock/HollowPlacement$.java new file mode 100644 index 0000000..e955c0c --- /dev/null +++ b/src/main/scala/codechicken/microblock/HollowPlacement$.java @@ -0,0 +1,33 @@ +package codechicken.microblock; + +public final class HollowPlacement$ extends PlacementProperties { + + public static final HollowPlacement$ MODULE$ = new HollowPlacement$(); + + private HollowPlacement$() {} + + @Override + public HollowMicroClass$ microClass() { + return HollowMicroClass$.MODULE$; + } + + @Override + public HollowPlacement.HollowPlacementGrid$ placementGrid() { + return HollowPlacement.HollowPlacementGrid$.MODULE$; + } + + @Override + public int opposite(int slot, int side) { + return slot ^ 1; + } + + @Override + public boolean expand(int slot, int side) { + return sneakOpposite(slot, side); + } + + @Override + public boolean sneakOpposite(int slot, int side) { + return slot == (side ^ 1); + } +} diff --git a/src/main/scala/codechicken/microblock/HollowPlacement.java b/src/main/scala/codechicken/microblock/HollowPlacement.java new file mode 100644 index 0000000..b058700 --- /dev/null +++ b/src/main/scala/codechicken/microblock/HollowPlacement.java @@ -0,0 +1,39 @@ +package codechicken.microblock; + +public final class HollowPlacement { + + private HollowPlacement() {} + + public static ExecutablePlacement customPlacement(MicroblockPlacement placement) { + return HollowPlacement$.MODULE$.customPlacement(placement); + } + + public static HollowMicroClass$ microClass() { + return HollowPlacement$.MODULE$.microClass(); + } + + public static HollowPlacementGrid$ placementGrid() { + return HollowPlacement$.MODULE$.placementGrid(); + } + + public static int opposite(int slot, int side) { + return HollowPlacement$.MODULE$.opposite(slot, side); + } + + public static boolean expand(int slot, int side) { + return HollowPlacement$.MODULE$.expand(slot, side); + } + + public static boolean sneakOpposite(int slot, int side) { + return HollowPlacement$.MODULE$.sneakOpposite(slot, side); + } + + public static class HollowPlacementGrid$ extends FaceEdgeGrid { + + public static final HollowPlacementGrid$ MODULE$ = new HollowPlacementGrid$(); + + public HollowPlacementGrid$() { + super(3 / 8D); + } + } +}