From 3399a52202247b547c45097d32b786db78223654 Mon Sep 17 00:00:00 2001 From: Algent Date: Sat, 5 Sep 2026 14:00:24 +0200 Subject: [PATCH] feat: add staged Java tile generation --- JAVA_MIGRATION.md | 7 +- JAVA_MIGRATION_ABI_INVENTORY.md | 7 +- JAVA_MIGRATION_CONSUMER_AUDIT.md | 21 ++++- JAVA_MIGRATION_HANDOFF.md | 35 ++++---- docs/API.md | 1 + docs/api/COMPOSITE_GENERATION.md | 90 +++++++++++++++++++ docs/api/FACTORY_LOOKUP.md | 4 +- docs/api/PART_LOADING.md | 9 +- docs/migration/HISTORY.md | 25 ++++++ .../examples/CompositeGenerationExample.java | 31 +++++++ .../CompositeGenerationFunctionalTest.java | 43 +++++++++ .../multipart/MultipartGenerator$.java | 8 +- .../multipart/MultipartGenerator.java | 28 ++++++ ...ultipartGeneratorCharacterizationTest.java | 6 +- 14 files changed, 284 insertions(+), 31 deletions(-) create mode 100644 docs/api/COMPOSITE_GENERATION.md create mode 100644 src/functionalTest/java/codechicken/multipart/examples/CompositeGenerationExample.java diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index 41d297e..fb5bd80 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -684,7 +684,7 @@ does not close a row, and scans must distinguish a consumer's own Scala code fro | --- | --- | --- | --- | | ProjectRed | Runtime Scala-signature decoding and external trait registration, reached through `MicroblockGenerator.registerTrait(classOf[LightMicroblock])` | Rewrite the ~60-line `LightMicroblock` trait as a Java mixin registered through the `registerJavaTrait` path | FMP compiler prerequisites complete; consumer rewrite and release remain | | Schematica | Private Scala-mangled field `codechicken$multipart$MultiPartRegistry$$typeMap`, cast to `scala.collection.mutable.Map` | `MultiPartRegistry.getPartFactory(String)` is implemented; [guide and example](docs/api/FACTORY_LOOKUP.md). Schematica replaces map/Option lookup with the public method and retains its microblock creation/rejection policy | FMP lookup ready; consumer patch/release/adoption pending | -| GuideNH | Companion-only `MultipartGenerator$.MODULE$.generateCompositeTile` and `MicroblockGenerator$.create`; `partList_$eq(scala.collection.Seq)`; mixin into private `BlockMicroMaterial.block` and `.meta` | FMP exposes supported static entry points and `setPartList(List)`; GuideNH targets those and public material accessors | After step 1 and Phase 9.1 | +| GuideNH | Companion `MultipartGenerator$.MODULE$.generateCompositeTile` and `MicroblockGenerator$.create`; `partList_$eq(scala.collection.Seq)`; mixin into private `BlockMicroMaterial.block` and `.meta` | Static Java tile generation and `setPartList(List)` are implemented; [generation guide](docs/api/COMPOSITE_GENERATION.md). Validate/document the existing Java microblock creation entry and public material accessors next | Tile generation/loading ready; remaining reflection contracts and consumer adoption pending | | Et Futurum Requiem | Mutable static `int[] ButtonPart.metaSideMap` and `sideMetaMap` must stay public and mutable | FMP exposes a supported orientation-override API; Et Futurum uses it | After step 1 | | IguanaTweaksTConstruct | Private `ItemSaw.harvestLevel` field name and type | FMP exposes a supported harvest-level setter; Iguana uses it | After step 1 | | Galacticraft | Selects the first public method named `registerMaterial` without checking its signature, so FMP cannot add any overload of that name | Make the reflection check the parameter types | Immediately; independent of the port | @@ -735,7 +735,10 @@ UtilitiesInExcess's `extrautils:*` aliases; there is no legacy-conversion risk i - [ ] Add the supported public equivalents needed by Schematica, GuideNH, Et Futurum, and Iguana as additive API. - [x] Provide Schematica's registered-factory lookup without exposing the mutable map: `getPartFactory(String)`, with identity/missing-name checks, exact public reflection, a compiling example and the retained private field. - Client/server composite generation remains a separate Schematica/GuideNH gap; this does not complete either migration. + This does not complete Schematica's consumer migration. +- [x] Provide static Java client/server composite generation for Schematica and GuideNH, preserving exact reuse, + staged loading, input traversal/failure behavior and the old companion reflection path; [guide](docs/api/COMPOSITE_GENERATION.md). + GuideNH's separate microblock creation/material reflection and both consumers' release/adoption remain pending. - [ ] Patch those four consumers and record the released versions that no longer need the private shapes. - [ ] Track all legacy FMP dependencies in the adoption ledger, including trait helper/companion calls and reflection outside the cleanup table; verify the released jars actually selected for the target pack. diff --git a/JAVA_MIGRATION_ABI_INVENTORY.md b/JAVA_MIGRATION_ABI_INVENTORY.md index 9aceaf6..d93e528 100644 --- a/JAVA_MIGRATION_ABI_INVENTORY.md +++ b/JAVA_MIGRATION_ABI_INVENTORY.md @@ -190,7 +190,7 @@ method on it. So for most entries the companion is a fallback. The exceptions be | --- | --- | --- | | `MultipartHelper` | `createTileFromNBT(World, NBTTagCompound)` | static; companion is fallback | | `MultipartRenderer` | `renderWorldBlock(IBlockAccess, int, int, int, Block, int, RenderBlocks)` | static; companion is fallback | -| `MultipartGenerator` | `generateCompositeTile(TileEntity, Iterable, boolean)` | **companion only** — see below | +| `MultipartGenerator` | `generateCompositeTile(TileEntity, scala.collection.Iterable, boolean)` | **companion only for the Scala descriptor**; new static Java-Iterable entry is additive | | `BlockMicroMaterial` | `register(material)`, plus a constructor of arity 2 `(Block, int)` or 1 `(Block)` | static; companion is fallback | | `MicroMaterialRegistry` | `getMaterial(int)` | static; companion is fallback | | `MicroblockGenerator$` | `create(MicroblockClass, int, boolean)` | **companion only**, matched by exact parameter types | @@ -209,6 +209,11 @@ Types used only for `isInstanceOf`: `BlockMultipart`, `TileMultipart`, `TileMult reaches the method only through the companion. A Phase 6/7 port that keeps the class but drops the companion, or promotes the method to a public static and removes it from the companion, breaks guidenh silently. + The branch now adds `MultipartGenerator.generateCompositeTile(TileEntity, java.lang.Iterable, boolean)` while + retaining the exact companion Scala descriptor/body. GuideNH's old Scala sequence is not assignable to the new + Java parameter, so its existing matcher still falls back to the companion. Both old and new reflective contracts + are tested; migration requires a Java parts collection. See the [guide](docs/api/COMPOSITE_GENERATION.md). + 2. **`MicroblockGenerator$.create` is matched by exact parameter types**, including `pts[0].getName()` string-compared against `"codechicken.microblock.MicroblockClass"`. That pins `create(MicroblockClass, int, boolean)` on the companion and pins `MicroblockClass`'s fully qualified name. Widening a parameter or renaming the class breaks the diff --git a/JAVA_MIGRATION_CONSUMER_AUDIT.md b/JAVA_MIGRATION_CONSUMER_AUDIT.md index 02154c1..d68c322 100644 --- a/JAVA_MIGRATION_CONSUMER_AUDIT.md +++ b/JAVA_MIGRATION_CONSUMER_AUDIT.md @@ -320,7 +320,8 @@ reflective to keep the integration optional. - It reflects `MultipartHelper.createTileFromNBT`, `MultipartRenderer.renderWorldBlock`, material registration and construction, registry lookup, tile part-list getters/setters, `loadParts`, `notifyTileChange`, `markRender`, microblock properties, and part drops. -- `MultipartGenerator$.MODULE$.generateCompositeTile(TileEntity, Iterable, boolean)` is companion-only. +- `MultipartGenerator$.MODULE$.generateCompositeTile(TileEntity, scala.collection.Iterable, boolean)` remains + companion-only for that descriptor; a static Java-Iterable entry is now available. - `MicroblockGenerator$.create(MicroblockClass, int, boolean)` is companion-only and matched by exact parameter classes. - Client preview promotion replaces parts with client microblock instances, assigns @@ -359,7 +360,8 @@ The branch now provides `MultiPartRegistry.getPartFactory(String)` as the suppor It returns the exact registered factory or null without construction or missing-name logging. Schematica can reflect this public static method and continue invoking `MicroblockClass.create(client, materialId)` on the returned object; `loadPart` would incorrectly choose the server factory path for its client preview. The old private field remains. -See the [guide](docs/api/FACTORY_LOOKUP.md); consumer patch, generator migration and pack adoption remain pending. +See the [guide](docs/api/FACTORY_LOOKUP.md) and the now-available [Java tile generator](docs/api/COMPOSITE_GENERATION.md); +consumer patches and pack adoption remain pending. ### UtilitiesInExcess — future replacement, already a substantial consumer @@ -513,8 +515,9 @@ tied to a released minimum dependency version. Unlisted contracts remain governe | `TileMultipart.partList(): scala.collection.Seq` | AE2 `87f2b3817c2a`: `FMPPlacementHelper.getPart` and `removePart` | Iterate `jPartList()`; retain last-match lookup and removal/break behavior | Source patch and release pending | No migrated pack version verified; retain the getter | | `TileMultipart.partList(): scala.collection.Seq` | Extra Utilities 1.2.12: multipart renderer iterators | Iterate `jPartList()` without adding detached-part filtering | Retirement/replacement pending | Confirm absence or migration in the target pack before retiring the getter | | `TileMultipart.partList(): scala.collection.Seq` plus reflective getter/setter/loading | GuideNH `7d8fb44e77b9`: `Ae2ForgeMultipartBridge`, `ForgeMultipartHelpers` | `jPartList()` for reads, `setPartList(List)` for staging, `loadPartList(Collection)` for binding/cache reconstruction | Source patch and release pending; preserve world/position setup and following tile/render notifications | Retain the legacy getter/setter/loader until adoption; companion-only generator migration is separate | -| `TileMultipart.loadParts(scala.collection.Iterable)` exact reflection | Schematica `3b03ee937953`: `nbt.ForgeMultipart` | Reflect `loadPartList(Collection.class)` and pass its existing Java part list directly | Source patch and release pending; registry lookup now available separately, generator reflection remains pending | No migrated pack version verified; retain the Scala loader descriptor | -| Private `MultiPartRegistry$` Scala `typeMap` field and `Map.get` / `Option` | Schematica `3b03ee937953`: `nbt.ForgeMultipart.init` and `createPart` | Reflect public static `MultiPartRegistry.getPartFactory(String.class)`; keep material lookup, `MicroblockClass.create(client, materialId)` and whole-preview rejection | Source patch/release pending; public FMP lookup implemented, generator migration remains separate | No migrated pack version verified; retain the exact private live Scala-map field | +| `TileMultipart.loadParts(scala.collection.Iterable)` exact reflection | Schematica `3b03ee937953`: `nbt.ForgeMultipart` | Reflect `loadPartList(Collection.class)` and pass its existing Java part list directly | Source patch and release pending; registry lookup and Java tile generation available separately | No migrated pack version verified; retain the Scala loader descriptor | +| Private `MultiPartRegistry$` Scala `typeMap` field and `Map.get` / `Option` | Schematica `3b03ee937953`: `nbt.ForgeMultipart.init` and `createPart` | Reflect public static `MultiPartRegistry.getPartFactory(String.class)`; keep material lookup, `MicroblockClass.create(client, materialId)` and whole-preview rejection | Source patch/release pending; lookup and Java tile generation implemented | No migrated pack version verified; retain the exact private live Scala-map field | +| `MultipartGenerator$.generateCompositeTile(TileEntity, scala.collection.Iterable, boolean)` | Schematica `3b03ee937953` exact reflection; GuideNH `7d8fb44e77b9` static-first assignability matcher | Static `MultipartGenerator.generateCompositeTile(TileEntity, java.lang.Iterable, boolean)` with Java parts; retain subsequent state setup/loading | Source patches/releases pending; preserve client part construction, candidate-reuse branch and notification order | No migrated pack version verified; retain the companion and Scala descriptor | | `NormalOcclusionTest$.apply(Traversable, Traversable)` | OpenComputers `2c00f79be24b`: `common.block.Cable.canConnectFromSideFMP`, `server.network.Network.canConnectFromSideFMP` | `NormalOcclusionTest.testBoxes(ownBounds.asJava, otherBounds)`; `otherBounds` already comes from Java `getOcclusionBoxes()` | Source patch and release pending; retain side/color/face filtering | No migrated pack version verified; retain the companion and descriptor | | `NormalOcclusionTest$.apply(Traversable, Traversable)` | ForgeRelocationFMP `49a810b8c63b`: `FramePart.occlusionTest` | `NormalOcclusionTest.testBoxes(boxes.asJava, getOcclusionBoxes)`; retain combined normal/partial/collision boxes and caller order | Source patch and release pending; preserve temporary face bounds and replacement protocol | No migrated pack version verified; retain the companion and descriptor | @@ -615,6 +618,16 @@ All 567 archived JVM tests and the byte-identical archived Forge mod's 256 cases `+719` scan retains all 386 member/type/reflection rows across 27 consumers. The private map retains its exact binary shape and live backing. Reference checkouts remain unchanged. Evidence: `run/migration-factory-lookup-reference/`. +Staged tile generation is available through static `MultipartGenerator.generateCompositeTile(TileEntity, +java.lang.Iterable, boolean)`. The adapter passes a view to the unchanged companion method, now deprecated +for callers. Both sides, exact candidate reuse, empty/duplicate input, no implicit copying/loading/installation, +input traversal and failures are characterized. Old exact reflection and GuideNH's Scala-argument fallback still work; +Java reflection and the example compile/use the Java parameter. The `+719` scan retains all 386 rows across 27 consumers. +Archived validation runs 567 JVM tests (one obsolete exact facade inventory assertion excluded) and all 261 archived +Forge tests; the full current suite and independent ABI comparison check the intentional method addition. Client tile +generation/worldless loading is covered, while physical-client microblock construction and GPU previews remain manual. +Reference checkouts and consumer adoption remain unchanged. Evidence: `run/migration-composite-generation-reference/`. + ## Practical priority for the current branch 1. Keep the existing `+678` ABI fixture as the exact binary floor and correct failures before source cleanup. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index d91b75f..91eacd8 100644 --- a/JAVA_MIGRATION_HANDOFF.md +++ b/JAVA_MIGRATION_HANDOFF.md @@ -17,7 +17,7 @@ migration checkout; `codex/tile-compatibility-fixes` was deleted after its fixes ## Current state and next target -**568 plain-JVM tests and 258 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **225 Java +**568 plain-JVM tests and 265 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **225 Java files and 9 Scala files / 747 nonblank Scala lines**. The packaged inventory has 444 classes. Review follow-up: restored packet-scheduler callback mutation behavior with the original Scala hash-map traversal, @@ -32,16 +32,17 @@ use, but no override triggering these three regressions was found. All 443 class payloads and 116 generated dumps are retained. The agreed next milestone is the documented consumer-facing Java API, followed by consumer release/adoption and final Scala removal; see the plan's API migration design and Phases 8–10. -Latest API addition: `MultiPartRegistry.getPartFactory(String)` returns the exact registered factory or null without -constructing a part. One JVM and one Forge baseline case were committed first as `2a52980`; one further JVM and two -Forge cases cover the Java entry, exact public reflection and compiling example. Schematica can replace its private -map/Scala Option lookup while retaining `MicroblockClass.create(client, materialId)`. The old private live Scala-map -field and all existing method bodies remain unchanged. All 567 frozen JVM tests and the archived Forge mod's 256 cases -pass against the addition. All 444 class APIs, 17 ScalaSignature payloads, 3,759 existing method bodies and 116 generated -dumps remain; exactly one public static method is added. The example compiles without Scala. Dedicated-server tests -cover server microblock construction; physical-client creation/preview rendering remain manual because Forge strips -the client's `clientTrait()` method on the server. -Evidence: `run/migration-factory-lookup-reference/`; [guide](docs/api/FACTORY_LOOKUP.md). +Latest API addition: static `MultipartGenerator.generateCompositeTile(TileEntity, java.lang.Iterable, +boolean)` exposes staged client/server generation. Three Forge baseline cases were committed first as `ab5654b`; +four more cases cover the Java entry, exact reflection and a compiling setup/loading example. Exact reuse, no implicit +state copying/loading/installation, input traversal and failures remain unchanged. Both consumers' old Scala reflection +paths still work; the companion entry retains its descriptor/body with deprecation. Of 568 archived JVM tests, 567 pass; +one obsolete exact facade inventory assertion is excluded, updated in the full current suite and supplemented +by the independent ABI comparison. All 261 archived Forge cases pass without recompilation. All 444 class APIs, +17 ScalaSignature payloads, 3,760 existing method bodies and 116 generated dumps remain, with one public static entry +and one deprecation added. The example compiles without Scala. Client tile generation/worldless loading are covered; +physical-client microblock construction and GPU previews remain manual. +Evidence: `run/migration-composite-generation-reference/`; [guide](docs/api/COMPOSITE_GENERATION.md). Naming correction: the planned `loadParts(Collection)` overload made javac require `scala.collection.Iterable` even for Java arguments. The distinct `loadPartList` name allows compilation without Scala on the example's classpath. @@ -60,14 +61,14 @@ adoption remain pending. Checkouts remain reference-only. The installed `+719` p Java surface; supply missing capabilities, precise contracts, migration guidance and compiling examples. Cover subclass/override behavior and generated extensions as well as ordinary calls. ProjectRed's illuminated microblocks are the representative external extension case. Consumer mods may remain Scala internally while adopting this API. -The next bounded candidate is a supported Java client/server composite-tile generation entry for Schematica and -GuideNH. Read their exact companion-only `generateCompositeTile` calls and the existing `MultipartHelper` helpers; -`createTileFromParts` currently creates a server tile and loads it immediately, which is not their staged contract. -Characterize generation, reuse, side selection and caller-owned loading before adding the smallest missing Java -entry. The representative external Java extension and internal-boundary documentation remain separate work. +The next bounded candidate is GuideNH's microblock creation contract: document and validate the existing static +`MicroblockGenerator.create(MicroblockClass, int, boolean)` as the replacement for its exact companion reflection. +Reuse that Java entry rather than adding a second one. Trace material-provided traits, side selection, class/factory +identity and caller-owned NBT loading, with a compiling example and explicit physical-client limits. The representative +external Java extension, private-material access migration and internal-boundary documentation remain separate work. Progress: all ten Phase 9.1 table rows now have implemented/documented Java replacements, plus the separate Schematica -registry lookup. Remaining work includes generator/reflection replacements, extension examples and internal-boundary +registry lookup and staged Java tile generation. Remaining work includes microblock/reflection guidance, extension examples and internal-boundary documentation. Then consumer patches, releases and pack adoption must precede final Scala removal and client/pack release validation; it is not a percentage of the whole migration. diff --git a/docs/API.md b/docs/API.md index 5ec3a1f..099a4d3 100644 --- a/docs/API.md +++ b/docs/API.md @@ -18,6 +18,7 @@ without converting the rest of its code to Java. | Read/index/search a tile's parts | `jPartList()` — [part collection ownership and order](api/PART_TRAVERSAL.md#collection-ownership-and-ordering) | | Run callbacks while skipping detached parts | `forEachPart(Consumer)` — [callback and override behavior](api/PART_TRAVERSAL.md#callback-behavior) | | Rebuild parts on an already prepared composite tile | `loadPartList(Collection)` — [part loading](api/PART_LOADING.md) | +| Select client/server tile capabilities before preparing state and loading | `MultipartGenerator.generateCompositeTile(TileEntity, Iterable, boolean)` — [staged generation and reflection migration](api/COMPOSITE_GENERATION.md) | | Assign stored parts during reconstruction, without binding or notifications | `setPartList(List)` — [storage assignment](api/PART_LOADING.md#storage-assignment) | | Test a candidate against a selected collection of parts | `testOcclusion(Collection, candidate)` — [occlusion queries and generated hooks](api/OCCLUSION.md) | | Test two groups of bounding boxes directly | `NormalOcclusionTest.testBoxes(Iterable, Iterable)` — [box-versus-box queries](api/OCCLUSION.md#box-versus-box-queries) | diff --git a/docs/api/COMPOSITE_GENERATION.md b/docs/api/COMPOSITE_GENERATION.md new file mode 100644 index 0000000..f1516cc --- /dev/null +++ b/docs/api/COMPOSITE_GENERATION.md @@ -0,0 +1,90 @@ +# Staged composite-tile generation + +[Java API index](../API.md) + +`MultipartGenerator.generateCompositeTile(TileEntity, java.lang.Iterable, boolean)` selects a tile's +generated capabilities without loading its parts. It is available on `algent/java`, with no minimum published +dependency version yet. The [compiling example](../../src/functionalTest/java/codechicken/multipart/examples/CompositeGenerationExample.java) +then assigns world/position and loads the same parts, leaving installation to its caller. It compiles without Scala. + +```java +TileMultipart prepared = MultipartGenerator.generateCompositeTile(candidate, parts, client); +// Prepare world, coordinates and any required tile NBT before loading. +prepared.loadPartList(parts); +``` + +Use a `List` or another repeatable collection when the same parts will subsequently be loaded. Generation +accepts `Iterable`; loading accepts `Collection`. A one-shot iterable can select traits, but +cannot then supply the same parts again. The generator reads the input once on every call, including candidate reuse, +without copying it. Do not mutate it during generation or change the required capabilities between generation and loading. + +## Selection and ownership + +| Candidate and required traits | Result | +| --- | --- | +| Null or a non-multipart tile | A fresh empty generated tile | +| Registered multipart class with exactly the required trait set | The same tile, with all existing state untouched | +| Registered multipart class with a different trait set or side | A fresh empty replacement; the candidate remains untouched | +| Multipart class unknown to the generator | `NoSuchElementException`, after reading the parts | + +An empty iterable is valid and chooses the side's base tile. Order and duplicate parts do not add extra copies of a +trait, but each input entry is visited. The generator caches constructed classes; fresh tiles are still distinct objects. + +Generation does not load or bind parts, assign world/position, copy source state, invalidate an old tile, install a +replacement or send notifications. New tiles have empty part storage and caches. Existing part-to-tile bindings remain +until the caller loads/rebinds them; loading a replacement does not clear the old tile's stored list. + +Call after trait registration on the initialization/game thread. Trait selection uses existing caches and scratch +state. Iterator exceptions, null inputs/elements and unregistered-class failures propagate without rollback of that +internal state. Generation is neither a placement check nor a transaction for replacing a live tile. + +## Side and loading lifecycle + +`client=true` selects client tile capabilities. It does not turn server parts into client part variants; supply the +correctly constructed parts yourself. The world assigned for loading must agree with the intended side. The example +also allows null for explicitly worldless staging, which omits world-dependent loading callbacks. + +Prepare position, world and any required tile NBT before [loading](PART_LOADING.md). With a world, the default loader +notifies parts and neighbors and updates lighting; a client world also triggers `onWorldJoin`. Preserve the integration's +subsequent installation, tile/render notifications and synchronization. Do not add them blindly to a worldless preview. + +For ordinary world placement use `TileMultipart.canPlacePart` / `addPart`. For immediate server construction and +loading, the existing `MultipartHelper.createTileFromParts` remains supported. It is not a substitute for consumers +that must set state between generation and loading. + +## Schematica and GuideNH migration + +The public static method can be resolved with: + +```java +Method generate = MultipartGenerator.class.getMethod( + "generateCompositeTile", TileEntity.class, java.lang.Iterable.class, boolean.class); +TileMultipart tile = (TileMultipart) generate.invoke(null, candidate, parts, client); +``` + +An optional integration can obtain the owner through `Class.forName("codechicken.multipart.MultipartGenerator")`. +Pass a Java list directly and cache the method during integration initialization. + +- **Schematica:** remove `JavaConversions.collectionAsScalaIterable` from generation; keep material resolution, + [factory lookup](FACTORY_LOOKUP.md), side-specific microblock construction, per-part NBT loading and rejection when + any part is missing. Preserve its following tile `readFromNBT`, `loadPartList(parts)` and per-part notification order. +- **GuideNH:** keep promotion of parts to their client variants, then use a Java list for generation. Preserve its + same-instance branch, copying of coordinates/world/block state, storage assignment where required, loading, + `notifyTileChange` and `markRender`. Generation does not perform any of those steps automatically. + +The old companion's `generateCompositeTile(TileEntity, scala.collection.Iterable, boolean)` keeps its descriptor and +body, deprecated for callers in favor of the static Java entry. Existing internal calls remain unchanged. GuideNH's +argument-assignability matcher still rejects the Java parameter for a Scala sequence and falls back to the companion; +Schematica's exact old reflective lookup remains valid. Consumer source patches/releases and pack adoption remain pending. +GuideNH's separate microblock-generator and private-material dependencies are not closed by this tile API. + +## Validation + +Forge characterization covers client/server tile selection, exact reuse, empty input, duplicates, unbound generation, +source-state retention, subsequent loading, one input traversal, failure propagation, and old/new reflection. +The example covers server-world setup and worldless client-tile loading. An exact JVM API inventory includes the new +method; the archived run excludes only its obsolete pre-addition inventory assertion. The remaining archived JVM tests +and all archived Forge cases run against the addition, with an independent class/member/body comparison. + +Generating a client tile in the Forge server harness does not prove physical-client microblock creation or GPU output. +Schematica and GuideNH preview rendering remain [manual release checks](../../JAVA_MIGRATION_MANUAL_CHECKS.md). diff --git a/docs/api/FACTORY_LOOKUP.md b/docs/api/FACTORY_LOOKUP.md index 61be2c4..2abb502 100644 --- a/docs/api/FACTORY_LOOKUP.md +++ b/docs/api/FACTORY_LOOKUP.md @@ -54,8 +54,8 @@ Not every registered factory is a microblock class: keep the existing rejection the reflected microblock class's `isInstance(factory)` explicitly before invoking. Do not silently produce a partial preview. This removes the registry-map Scala dependency. It does not finish Schematica's migration: use the -[Java loading API](PART_LOADING.md#overrides-and-reflection) for its part collection, and retain the companion generator -call until a supported Java client/server composite-generation entry is provided. Material lookup, saved part order, +[Java loading API](PART_LOADING.md#overrides-and-reflection) for its part collection and the +[static Java composite generator](COMPOSITE_GENERATION.md). Material lookup, saved part order, shape/material loading, tile NBT and subsequent notifications remain unchanged. The private `MultiPartRegistry$.codechicken$multipart$MultiPartRegistry$$typeMap` field keeps its exact name, modifiers, diff --git a/docs/api/PART_LOADING.md b/docs/api/PART_LOADING.md index 54a0909..e3aafaa 100644 --- a/docs/api/PART_LOADING.md +++ b/docs/api/PART_LOADING.md @@ -10,6 +10,9 @@ These are reconstruction operations, not normal placement/removal. Use `TileMult changes. Use `MultipartHelper.createTileFromParts(Iterable)` to construct a new server composite tile; the loader itself does not choose traits, promote a tile or install it in the world. +For separate client/server generation before world/NBT setup and loading, use the +[staged composite-generation API](COMPOSITE_GENERATION.md). + ## Loading a prepared tile To rebuild a tile using its existing parts, capture them before the loader clears the tile: @@ -84,9 +87,9 @@ hook and its name. This changes the planned Java name, not any existing entry po For GuideNH's migration, use a Java list of the promoted client parts, retain its existing world/position setup, replace the raw setter with `setPartList`, and call the Collection loader. Preserve its following `notifyTileChange` -and `markRender` steps. This does not replace its companion-only generator or other reflective dependencies. -Schematica can select the Collection loader and pass its existing Java list directly; its Scala map and generator -reflection need separate migration. +and `markRender` steps. Its tile generator now has a [static Java replacement](COMPOSITE_GENERATION.md); other +reflective dependencies remain. Schematica can select the Collection loader and pass its existing Java list directly, +using the separate [factory lookup](FACTORY_LOOKUP.md) and generation entries to remove those Scala dependencies. ## Validation and release gates diff --git a/docs/migration/HISTORY.md b/docs/migration/HISTORY.md index 02173c5..46429dd 100644 --- a/docs/migration/HISTORY.md +++ b/docs/migration/HISTORY.md @@ -1922,3 +1922,28 @@ differences belong in the [divergence ledger](../../JAVA_MIGRATION_DIVERGENCES.m claimed. Next bounded task is Java client/server composite generation for Schematica and GuideNH; loading, material/shape restoration, all-parts rejection and notifications must retain their staged lifecycle. Evidence: `run/migration-factory-lookup-reference/`. + +### 2026-09-05 — Staged Java composite-tile generation + +- Traced Schematica and GuideNH generation followed by their distinct NBT/world/position/loading/notification steps. + `MultipartHelper.createTileFromParts` constructs and loads a server tile immediately, so it cannot replace their + staged client paths. Added static `MultipartGenerator.generateCompositeTile(TileEntity, Iterable, boolean)` + through a Java iterable view over the existing companion behavior; no snapshot or new generation logic. +- Committed three Forge characterization cases first as `ab5654b`, preserving the reference jar, sources, compiled + fixtures, reports and dumps. Both tile sides, exact reuse, capability changes, empty/duplicate inputs, no implicit + loading/copying/invalidation, iterator evaluation/failures and exact companion reflection are covered. +- Four additional Forge cases exercise the Java entry, public reflection and staged world/coordinate setup followed + by loading. The example compiles without Scala. GuideNH's old Scala argument does not match the new Java parameter, + retaining its companion fallback; Schematica's old exact descriptor remains. The companion method is deprecated, + with its body and internal callers unchanged. +- The JVM facade inventory initially rejected the intentional new public method; updated its exact expected set, + leaving the companion set unchanged. Archived validation excludes only that obsolete inventory assertion, running + the remaining 567 JVM cases and all 261 cases from the byte-identical archived Forge mod. Full normal/clean suites + pass with 568 JVM and 265 Forge tests, zero failures/errors/skips. An independent class/member comparison verifies + all 444 old class APIs with precisely one added static entry and one deprecation. All 17 ScalaSignature payloads, + 3,760 existing method bodies and 116 generated dumps remain apart from expected metadata/build versions. +- Added the generation guide, Java/reflection examples and consumer adoption ledger entry, and linked the loading + and factory guides. The `+719` scan retains all 386 member/type/reflection rows across 27 consumers. Checkouts remain + reference-only and releases/adoption are pending. Client tile generation/worldless loading are tested; actual client + microblock construction and preview rendering remain manual. Next bounded task: GuideNH's existing Java microblock + creation entry and its documented contract. Evidence: `run/migration-composite-generation-reference/`. diff --git a/src/functionalTest/java/codechicken/multipart/examples/CompositeGenerationExample.java b/src/functionalTest/java/codechicken/multipart/examples/CompositeGenerationExample.java new file mode 100644 index 0000000..2cff7fc --- /dev/null +++ b/src/functionalTest/java/codechicken/multipart/examples/CompositeGenerationExample.java @@ -0,0 +1,31 @@ +package codechicken.multipart.examples; + +import java.util.List; + +import net.minecraft.world.World; + +import codechicken.lib.vec.BlockCoord; +import codechicken.multipart.MultipartGenerator; +import codechicken.multipart.TMultiPart; +import codechicken.multipart.TileMultipart; + +/** Forge-tested compiling example for docs/api/COMPOSITE_GENERATION.md. */ +public final class CompositeGenerationExample { + + private CompositeGenerationExample() {} + + /** + * Prepares and loads a fresh tile without installing it. Parts must already be loaded and appropriate for the + * requested side. A supplied world must agree with that side; null is allowed for worldless staging. + */ + public static TileMultipart createUninstalledTile(World world, BlockCoord pos, List parts, + boolean client) { + TileMultipart tile = MultipartGenerator.generateCompositeTile(null, parts, client); + tile.xCoord = pos.x; + tile.yCoord = pos.y; + tile.zCoord = pos.z; + tile.setWorldObj(world); + tile.loadPartList(parts); + return tile; + } +} diff --git a/src/functionalTest/java/codechicken/multipart/test/CompositeGenerationFunctionalTest.java b/src/functionalTest/java/codechicken/multipart/test/CompositeGenerationFunctionalTest.java index 8fefc87..2570680 100644 --- a/src/functionalTest/java/codechicken/multipart/test/CompositeGenerationFunctionalTest.java +++ b/src/functionalTest/java/codechicken/multipart/test/CompositeGenerationFunctionalTest.java @@ -17,19 +17,62 @@ import java.util.concurrent.atomic.AtomicInteger; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; import org.junit.jupiter.api.Test; +import codechicken.lib.vec.BlockCoord; import codechicken.multipart.MultipartGenerator; import codechicken.multipart.MultipartGenerator$; import codechicken.multipart.TMultiPart; import codechicken.multipart.TileMultipart; import codechicken.multipart.TileMultipartClient; +import codechicken.multipart.examples.CompositeGenerationExample; import codechicken.multipart.scalatraits.TSlottedTile; import scala.collection.JavaConversions; class CompositeGenerationFunctionalTest { + @Test + void javaGenerationSelectsCapabilitiesWithoutLoadingOrCopyingTiles() { + checkStaging(MultipartGenerator::generateCompositeTile); + } + + @Test + void javaGenerationReadsInputOnceAndPropagatesFailuresBeforeReuse() { + checkInput(MultipartGenerator::generateCompositeTile); + } + + @Test + void javaExactReflectionAcceptsJavaParts() throws Exception { + Method method = MultipartGenerator.class + .getMethod("generateCompositeTile", TileEntity.class, Iterable.class, boolean.class); + TileMultipart tile = (TileMultipart) method.invoke(null, null, Collections.emptyList(), true); + assertTrue(tile instanceof TileMultipartClient); + assertSame(tile, method.invoke(null, tile, Collections.emptyList(), true)); + assertNull(tile.getWorldObj()); + assertTrue(tile.jPartList().isEmpty()); + } + + @Test + void javaExamplePreparesWorldAndCoordinatesBeforeLoadingWithoutInstallation() { + for (boolean client : new boolean[] { false, true }) { + World world = client ? null : MinecraftServer.getServer().worldServers[0]; + BlockCoord pos = new BlockCoord(78, 200, 48); + TileEntity installed = world == null ? null : world.getTileEntity(pos.x, pos.y, pos.z); + TMultiPart part = new MultipartGeneratorFunctionalTest.SlottedPart(); + List parts = Collections.singletonList(part); + TileMultipart tile = CompositeGenerationExample.createUninstalledTile(world, pos, parts, client); + assertEquals(client, tile instanceof TileMultipartClient); + assertSame(world, tile.getWorldObj()); + assertEquals(pos, new BlockCoord(tile)); + assertSame(tile, part.tile()); + assertSame(part, tile.partMap(3)); + assertEquals(parts, tile.jPartList()); + if (world != null) assertSame(installed, world.getTileEntity(pos.x, pos.y, pos.z)); + } + } + @Test void legacyGenerationSelectsCapabilitiesWithoutLoadingOrCopyingTiles() { checkStaging(CompositeGenerationFunctionalTest::legacyGenerate); diff --git a/src/main/scala/codechicken/multipart/MultipartGenerator$.java b/src/main/scala/codechicken/multipart/MultipartGenerator$.java index d4f61c7..447d108 100644 --- a/src/main/scala/codechicken/multipart/MultipartGenerator$.java +++ b/src/main/scala/codechicken/multipart/MultipartGenerator$.java @@ -148,7 +148,13 @@ public final class MultipartGenerator$ implements ScratchBitSet { if (chunk != null) chunk.func_150812_a(pos.x & 15, pos.y, pos.z & 15, tile); } - /** Reuses the tile only when it has exactly the interfaces required by the parts. */ + /** + * Reuses the tile only when it has exactly the interfaces required by the parts. + * + * @deprecated Use {@link MultipartGenerator#generateCompositeTile(TileEntity, java.lang.Iterable, boolean)} with + * Java parts. Retained for compiled callers and exact Scala-parameter reflection. + */ + @Deprecated public TileMultipart generateCompositeTile(TileEntity tile, Iterable parts, boolean client) { BitSet bitset = setTraits(parts, client); if (tile instanceof TileMultipart && bitset.equals(tileTraitMap.apply(tile.getClass()))) { diff --git a/src/main/scala/codechicken/multipart/MultipartGenerator.java b/src/main/scala/codechicken/multipart/MultipartGenerator.java index 6d7e174..e5bfce0 100644 --- a/src/main/scala/codechicken/multipart/MultipartGenerator.java +++ b/src/main/scala/codechicken/multipart/MultipartGenerator.java @@ -6,6 +6,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import codechicken.lib.vec.BlockCoord; +import scala.collection.JavaConversions; /** * Manages dynamic construction of multipart container tiles. Register a mixin against a part's marker interface to add @@ -16,6 +17,33 @@ public final class MultipartGenerator { private MultipartGenerator() {} + /** + * Selects a composite tile with exactly the capabilities required by the supplied parts and side. Reuses a + * registered multipart tile only when its trait set matches exactly; otherwise returns a fresh empty tile. A null + * or non-multipart candidate is allowed. An unregistered multipart subclass throws NoSuchElementException. + * + *

