mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-25 14:34:45 +00:00
refactor: port microblock classes to Java
This commit is contained in:
1 parent
ee75f86e02
commit
7172af4573
8 files changed
+200
-73
No files matched your search
@@ -1135,3 +1135,13 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
anonymous/closure classes.
|
||||
- A clean build passes all 238 plain-JVM tests and the Java 8 Forge server passes all 103 tests.
|
||||
`microblock/MicroblockClass.scala` is next.
|
||||
- Characterized `MicroblockClass`, `CommonMicroClass` and its companion against untouched Scala. Three plain-JVM
|
||||
cases freeze the exact hierarchy, constructors, public descriptors, private fields, side annotations, registry
|
||||
semantics and generator call descriptors. Constructor execution remains a Forge-only boundary because generator
|
||||
initialization requires the launch class loader.
|
||||
- Ported all three retained types directly to Java. Eager base-trait registration, synchronized one-time client-trait
|
||||
registration, part-factory registration order, class IDs, duplicate rejection and both create paths are unchanged.
|
||||
The GuideNH-pinned `MicroblockGenerator$.create(MicroblockClass, int, boolean)` descriptor remains exact.
|
||||
- A clean build passes all 241 plain-JVM tests and the Java 8 Forge server passes all 103 tests. The clean reference and
|
||||
port jars contain the same three runtime types and every callable public descriptor matches. `microblock/Microblock.scala`
|
||||
is the next deliberately high-risk target.
|
||||
@@ -2657,3 +2657,48 @@ references to them.
|
||||
- Clean reference/port jars retain the same two supported types, and raw `javap` comparison confirms identical
|
||||
callable public names/descriptors and retained field shape.
|
||||
- Actual item, material-face, placement-grid and highlight OpenGL output remains on the manual checklist.
|
||||
|
||||
## 2026-09-01 — MicroblockClass Java port
|
||||
|
||||
The abstract microblock factory, common factory base and common-factory registry singleton are now Java.
|
||||
|
||||
### Observable behavior
|
||||
|
||||
No known runtime divergence. Construction still registers the common trait eagerly. The client trait ID remains a
|
||||
synchronized, one-time lazy value backed by the same volatile bitmap shape, so a dedicated server does not initialize
|
||||
the client trait. `register(int)` still publishes the multipart factory before assigning and publishing the common
|
||||
class ID. Packet creation still passes `client = true`; NBT creation still passes `client = false`.
|
||||
|
||||
The common-class registry remains a fixed 256-entry array indexed by the signed high byte of the material ID. A
|
||||
duplicate registration still throws with the same message and leaves the first entry installed.
|
||||
|
||||
### ABI and reflection compatibility
|
||||
|
||||
The retained runtime types are exactly `MicroblockClass`, `CommonMicroClass`, and `CommonMicroClass$`. Their hierarchy,
|
||||
constructors, callable public names/descriptors, private fields and `@SideOnly` annotations match the Scala reference.
|
||||
The compiler-generated covariant `createPart` bridges retain the `TMultiPart` descriptors expected by
|
||||
`IPartFactory2`.
|
||||
|
||||
This identity is load-bearing: Schematica calls `MicroblockClass.create(boolean, int)` reflectively, while GuideNH
|
||||
matches `MicroblockGenerator$.create(MicroblockClass, int, boolean)` by exact parameter type. Both descriptors are
|
||||
unchanged. The `CommonMicroClass` static facade and `CommonMicroClass$.MODULE$` companion also remain available to
|
||||
downstream Scala and Java consumers.
|
||||
|
||||
Accepted classfile-only differences are removed Scala signature/marker attributes, removal of the private Scala
|
||||
`classId` accessor methods, and the companion class initializer without Scala's `ACC_PUBLIC` flag. The exact private
|
||||
`clientTraitId$lzycompute` method, `clientTraitId` field and `bitmap$0` field are deliberately retained.
|
||||
|
||||
### Compiler artifacts
|
||||
|
||||
No runtime class is added or removed; both clean jars contain the same three supported types.
|
||||
|
||||
### Validation
|
||||
|
||||
- `MicroblockClassCharacterizationTest`: 3 plain-JVM tests, unchanged from the Scala baseline.
|
||||
- Clean complete plain-JVM suite: 241 tests, 0 failures, 0 errors.
|
||||
- Java 8 Forge dedicated-server suite: 103 tests, 0 failures, 0 errors, including all five built-in factories and
|
||||
runtime-generated microblock classes.
|
||||
- Clean reference/port jars retain the same three types, and raw `javap` comparison confirms identical callable public
|
||||
names/descriptors and retained field/annotation shapes.
|
||||
- The real constructor cannot be initialized under the plain-JVM application class loader; exact generator calls are
|
||||
therefore frozen at the bytecode boundary and exercised end to end by the Forge suite.
|
||||
@@ -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`. 132 commits including the API-cleanup plan and separate characterization and
|
||||
port commits through `MicroblockRender`.
|
||||
Branch: `algent/java`. Base: `master`. 134 commits including the API-cleanup plan and separate characterization and
|
||||
port commits through `MicroblockClass`.
|
||||
|
||||
## 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: **238 plain-JVM tests and 103 Java 8 Forge dedicated-server tests passing.** The ignored local server
|
||||
Current baseline: **241 plain-JVM tests and 103 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.
|
||||
|
||||
@@ -270,7 +270,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.
|
||||
|
||||
162 Java files, 17 Scala files, ~3,285 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
165 Java files, 16 Scala files, ~3,234 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
|
||||
## What is left, and in what order
|
||||
|
||||
@@ -478,10 +478,15 @@ boundary. A clean compile proves Java retains `invokevirtual Microblock.setShape
|
||||
remain, while three private Scala anonymous/closure artifacts disappear. Actual OpenGL item/highlight output remains
|
||||
on the manual checklist.
|
||||
|
||||
**Medium.** `MicroblockClass.scala` is next. Freeze `MicroblockClass`, `CommonMicroClass`, the `CommonMicroClass$`
|
||||
singleton/array surface, factory creation paths and exact `MicroblockGenerator` calls before translating it. GuideNH
|
||||
matches `MicroblockGenerator$.create(MicroblockClass, int, boolean)` by exact parameter type, so the class identity and
|
||||
descriptor are load-bearing.
|
||||
`MicroblockClass`, `CommonMicroClass` and `CommonMicroClass$` are now Java. Three plain-JVM cases freeze their exact
|
||||
hierarchy, public/private shape, side annotations, common-class registry behavior and generator call descriptors. The
|
||||
Forge suite exercises eager base-trait registration, lazy client-trait avoidance on a dedicated server, all five
|
||||
built-in factories and generated parts. The three runtime class names and all callable public descriptors match the
|
||||
reference, including the GuideNH-pinned `MicroblockGenerator$.create(MicroblockClass, int, boolean)` boundary.
|
||||
|
||||
**High.** `Microblock.scala` is next. It is the shared transformed base for the face, hollow, edge and corner hierarchy,
|
||||
so freeze the exact trait/class hierarchy, state fields and accessors, NBT/shape behavior, generated interfaces and
|
||||
Scala-trait consumer paths before translating it. Do not combine it with a shape subclass or generator change.
|
||||
|
||||
**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
|
||||
|
||||
@@ -49,8 +49,8 @@ below its table.
|
||||
| --- | --- | --- | --- |
|
||||
| [ ] | Load the pack with ProjRed installed and place illumar lamp microblocks | The lamps generate, render and light correctly | `MicroblockGenerator.registerTrait` Scala trait path |
|
||||
| [ ] | Place and break OpenComputers, ProjectBlue and AE2 parts | No `NoSuchMethodError` or `AbstractMethodError` in the log | retained `$class` bridges |
|
||||
| [ ] | Load and render a schematic containing an ordered mixed multipart tile | Every part appears in the preview in the saved order; the integration does not silently disable itself | Schematica private registry-map reflection and tile NBT reconstruction |
|
||||
| [ ] | Open a GuideNH scene containing a multipart tile and export its part/material data | The preview, material data and part statistics are complete | companion reflection, `partList_$eq`, and `BlockMicroMaterial` mixin fields |
|
||||
| [ ] | Load and render a schematic containing an ordered mixed multipart tile | Every part appears in the preview in the saved order; the integration does not silently disable itself | Schematica private registry-map reflection, `MicroblockClass.create`, and tile NBT reconstruction |
|
||||
| [ ] | Open a GuideNH scene containing a multipart tile and export its part/material data | The preview, material data and part statistics are complete | companion reflection, `MicroblockGenerator$.create`, `partList_$eq`, and `BlockMicroMaterial` mixin fields |
|
||||
| [ ] | Place FMP buttons on every supported face with Et Futurum loaded | Button orientation matches the fixed vanilla behavior | reflected mutable `ButtonPart` side/meta arrays |
|
||||
| [ ] | Toggle an OpenComputers print that shares a block with another slotted part | Its slots are rebuilt without losing, hiding or disconnecting either part | external mutation of `TSlottedTile.v_partMap` plus `bindPart` |
|
||||
| [ ] | Move the same composite tile once through ForgeRelocationFMP and once through MatterManipulator | Coordinates, part-to-tile references, generated interfaces and rendering remain correct after `onMoved` | live multipart move lifecycle |
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package codechicken.microblock;
|
||||
|
||||
public final class CommonMicroClass$ {
|
||||
|
||||
public static final CommonMicroClass$ MODULE$ = new CommonMicroClass$();
|
||||
|
||||
private final CommonMicroClass[] classes = new CommonMicroClass[256];
|
||||
|
||||
private CommonMicroClass$() {}
|
||||
|
||||
public CommonMicroClass[] classes() {
|
||||
return classes;
|
||||
}
|
||||
|
||||
public CommonMicroClass getMicroClass(int modelId) {
|
||||
return classes[modelId >> 8];
|
||||
}
|
||||
|
||||
public void registerMicroClass(CommonMicroClass microClass, int id) {
|
||||
if (classes[id] != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Microblock class id " + id
|
||||
+ " is already taken by "
|
||||
+ classes[id].getName()
|
||||
+ " when adding "
|
||||
+ microClass.getName());
|
||||
}
|
||||
classes[id] = microClass;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package codechicken.microblock;
|
||||
|
||||
public abstract class CommonMicroClass extends MicroblockClass {
|
||||
|
||||
private int classId;
|
||||
|
||||
public static CommonMicroClass[] classes() {
|
||||
return CommonMicroClass$.MODULE$.classes();
|
||||
}
|
||||
|
||||
public static CommonMicroClass getMicroClass(int modelId) {
|
||||
return CommonMicroClass$.MODULE$.getMicroClass(modelId);
|
||||
}
|
||||
|
||||
public static void registerMicroClass(CommonMicroClass microClass, int id) {
|
||||
CommonMicroClass$.MODULE$.registerMicroClass(microClass, id);
|
||||
}
|
||||
|
||||
public int getClassId() {
|
||||
return classId;
|
||||
}
|
||||
|
||||
public abstract int itemSlot();
|
||||
|
||||
public abstract PlacementProperties placementProperties();
|
||||
|
||||
public void register(int id) {
|
||||
register();
|
||||
classId = id;
|
||||
CommonMicroClass$.MODULE$.registerMicroClass(this, id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package codechicken.microblock;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.MultiPartRegistry.IPartFactory2;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public abstract class MicroblockClass implements IPartFactory2 {
|
||||
|
||||
private final int baseTraitId;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private int clientTraitId;
|
||||
|
||||
private volatile boolean bitmap$0;
|
||||
|
||||
public MicroblockClass() {
|
||||
baseTraitId = MicroblockGenerator$.MODULE$.registerTrait(baseTrait());
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract Class<? extends Microblock> baseTrait();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract Class<? extends MicroblockClient> clientTrait();
|
||||
|
||||
public abstract float getResistanceFactor();
|
||||
|
||||
public int baseTraitId() {
|
||||
return baseTraitId;
|
||||
}
|
||||
|
||||
public int clientTraitId() {
|
||||
return bitmap$0 ? clientTraitId : clientTraitId$lzycompute();
|
||||
}
|
||||
|
||||
private int clientTraitId$lzycompute() {
|
||||
synchronized (this) {
|
||||
if (!bitmap$0) {
|
||||
clientTraitId = MicroblockGenerator$.MODULE$.registerTrait(clientTrait());
|
||||
bitmap$0 = true;
|
||||
}
|
||||
return clientTraitId;
|
||||
}
|
||||
}
|
||||
|
||||
public void register() {
|
||||
MultiPartRegistry.registerParts(this, getName());
|
||||
}
|
||||
|
||||
public Microblock create(boolean client, int material) {
|
||||
return MicroblockGenerator$.MODULE$.create(this, material, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Microblock createPart(String name, MCDataInput packet) {
|
||||
return create(true, MicroMaterialRegistry.readMaterialID(packet));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Microblock createPart(String name, NBTTagCompound nbt) {
|
||||
return create(false, MicroMaterialRegistry.materialID(nbt.getString("material")));
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package codechicken.microblock
|
||||
|
||||
import codechicken.multipart.MultiPartRegistry
|
||||
import codechicken.multipart.MultiPartRegistry.IPartFactory2
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import codechicken.lib.data.MCDataInput
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
|
||||
abstract class MicroblockClass extends IPartFactory2 {
|
||||
def getName: String
|
||||
def baseTrait: Class[_ <: Microblock]
|
||||
@SideOnly(Side.CLIENT)
|
||||
def clientTrait: Class[_ <: MicroblockClient]
|
||||
def getResistanceFactor: Float
|
||||
|
||||
val baseTraitId = MicroblockGenerator.registerTrait(baseTrait)
|
||||
@SideOnly(Side.CLIENT)
|
||||
lazy val clientTraitId = MicroblockGenerator.registerTrait(clientTrait)
|
||||
|
||||
def register() {
|
||||
MultiPartRegistry.registerParts(this, getName)
|
||||
}
|
||||
|
||||
def create(client: Boolean, material: Int) =
|
||||
MicroblockGenerator.create(this, material, client)
|
||||
override def createPart(name: String, packet: MCDataInput) =
|
||||
create(true, MicroMaterialRegistry.readMaterialID(packet))
|
||||
override def createPart(name: String, nbt: NBTTagCompound) =
|
||||
create(false, MicroMaterialRegistry.materialID(nbt.getString("material")))
|
||||
}
|
||||
|
||||
/** Microblocks with corresponding items
|
||||
*/
|
||||
abstract class CommonMicroClass extends MicroblockClass {
|
||||
private var classId: Int = _
|
||||
|
||||
def getClassId = classId
|
||||
def itemSlot: Int
|
||||
def placementProperties: PlacementProperties
|
||||
|
||||
def register(id: Int) {
|
||||
register()
|
||||
classId = id
|
||||
CommonMicroClass.registerMicroClass(this, id)
|
||||
}
|
||||
}
|
||||
|
||||
object CommonMicroClass {
|
||||
val classes = new Array[CommonMicroClass](256)
|
||||
|
||||
def getMicroClass(modelId: Int) = classes(modelId >> 8)
|
||||
|
||||
def registerMicroClass(mcrClass: CommonMicroClass, id: Int) {
|
||||
if (classes(id) != null)
|
||||
throw new IllegalArgumentException(
|
||||
"Microblock class id " + id + " is already taken by " + classes(
|
||||
id
|
||||
).getName + " when adding " + mcrClass.getName
|
||||
)
|
||||
|
||||
classes(id) = mcrClass
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user