refactor: port micro occlusion logic to Java

This commit is contained in:
Algent committed 2026-09-04 00:16:03 +02:00
1 parent c70975914c
commit f6d1568399
5 files changed
+105 -72

No files matched your search

+6 -7
View File
@@ -24,13 +24,12 @@ 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. Common, face, corner, edge, post
and hollow microblock traits retain Scala inheritance/bridge declarations over Java behavior. The remaining
microblock implementations are in `TMicroOcclusion.scala`, alongside the compiler/signature/analyser compatibility
shells elsewhere. 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. Next:
`TMicroOcclusion`, followed separately by `TMicroOcclusionClient`. Retain trait lifecycle/super-dispatch bridges and
the ScalaSignature path-dependent model bridges.
placement/render helpers, both generators and all built-in tile traits are Java. Common, face, corner, edge, post,
hollow and occlusion microblock traits retain Scala inheritance/bridge declarations over Java behavior. The next
bounded target is `TMicroOcclusionClient`: lifecycle handling and render-state updates in `TMicroOcclusion.scala`.
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. Retain trait
state/accessor/super bridges and the compiler/signature/analyser model shells.
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
+15 -16
View File
@@ -16,23 +16,22 @@ migration checkout; `codex/tile-compatibility-fixes` was deleted after its fixes
## Current state and next target
**378 plain-JVM tests and 232 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **222 Java
files and 9 Scala files / 820 nonblank Scala lines**. The packaged inventory has 442 classes.
**386 plain-JVM tests and 234 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **223 Java
files and 9 Scala files / 784 nonblank Scala lines**. The packaged inventory has 443 classes.
Latest bounded target: `HollowMicroblockClient` delegates rendering and mask updates to
`HollowMicroblockClientLogic.java`. Scala retains inheritance metadata, `$class`, initialization and the recalculation
super bridge. Characterization was committed first as `c22d1ac`: frozen Scala forwarders pin initialization/super
ordering, render dispatch, rim bounds/masks/callback order, snapshots, breaking pipelines and highlight commands.
Forge covers real materials, all 42 shapes and live center connectors. Clean checks preserve 439 retained
class/member APIs, all 17 ScalaSignature payloads, 3,706 unrelated method bodies and all 116 generated dumps.
Five internal Scala callbacks become two Java callbacks under the shared classfile policy. Evidence:
`run/migration-hollow-client-reference/`; `clean` preserves it.
Latest bounded target: `TMicroOcclusion` delegates its occlusion and edge/corner rules to `TMicroOcclusionLogic.java`.
Scala retains inheritance metadata, `$class` and the short-circuiting super bridge. Characterization was committed
first as `c709759`: frozen Scala forwarders pin super/type-guard order, repeated getters, signed overflow,
material short-circuits, virtual edge/corner delegation and failures. Forge tests generated face/corner/edge pairs
with matching and different materials. Clean checks preserve all 442 original class/member APIs, all 17
ScalaSignature payloads, 3,721 unrelated method bodies and all 116 generated dumps. The Java helper is the sole
added class; no originals are removed. Evidence: `run/migration-micro-occlusion-trait-reference/`.
**Next: port `TMicroOcclusion` in `microblock/TMicroOcclusion.scala`.** Characterize super-call short-circuiting,
size/material/slot constraints, repeated virtual reads and edge/corner bit tests before extraction. Leave
`TMicroOcclusionClient` lifecycle/state handling for a separate bounded target.
Retain the Scala inheritance declarations, external ProjectRed Scala-trait fixture and ScalaSignature model bridges;
compiler changes stay separate. Actual client generation, GPU output and full-pack checks remain manual.
**Next: port `TMicroOcclusionClient` in `microblock/TMicroOcclusion.scala`.** Characterize lifecycle super/recalc
ordering, packet propagation, render-bounds copying, mask updates and failures before extraction. Retain the
`JMicroShrinkRender` declaration, Scala inheritance metadata and state/accessor/super bridges as needed.
The external ProjectRed Scala-trait fixture and ScalaSignature model bridges remain required; compiler changes
stay separate. Actual client generation, GPU output and full-pack checks remain manual.
Remaining Scala units:
@@ -43,7 +42,7 @@ Remaining Scala units:
| `multipart/asm/StackAnalyser.scala` | Class/companion/model shell over Java `StackAnalyserLogic` |
| `microblock/MicroblockTraits.scala`, `FaceMicroblockTraits.scala`, `CornerMicroblockTraits.scala`, `EdgeMicroblockTraits.scala` | Nine retained state/inheritance/bridge shells over Java implementation, including post lifecycle/super dispatch |
| `microblock/HollowMicroblockTraits.scala` | Hollow server/client inheritance, initializer and super shells over Java behavior |
| `microblock/TMicroOcclusion.scala` | Remaining occlusion and client lifecycle implementations; preserve inheritance metadata |
| `microblock/TMicroOcclusion.scala` | Occlusion inheritance/super shell and remaining client lifecycle/state implementation |
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
+22
View File
@@ -1217,3 +1217,25 @@ differences belong in the [divergence ledger](../../JAVA_MIGRATION_DIVERGENCES.m
edge/corner bit tests before extraction. Leave `TMicroOcclusionClient` for a separate target. Existing manual checks
cover AE2 cables and ProjectRed Framed Red Alloy Wire through hollow covers. Recorded rendering commands and
headless helper tests do not validate actual client generation or GPU/full-pack output.
### 2026-09-04 — Micro occlusion trait implementation
- Committed eight JVM and two Forge characterization tests first as `c709759`. Frozen Scala 2.11.5 forwarders
compiled under Java 8 against the untouched jar pin the real super call before null/non-micro guards, repeated
getter order, signed size overflow, material short-circuits, own-receiver edge/corner delegation and getter errors.
Edge/corner tests cover the full 12-by-8 mapping, independent edge reads and invalid-slot failure order. Forge
exercises generated face/corner/edge pairs at size thresholds with Stone/Glass materials in both directions.
The existing complete decision-table digest and external Scala-trait fixtures remain unchanged and passing.
- Extracted two method bodies to package-private `TMicroOcclusionLogic.java`. The Scala shell retains inheritance
metadata, `$class`, initializer and the synthetic super call, which Java source cannot invoke directly. Rules still
use the original virtual reads and integer arithmetic, including overflow and out-of-range slot behavior; no
unrelated fix, compiler change or new effective divergence was introduced. `TMicroOcclusionClient` is untouched.
- Evidence in ignored `run/migration-micro-occlusion-trait-reference/` includes source/jar, fixture compilation,
reports and 116 generated dumps. Normal and clean checks after stopping Gradle preserve all 442 original
class/member APIs, all 17 ScalaSignature payloads, 3,721 unrelated method bodies and all 116 dump names/hashes.
Only the Java helper is added: 442 -> 443 packaged classes. Formatting, checkstyle, build and Forge pass with
386 JVM / 234 Forge tests, zero failures/errors/skips. The forced Scala-compilation guard and all five packaged
`@Mod` versions remain verified. Sources total 223 Java files and 9 Scala files / 784 nonblank Scala lines.
- Next: `TMicroOcclusionClient`; characterize lifecycle super/recalc ordering, packet propagation, bounds copying,
mask updates and failures. Retain `JMicroShrinkRender` and required Scala metadata/state/super bridges. Actual
client generation, GPU drawing and full-pack checks remain on the existing manual checklist.
@@ -2,7 +2,6 @@ package codechicken.microblock
import codechicken.multipart.TMultiPart
import codechicken.lib.vec.Cuboid6
import codechicken.multipart.PartMap._
import codechicken.lib.data.MCDataInput
trait JMicroShrinkRender {
@@ -46,56 +45,13 @@ trait TMicroOcclusion extends TMultiPart {
def getMaterial: Int
def getBounds: Cuboid6
override def occlusionTest(npart: TMultiPart): Boolean = {
if (!super.occlusionTest(npart))
return false
if (!npart.isInstanceOf[TMicroOcclusion])
return true
val mpart = npart.asInstanceOf[TMicroOcclusion]
val shape1 = MicroOcclusion$.MODULE$.shapePriority(getSlot)
val shape2 = MicroOcclusion$.MODULE$.shapePriority(mpart.getSlot)
if (mpart.getSize + getSize > 8) // intersecting if opposite
{
if (shape1 == 2 && shape2 == 2)
if (mpart.getSlot == (getSlot ^ 1))
return false
if (mpart.getMaterial != getMaterial) {
if (shape1 == 1 && shape2 == 1) {
val axisMask = (getSlot - 7) ^ (mpart.getSlot - 7)
if (axisMask == 3 || axisMask == 5 || axisMask == 6)
return false
}
if (shape1 == 0 && shape2 == 1)
if (!edgeCornerOcclusionTest(this, mpart))
return false
if (shape1 == 1 && shape2 == 0)
if (!edgeCornerOcclusionTest(mpart, this))
return false
if (shape1 == 0 && shape2 == 0) {
val e1 = getSlot - 15
val e2 = mpart.getSlot - 15
if ((e1 & 0xc) == (e2 & 0xc) && ((e1 & 3) ^ (e2 & 3)) == 3)
return false
}
}
}
return true
}
// Scala retains the synthetic super accessor and trait linearization.
override def occlusionTest(npart: TMultiPart): Boolean =
super
.occlusionTest(npart) && TMicroOcclusionLogic.occlusionTest(this, npart)
def edgeCornerOcclusionTest(
edge: TMicroOcclusion,
corner: TMicroOcclusion
): Boolean = {
((corner.getSlot - 7) & edgeAxisMask(edge.getSlot - 15)) == unpackEdgeBits(
edge.getSlot - 15
)
}
): Boolean = TMicroOcclusionLogic.edgeCornerOcclusionTest(edge, corner)
}
@@ -0,0 +1,57 @@
package codechicken.microblock;
import codechicken.multipart.PartMap;
import codechicken.multipart.TMultiPart;
/** Occlusion rules after the retained Scala super call. */
final class TMicroOcclusionLogic {
private TMicroOcclusionLogic() {}
static boolean occlusionTest(TMicroOcclusion part, TMultiPart next) {
if (!(next instanceof TMicroOcclusion)) {
return true;
}
TMicroOcclusion other = (TMicroOcclusion) next;
int shape1 = MicroOcclusion$.MODULE$.shapePriority(part.getSlot());
int shape2 = MicroOcclusion$.MODULE$.shapePriority(other.getSlot());
if (other.getSize() + part.getSize() > 8) {
if (shape1 == 2 && shape2 == 2) {
if (other.getSlot() == (part.getSlot() ^ 1)) {
return false;
}
}
if (other.getMaterial() != part.getMaterial()) {
if (shape1 == 1 && shape2 == 1) {
int axisMask = (part.getSlot() - 7) ^ (other.getSlot() - 7);
if (axisMask == 3 || axisMask == 5 || axisMask == 6) {
return false;
}
}
if (shape1 == 0 && shape2 == 1) {
if (!part.edgeCornerOcclusionTest(part, other)) {
return false;
}
}
if (shape1 == 1 && shape2 == 0) {
if (!part.edgeCornerOcclusionTest(other, part)) {
return false;
}
}
if (shape1 == 0 && shape2 == 0) {
int edge1 = part.getSlot() - 15;
int edge2 = other.getSlot() - 15;
if ((edge1 & 0xc) == (edge2 & 0xc) && ((edge1 & 3) ^ (edge2 & 3)) == 3) {
return false;
}
}
}
}
return true;
}
static boolean edgeCornerOcclusionTest(TMicroOcclusion edge, TMicroOcclusion corner) {
return ((corner.getSlot() - 7) & PartMap.edgeAxisMask(edge.getSlot() - 15))
== PartMap.unpackEdgeBits(edge.getSlot() - 15);
}
}