refactor: port hollow microblock factory

This commit is contained in:
Algent committed 2026-09-02 01:23:47 +02:00
1 parent 911e73291f
commit 33510e74bd
9 files changed
+332 -57

No files matched your search

+11
View File
@@ -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.
+57
View File
@@ -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<? extends Microblock>` in Java rather
than Scala's `Class<HollowMicroblock>`; 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.
+14 -7
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`. 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'"' '/<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: **250 plain-JVM tests and 108 Java 8 Forge dedicated-server tests passing.** The ignored local server
Current baseline: **252 plain-JVM tests and 110 Java 8 Forge dedicated-server tests passing.** The ignored local server
EULA is accepted in this checkout. GitHub Actions runs the same self-validating Forge suite in a dependent job after
the shared GTNH build; keep both jobs required.
@@ -272,7 +272,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.
181 Java files, 16 Scala files, ~3,001 Scala lines left (non-blank; that is the metric this figure has always used).
185 Java files, 16 Scala files, ~2,967 Scala lines left (non-blank; that is the metric this figure has always used).
## What is left, and in what order
@@ -513,9 +513,16 @@ edge bounds, 12 post bounds, generated behavior, even-size centre placement and
The stateful `PostMicroblockClient` traversal closure remains an exact private-surface match; only four private bounds
initializer closures disappear.
**High.** `HollowMicroblock.scala` is next. Characterize its placement/factory surfaces, bounds and all hollow-size/
side geometry plus the large stateful client-render trait before splitting only the concrete facade/companion code.
Keep both generated traits Scala and do not combine this with `TMicroOcclusion` or generator work.
The Hollow source unit is now four Java facade/companion sources plus two retained Scala traits. Two plain-JVM cases
freeze all nine supported surfaces, including the public static nested placement-grid relationship. Two Forge cases
freeze both 42-entry tables, generated server behavior and every face across connected hollow sizes 1 through 11.
Both trait helpers and all seven retained geometry/render closures are bytecode-identical to the reference; only the
three private table-initializer closures disappear. ProjectRed's trait checks and static class-ID call, Extra
Utilities' two client-trait checks, and BuildCraft/MatterManipulator's stable `"mcr_hllw"` ID remain exact.
**High.** `TMicroOcclusion.scala` is next. Freeze the complete shrink/priority math and all generated trait/helper
surfaces before splitting only the concrete `MicroOcclusion` facade/companion logic. Keep `JMicroShrinkRender`,
`TMicroOcclusion`, and the stateful `TMicroOcclusionClient` Scala, and do not combine this with 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
+1
View File
@@ -31,6 +31,7 @@ below its table.
| [ ] | Render several block micro-materials with Angelica shaders enabled, then render an unrelated block | Each face receives the matching block/meta shader material and the override is reset after the microblock draw | `MaterialRenderHelper.blockAndMeta` / `render` |
| [ ] | Inspect face, hollow, edge and corner microblocks in inventory and as dropped entities | Every size/material combination uses the correct localized name and centered shape/material render | `ItemMicroPart` / `ItemMicroPartRenderer` / `MicroblockRender.renderItem` |
| [ ] | Place crossing posts of different sizes/transparency beside face covers, then add and remove neighbours | Post segments shrink and split at intersections without missing sections or stale render bounds | `PostMicroblockClient.recalcBounds` / `shrinkFace` / `shrinkPost` |
| [ ] | Run centre pipes/cables with several connection widths through hollow covers on all six faces, including glass | Each opening follows the connector size; opaque and transparent rims, breaking overlay and highlight have no missing, doubled or stale sections after neighbour changes | `HollowMicroblockClient.recalcBounds` / `renderHollow` / `drawBreaking` / `drawHighlight` |
## Placement and interaction
@@ -0,0 +1,88 @@
package codechicken.microblock;
import java.util.Arrays;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Rotation;
import codechicken.lib.vec.Transformation;
import codechicken.lib.vec.Vector3;
import scala.collection.JavaConversions;
import scala.collection.Seq;
public final class HollowMicroClass$ extends CommonMicroClass {
public static final HollowMicroClass$ MODULE$ = new HollowMicroClass$();
private Seq<Cuboid6>[] pBoxes;
private Cuboid6[] occBounds;
@SuppressWarnings("unchecked")
private HollowMicroClass$() {
pBoxes = (Seq<Cuboid6>[]) 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<Cuboid6>[] pBoxes() {
return pBoxes;
}
public void pBoxes_$eq(Seq<Cuboid6>[] 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<? extends Microblock> baseTrait() {
return (Class) HollowMicroblock.class;
}
@Override
public Class<HollowMicroblockClient> clientTrait() {
return HollowMicroblockClient.class;
}
@Override
public int itemSlot() {
return 3;
}
@Override
public HollowPlacement$ placementProperties() {
return HollowPlacement$.MODULE$;
}
@Override
public float getResistanceFactor() {
return 1;
}
}
@@ -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<Cuboid6>[] pBoxes() {
return HollowMicroClass$.MODULE$.pBoxes();
}
public static void pBoxes_$eq(Seq<Cuboid6>[] 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<HollowMicroblock> baseTrait() {
return (Class) HollowMicroClass$.MODULE$.baseTrait();
}
public static Class<HollowMicroblockClient> 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();
}
}
@@ -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
@@ -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);
}
}
@@ -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);
}
}
}