mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-18 11:29:33 +00:00
refactor: port hollow microblock logic to Java
This commit is contained in:
1 parent
6e807cce34
commit
940609bf46
6 files changed
+194
-82
No files matched your search
+3
-2
@@ -26,10 +26,11 @@ 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. Two files still contain generated
|
||||
microblock implementations in Scala, alongside the compiler/signature/analyser compatibility shells. The common,
|
||||
face, corner, edge and post traits retain inheritance/bridge declarations over Java behavior. Composite generation,
|
||||
face, corner, edge, post and hollow server 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
|
||||
`HollowMicroblock` in `microblock/HollowMicroblockTraits.scala`, followed separately by its client trait. Retain the
|
||||
`HollowMicroblockClient` in `microblock/HollowMicroblockTraits.scala`. Retain the
|
||||
post lifecycle/super-dispatch bridges and the ScalaSignature path-dependent model bridges.
|
||||
|
||||
Start with [JAVA_MIGRATION_HANDOFF.md](JAVA_MIGRATION_HANDOFF.md) for the exact source/test baseline, workflow and
|
||||
|
||||
+14
-15
@@ -16,22 +16,21 @@ migration checkout; `codex/tile-compatibility-fixes` was deleted after its fixes
|
||||
|
||||
## Current state and next target
|
||||
|
||||
**365 plain-JVM tests and 227 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **220 Java
|
||||
files and 9 Scala files / 1,104 nonblank Scala lines**. The packaged inventory has 443 classes.
|
||||
**370 plain-JVM tests and 231 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **221 Java
|
||||
files and 9 Scala files / 1,051 nonblank Scala lines**. The packaged inventory has 444 classes.
|
||||
|
||||
Latest bounded target: `PostMicroblockClient` delegates render/recalculation/shrink behavior to
|
||||
`PostMicroblockClientLogic.java`. Scala retains its state, inheritance metadata, `$class` and lifecycle/super
|
||||
forwarders. Characterization was committed first as `47885d1`: frozen Scala forwarders pin render pass selection,
|
||||
material reuse, repeated getters, equality receivers, collection `foreach`, split/reset behavior and lifecycle
|
||||
failure ordering. Forge exercises real cover/post geometry on all three axes through the client helper; actual
|
||||
client generation/GPU output remains a manual gate. Clean verification after stopping Gradle preserves all 441
|
||||
retained class/member APIs, all 17 ScalaSignature payloads, 3,703 unrelated method bodies and all 116 generated dumps.
|
||||
One internal Scala callback is replaced by the Java helper/callback under the shared classfile policy. Local evidence
|
||||
is in `run/migration-post-client-reference/`; `clean` preserves it.
|
||||
Latest bounded target: `HollowMicroblock` delegates connector lookup, geometry, collections and normal occlusion to
|
||||
`HollowMicroblockTraitLogic.java`. Scala retains inheritance metadata, `$class`, singleton/constants and its
|
||||
short-circuiting super bridge. Characterization was committed first as `6e807cc`: frozen Scala forwarders pin
|
||||
repeated tile/raw-shape reads, connector/slot dispatch, list mutability/copies and occlusion super ordering. Forge
|
||||
covers all 42 shapes, live opening sizes, bounds-array replacement/errors and NBT/description bytes. Clean checks
|
||||
preserve 441 retained class/member APIs, all 17 ScalaSignature payloads, 3,704 unrelated method bodies and all 116
|
||||
generated dumps. Two internal Scala callbacks become Java callbacks under the shared classfile policy. Evidence:
|
||||
`run/migration-hollow-trait-reference/`; `clean` preserves it.
|
||||
|
||||
**Next: port `HollowMicroblock` in `microblock/HollowMicroblockTraits.scala`.** Characterize its center connector
|
||||
lookup, hollow-size/slot geometry, normal/partial/collision boxes, subparts and occlusion super ordering before
|
||||
conversion. Leave `HollowMicroblockClient` rendering for a separate bounded target.
|
||||
**Next: port `HollowMicroblockClient` in `microblock/HollowMicroblockTraits.scala`.** Characterize render-mask
|
||||
initialization/recalculation and super ordering, pass/transparency dispatch, rim geometry/callback order, breaking
|
||||
and highlight behavior before extraction. Actual client generation, GPU output and full-pack checks remain manual.
|
||||
Retain the Scala declarations where inheritance metadata is required, the external ProjectRed Scala-trait fixture
|
||||
and the ScalaSignature model bridges; compiler changes stay separate.
|
||||
|
||||
@@ -43,7 +42,7 @@ 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`, `EdgeMicroblockTraits.scala` | Nine retained state/inheritance/bridge shells over Java implementation, including post lifecycle/super dispatch |
|
||||
| `microblock/HollowMicroblockTraits.scala`, `TMicroOcclusion.scala` | Generated trait implementations; port in bounded groups while preserving inheritance metadata |
|
||||
| `microblock/HollowMicroblockTraits.scala`, `TMicroOcclusion.scala` | Hollow server shell plus remaining client/occlusion implementations; preserve 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
|
||||
|
||||
@@ -61,6 +61,7 @@ entries complete.
|
||||
| [ ] | Repeat with **Red Alloy Wire**, clicking deep into a face | The part is placed in the neighbouring block on that side | `TItemMultiPart.onItemUse` offset path |
|
||||
| [ ] | Place a part where it would overlap an existing one | Placement is refused rather than silently replacing | `NormalOcclusionTest`, `PartialOcclusionTest` |
|
||||
| [ ] | Place a cover on a face that already has a hollow cover | Redstone still passes through the hollow centre | `TFacePart.redstoneConductionMap` |
|
||||
| [ ] | Place **Hollow Stone Cover** and **Hollow Inverted White Lamp Cover** parts at several thicknesses around ProjectRed **Framed Red Alloy Wire** on all six faces; add/remove the wire, select the rim, then save and reload | The opening follows the connector, selection/collision respect the hollow centre, incompatible overlaps are refused, and shape/material survive reload | `HollowMicroblock` / `HollowMicroblockTraitLogic` |
|
||||
| [ ] | Run ProjectRed **Red Alloy Wire** across a **Stone Strip** edge microblock | Conduction matches the pre-port behavior | `TEdgePart.conductsRedstone` |
|
||||
| [ ] | Cut materials with saws of different harvest levels | Only materials at or below the saw's strength can be cut | `Saw.getMaxCuttingStrength` |
|
||||
| [ ] | Place the same microblock in survival and creative, including onto an existing multipart tile | Valid placements play the material sound; survival consumes the expected amount while creative does not | `ItemMicroPart.onItemUse` |
|
||||
|
||||
@@ -1163,3 +1163,30 @@ differences belong in the [divergence ledger](../../JAVA_MIGRATION_DIVERGENCES.m
|
||||
- Expanded the existing manual post check with Stone, Glass and ProjectRed Inverted White Lamp examples. The
|
||||
dedicated server strips the client factory entry point; helper/geometry coverage does not establish actual client
|
||||
generation or GPU output. Next: `HollowMicroblock`, followed separately by `HollowMicroblockClient`.
|
||||
|
||||
### 2026-09-03 — Hollow microblock trait implementation
|
||||
|
||||
- Committed five JVM and four Forge characterization tests first as `6e807cc`, before changing production code.
|
||||
Frozen Scala 2.11.5 forwarders compiled under Java 8 against the untouched jar pin repeated tile/raw-shape reads,
|
||||
center-slot lookup and arbitrary connector results, signed thickness and invalid rotations, fresh read-only collision
|
||||
boxes, mutable copied subparts, normal/partial overlap short-circuiting and the real Scala super chain. Forge covers
|
||||
all 42 supported shapes, live opening sizes, public bounds arrays/views, null/signed-index/invalid-slot failures and
|
||||
exact material/shape NBT and description bytes. Existing ordered geometry and ProjectRed trait fixtures still run.
|
||||
- Extracted seven method bodies to package-private `HollowMicroblockTraitLogic.java`; retained Scala inheritance,
|
||||
singleton/constants and the synthetic super bridge. Java cannot directly invoke that Scala synthetic accessor.
|
||||
Kept Scala collection builders and conversions: a null partial-box sequence returns a wrapper whose use throws,
|
||||
collision lists reject mutations, and subparts are mutable copies. Connector sizes remain unclamped; applying the
|
||||
original transformation still normalizes inverted collision bounds. These are characterized existing behaviors,
|
||||
not new defects or fixes. Two internal Scala callbacks are replaced under the existing shared classfile policy;
|
||||
no new effective divergence, compiler change or client-rendering change was introduced.
|
||||
- Saved the source/reference jar, frozen fixture compilation, reports and 116 generated dumps in ignored
|
||||
`run/migration-hollow-trait-reference/`. Normal and clean verification after stopping Gradle preserve all 441
|
||||
retained original class/member APIs, all 17 ScalaSignature payloads, 3,704 unrelated method bodies and all 116
|
||||
generated dump names/hashes. The helper and two callbacks replace two Scala callbacks: 443 -> 444 packaged classes.
|
||||
Formatting, checkstyle, build and Forge pass with 370 JVM / 231 Forge tests, zero failures/errors/skips. The forced
|
||||
Scala-compilation guard and all five packaged `@Mod` versions remain verified. Sources total 221 Java files and
|
||||
9 Scala files / 1,051 nonblank Scala lines.
|
||||
- Next: `HollowMicroblockClient`. Characterize render-mask initialization/recalculation and super ordering,
|
||||
pass/transparency dispatch, rim geometry/callback order, breaking and highlight behavior before extraction.
|
||||
Added a manual hollow-cover interaction/reload check with ProjectRed Framed Red Alloy Wire and Hollow Inverted
|
||||
White Lamp Cover examples; actual client generation, GPU output and full-pack validation remain manual gates.
|
||||
@@ -0,0 +1,139 @@
|
||||
package codechicken.microblock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.lib.raytracer.IndexedCuboid6;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.lib.vec.Transformation;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.NormalOcclusionTest;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import scala.MatchError;
|
||||
import scala.Predef$;
|
||||
import scala.collection.JavaConversions;
|
||||
import scala.collection.Seq;
|
||||
import scala.collection.Seq$;
|
||||
import scala.collection.TraversableLike;
|
||||
import scala.collection.mutable.Buffer;
|
||||
import scala.collection.mutable.Buffer$;
|
||||
import scala.runtime.AbstractFunction1;
|
||||
|
||||
/** Hollow-cover behavior behind the retained Scala inheritance metadata and super-dispatch bridge. */
|
||||
final class HollowMicroblockTraitLogic {
|
||||
|
||||
private HollowMicroblockTraitLogic() {}
|
||||
|
||||
static Cuboid6 getBounds(HollowMicroblock part) {
|
||||
return FaceMicroClass.aBounds()[((Microblock) part).shape()];
|
||||
}
|
||||
|
||||
static boolean normalOcclusionTest(HollowMicroblock part, TMultiPart next) {
|
||||
return NormalOcclusionTest.apply(part, next);
|
||||
}
|
||||
|
||||
static List<Cuboid6> getPartialOcclusionBoxes(HollowMicroblock part) {
|
||||
return JavaConversions.seqAsJavaList(HollowMicroClass$.MODULE$.pBoxes()[((Microblock) part).shape()]);
|
||||
}
|
||||
|
||||
static int getHollowSize(HollowMicroblock part) {
|
||||
if (((TMultiPart) part).tile() == null) {
|
||||
return 8;
|
||||
}
|
||||
// The second virtual lookup is observable when a part overrides tile().
|
||||
TMultiPart center = ((TMultiPart) part).tile().partMap(6);
|
||||
if (center instanceof ISidedHollowConnect) {
|
||||
return ((ISidedHollowConnect) center).getHollowSize(part.getSlot());
|
||||
}
|
||||
return 8;
|
||||
}
|
||||
|
||||
static Iterable<Cuboid6> getOcclusionBoxes(HollowMicroblock part) {
|
||||
int size = part.getHollowSize();
|
||||
Cuboid6 c = HollowMicroClass$.MODULE$.occBounds()[((Microblock) part).shape()];
|
||||
double d1 = 0.5 - size / 32D;
|
||||
double d2 = 0.5 + size / 32D;
|
||||
double x1 = c.min.x;
|
||||
double x2 = c.max.x;
|
||||
double y1 = c.min.y;
|
||||
double y2 = c.max.y;
|
||||
double z1 = c.min.z;
|
||||
double z2 = c.max.z;
|
||||
int slot = part.getSlot();
|
||||
Cuboid6[] boxes;
|
||||
switch (slot) {
|
||||
case 0:
|
||||
case 1:
|
||||
boxes = new Cuboid6[] { new Cuboid6(d2, y1, d1, x2, y2, d2), new Cuboid6(x1, y1, d1, d1, y2, d2),
|
||||
new Cuboid6(x1, y1, d2, x2, y2, z2), new Cuboid6(x1, y1, z1, x2, y2, d1) };
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
boxes = new Cuboid6[] { new Cuboid6(d1, d2, z1, d2, y2, z2), new Cuboid6(d1, y1, z1, d2, d1, z2),
|
||||
new Cuboid6(d2, y1, z1, x2, y2, z2), new Cuboid6(x1, y1, z1, d1, y2, z2) };
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
boxes = new Cuboid6[] { new Cuboid6(x1, d1, d2, x2, d2, z2), new Cuboid6(x1, d1, z1, x2, d2, d1),
|
||||
new Cuboid6(x1, d2, z1, x2, y2, z2), new Cuboid6(x1, y1, z1, x2, d1, z2) };
|
||||
break;
|
||||
default:
|
||||
throw new MatchError(slot);
|
||||
}
|
||||
return JavaConversions.seqAsJavaList(sequence(boxes));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
static List<Cuboid6> getCollisionBoxes(HollowMicroblock part) {
|
||||
int size = part.getHollowSize();
|
||||
double d1 = 0.5 - size / 32D;
|
||||
double d2 = 0.5 + size / 32D;
|
||||
double thickness = (((Microblock) part).shape() >> 4) / 8D;
|
||||
Transformation rotation = Rotation.sideRotations[((Microblock) part).shape() & 15].at(Vector3.center);
|
||||
Seq<Cuboid6> boxes = sequence(
|
||||
new Cuboid6[] { new Cuboid6(0, 0, 0, 1, thickness, d1), new Cuboid6(0, 0, d2, 1, thickness, 1),
|
||||
new Cuboid6(0, 0, d1, d1, thickness, d2), new Cuboid6(d2, 0, d1, 1, thickness, d2) });
|
||||
return JavaConversions.seqAsJavaList(
|
||||
(Seq<Cuboid6>) ((TraversableLike) boxes).map(new RotateBox(rotation), Seq$.MODULE$.canBuildFrom()));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
static List<IndexedCuboid6> getSubParts(HollowMicroblock part) {
|
||||
return JavaConversions.bufferAsJavaList(
|
||||
(Buffer<IndexedCuboid6>) ((TraversableLike) JavaConversions.asScalaBuffer(part.getCollisionBoxes()))
|
||||
.map(new IndexBox(), Buffer$.MODULE$.canBuildFrom()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Seq<Cuboid6> sequence(Cuboid6[] boxes) {
|
||||
return (Seq<Cuboid6>) Seq$.MODULE$.apply(Predef$.MODULE$.wrapRefArray(boxes));
|
||||
}
|
||||
|
||||
private static final class RotateBox extends AbstractFunction1<Cuboid6, Cuboid6> implements scala.Serializable {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
private final Transformation rotation;
|
||||
|
||||
RotateBox(Transformation rotation) {
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cuboid6 apply(Cuboid6 box) {
|
||||
return box.apply(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class IndexBox extends AbstractFunction1<Cuboid6, IndexedCuboid6>
|
||||
implements scala.Serializable {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
IndexBox() {}
|
||||
|
||||
@Override
|
||||
public IndexedCuboid6 apply(Cuboid6 box) {
|
||||
return new IndexedCuboid6(0, box);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -294,79 +294,24 @@ trait HollowMicroblock
|
||||
with TNormalOcclusion {
|
||||
def microClass = HollowMicroClass$.MODULE$
|
||||
|
||||
def getBounds: Cuboid6 = FaceMicroClass.aBounds()(shape)
|
||||
def getBounds: Cuboid6 = HollowMicroblockTraitLogic.getBounds(this)
|
||||
|
||||
// TNormalOcclusion is a Java interface, so its box test must be applied here rather than by the super chain.
|
||||
// Scala retains the synthetic super accessor and its trait linearization.
|
||||
override def occlusionTest(npart: TMultiPart): Boolean =
|
||||
NormalOcclusionTest.apply(this, npart) && super.occlusionTest(npart)
|
||||
HollowMicroblockTraitLogic.normalOcclusionTest(this, npart) && super
|
||||
.occlusionTest(npart)
|
||||
|
||||
override def getPartialOcclusionBoxes =
|
||||
HollowMicroClass$.MODULE$.pBoxes()(shape)
|
||||
HollowMicroblockTraitLogic.getPartialOcclusionBoxes(this)
|
||||
|
||||
def getHollowSize = tile match {
|
||||
case null => 8
|
||||
case _ =>
|
||||
tile.partMap(6) match {
|
||||
case part: ISidedHollowConnect => part.getHollowSize(getSlot)
|
||||
case _ => 8
|
||||
}
|
||||
}
|
||||
def getHollowSize = HollowMicroblockTraitLogic.getHollowSize(this)
|
||||
|
||||
def getOcclusionBoxes = {
|
||||
val size = getHollowSize
|
||||
val c = HollowMicroClass$.MODULE$.occBounds()(shape)
|
||||
val d1 = 0.5 - size / 32d
|
||||
val d2 = 0.5 + size / 32d
|
||||
val x1 = c.min.x
|
||||
val x2 = c.max.x
|
||||
val y1 = c.min.y
|
||||
val y2 = c.max.y
|
||||
val z1 = c.min.z
|
||||
val z2 = c.max.z
|
||||
def getOcclusionBoxes = HollowMicroblockTraitLogic.getOcclusionBoxes(this)
|
||||
|
||||
getSlot match {
|
||||
case 0 | 1 =>
|
||||
Seq(
|
||||
new Cuboid6(d2, y1, d1, x2, y2, d2),
|
||||
new Cuboid6(x1, y1, d1, d1, y2, d2),
|
||||
new Cuboid6(x1, y1, d2, x2, y2, z2),
|
||||
new Cuboid6(x1, y1, z1, x2, y2, d1)
|
||||
)
|
||||
case 2 | 3 =>
|
||||
Seq(
|
||||
new Cuboid6(d1, d2, z1, d2, y2, z2),
|
||||
new Cuboid6(d1, y1, z1, d2, d1, z2),
|
||||
new Cuboid6(d2, y1, z1, x2, y2, z2),
|
||||
new Cuboid6(x1, y1, z1, d1, y2, z2)
|
||||
)
|
||||
case 4 | 5 =>
|
||||
Seq(
|
||||
new Cuboid6(x1, d1, d2, x2, d2, z2),
|
||||
new Cuboid6(x1, d1, z1, x2, d2, d1),
|
||||
new Cuboid6(x1, d2, z1, x2, y2, z2),
|
||||
new Cuboid6(x1, y1, z1, x2, d1, z2)
|
||||
)
|
||||
}
|
||||
}
|
||||
override def getCollisionBoxes =
|
||||
HollowMicroblockTraitLogic.getCollisionBoxes(this)
|
||||
|
||||
override def getCollisionBoxes = {
|
||||
val size = getHollowSize
|
||||
val d1 = 0.5 - size / 32d
|
||||
val d2 = 0.5 + size / 32d
|
||||
val t = (shape >> 4) / 8d
|
||||
|
||||
val tr = sideRotations(shape & 0xf).at(center)
|
||||
Seq(
|
||||
new Cuboid6(0, 0, 0, 1, t, d1),
|
||||
new Cuboid6(0, 0, d2, 1, t, 1),
|
||||
new Cuboid6(0, 0, d1, d1, t, d2),
|
||||
new Cuboid6(d2, 0, d1, 1, t, d2)
|
||||
)
|
||||
.map(c => c.apply(tr))
|
||||
}
|
||||
|
||||
override def getSubParts =
|
||||
getCollisionBoxes.map(c => new IndexedCuboid6(0, c))
|
||||
override def getSubParts = HollowMicroblockTraitLogic.getSubParts(this)
|
||||
|
||||
override def allowCompleteOcclusion = true
|
||||
|
||||
|
||||
Reference in new issue
Block a user