+ * This is generation only: no parts are loaded/bound, no world or position is assigned, no state is copied, no + * previous tile is invalidated and no tile is installed in a world. A reused tile retains all its existing state. + * The caller prepares world/position or NBT state before {@link TileMultipart#loadPartList(java.util.Collection)} + * and owns any subsequent installation and notifications. For ordinary placement use + * {@link TileMultipart#addPart(World, BlockCoord, TMultiPart)} instead. + * + *

+ * Reads the iterable once per call, including reuse, without a snapshot. Do not mutate it during generation; retain + * a repeatable collection for later loading. Null inputs/elements and iterator failures propagate through the + * existing generator, without rollback of its scratch state or caches. Call on the initialization/game thread after + * trait registration. Client tile selection does not convert server parts into client part variants. + * + * @param tile candidate for exact reuse, or null for a fresh tile + * @param parts parts whose capabilities select the tile; use these same parts for subsequent loading + * @param client true for a client tile, false for a server tile + */ + public static TileMultipart generateCompositeTile(TileEntity tile, Iterable parts, boolean client) { + return MultipartGenerator$.MODULE$ + .generateCompositeTile(tile, JavaConversions.iterableAsScalaIterable(parts), client); + } + public static BitSet getBitSet() { return MultipartGenerator$.MODULE$.getBitSet(); } diff --git a/src/test/java/codechicken/multipart/MultipartGeneratorCharacterizationTest.java b/src/test/java/codechicken/multipart/MultipartGeneratorCharacterizationTest.java index 03634f8..b4d5a94 100644 --- a/src/test/java/codechicken/multipart/MultipartGeneratorCharacterizationTest.java +++ b/src/test/java/codechicken/multipart/MultipartGeneratorCharacterizationTest.java @@ -36,7 +36,11 @@ class MultipartGeneratorCharacterizationTest { @Test void keepsExactFacadeCompanionAndScalaMapSurfaceWithoutInitializingForge() throws Exception { - assertEquals(FACADE, publicMethods(MultipartGenerator.class)); + Set facade = new TreeSet<>(FACADE); + facade.add( + "generateCompositeTile(Lnet/minecraft/tileentity/TileEntity;Ljava/lang/Iterable;Z)" + + "Lcodechicken/multipart/TileMultipart;"); + assertEquals(facade, publicMethods(MultipartGenerator.class)); Set companion = new TreeSet<>(FACADE); companion.addAll( signatures(