mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-27 23:45:52 +00:00
docs: define direct Java material access
This commit is contained in:
1 parent
079739ea80
commit
37d5ea98f6
13 files changed
+311
-31
No files matched your search
@@ -54,7 +54,9 @@ that must set state between generation and loading.
|
||||
|
||||
## Schematica and GuideNH migration
|
||||
|
||||
The public static method can be resolved with:
|
||||
Prefer the direct call `MultipartGenerator.generateCompositeTile(candidate, parts, client)`, as in the compiling
|
||||
example. Gate optional typed integration code as described in the [API index](../API.md#direct-calls-and-optional-integration).
|
||||
For temporary interoperability with an existing reflective integration, the method can also be resolved with:
|
||||
|
||||
```java
|
||||
Method generate = MultipartGenerator.class.getMethod(
|
||||
@@ -77,7 +79,8 @@ body, deprecated for callers in favor of the static Java entry. Existing interna
|
||||
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 call has an [existing Java replacement](MICROBLOCK_CREATION.md).
|
||||
Private-material access remains a separate migration contract; neither is closed by this tile API alone.
|
||||
Private-material access has a separate [typed material query](MATERIAL_ACCESS.md); neither consumer adoption contract
|
||||
is closed by this tile API alone.
|
||||
|
||||
## Validation
|
||||
|
||||
|
||||
@@ -39,7 +39,10 @@ cause the whole preview to be rejected when matching Schematica's all-parts-requ
|
||||
|
||||
## Migrating Schematica's optional reflection
|
||||
|
||||
Replace the companion singleton/private-field lookup and Scala `Map.get` / `Option` handling with:
|
||||
Prefer direct `MultiPartRegistry.getPartFactory(partID)` calls, as in the compiling example above. Isolate typed
|
||||
optional integration code behind mod-presence/version checks; see the [direct-call policy](../API.md#direct-calls-and-optional-integration).
|
||||
The following is only a legacy interoperability option for a consumer retaining reflection temporarily. It replaces
|
||||
the companion singleton/private-field lookup and Scala `Map.get` / `Option` handling:
|
||||
|
||||
```java
|
||||
Class<?> registry = Class.forName("codechicken.multipart.MultiPartRegistry");
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# Read a microblock's block and metadata
|
||||
|
||||
Use the existing public `BlockMicroMaterial.block()` and `meta()` methods. Neither reflection nor an accessor mixin
|
||||
is needed. The [compiling Java example](../../src/functionalTest/java/codechicken/multipart/examples/MaterialAccessExample.java)
|
||||
implements GuideNH's complete primary-material query using typed calls:
|
||||
|
||||
1. Traverse `TileMultipart.jPartList()` in its stored order.
|
||||
2. For each `Microblock`, resolve `material()` through `MicroMaterialRegistry.getMaterial(int)`.
|
||||
3. If the result is a `BlockMicroMaterial`, read `block()` then `meta()`.
|
||||
4. Skip null/air blocks and absent/empty block registry names; return the first usable block ID.
|
||||
|
||||
For example, wool with metadata 14 exports as `minecraft:wool:14`. GuideNH appends a metadata suffix only when the
|
||||
value is positive; zero and negative values export the unsuffixed block ID. This is GuideNH's export convention,
|
||||
not a general material serialization format. The example preserves positive values above 15 without masking.
|
||||
|
||||
## Identity, lifecycle and overrides
|
||||
|
||||
- `block()` returns the constructor's block by identity in the base implementation, including null. `meta()` returns
|
||||
the original integer unchanged. Both are public virtual methods; consumer calls must respect subclass overrides.
|
||||
- A microblock's numeric `material()` value is an ID in the active material map, not block metadata. Query after
|
||||
registry initialization and, on a client, material-ID synchronization. Do not persist these numeric IDs across
|
||||
sessions; see [material enumeration](MATERIAL_ENUMERATION.md).
|
||||
- `IMicroMaterial` does not promise a block/meta representation. Skip non-block materials for this block-only query;
|
||||
do not cast every registered material to `BlockMicroMaterial` or infer its block from an item drop.
|
||||
- `blockKey()` caches the constructor block's registry name. It can differ from an overridden `block()` and from
|
||||
the material's registered name. Export the registry name of the returned block, as the example does.
|
||||
- This is a read operation with no binding, world access, material registration or tile mutation. Observe the
|
||||
[part-list ownership contract](PART_TRAVERSAL.md#collection-ownership-and-ordering); the traversal is not a snapshot.
|
||||
|
||||
## GuideNH migration
|
||||
|
||||
Replace `resolvePrimaryMicroblockId`'s reflective part traversal, material lookup and `AccessorBlockMicroMaterial`
|
||||
field reads with the typed example. Remove that mixin and its configuration entry when the consumer migrates. Keep
|
||||
FMP's private fields unchanged until the migrated consumer release is adopted; this branch does not edit the
|
||||
reference consumer checkout or claim adoption.
|
||||
|
||||
The old mixin reads constructor fields directly, bypassing overrides. The old reflection fallback already calls
|
||||
the public virtual getters. The supported typed path follows those getters too, so custom materials that override
|
||||
them may produce a different export from the mixin. Validate those materials in GuideNH; do not introduce raw-field
|
||||
accessors to preserve an implementation detail that disagrees with the material's public behavior.
|
||||
|
||||
The example returns null for a null/non-multipart tile or no usable block. Invalid material IDs and exceptions from
|
||||
custom accessors propagate. GuideNH currently logs query failures and returns null from its outer integration
|
||||
boundary; retain that policy around the typed call. Do not catch a broken material and silently select a later part.
|
||||
Metadata is read before the null/air check, preserving accessor order even for a skipped block.
|
||||
|
||||
For optional FMP support, isolate typed code in a compatibility class and load it only after checking mod presence
|
||||
and the supported dependency version. Keep FMP types out of classes loaded unconditionally when FMP is absent.
|
||||
An optional dependency does not itself require reflection. The [API index](../API.md) describes the current
|
||||
unreleased branch/version status; pin an artifact containing every method used by the integration.
|
||||
|
||||
## Validation
|
||||
|
||||
JVM characterization pins constructor identity, every metadata bit, virtual dispatch and the retained private
|
||||
fields. Dedicated-server Forge tests cover initialized material lookup, ordered filtering, registry aliases,
|
||||
null/air/unregistered blocks, non-block materials, metadata formatting, overridden accessors and failure propagation.
|
||||
The example compiles with Scala excluded from its classpath and contains no reflection, companion or Scala calls.
|
||||
Actual GuideNH exports and optional-mod absent/present loading remain consumer adoption checks.
|
||||
@@ -51,7 +51,9 @@ or authorize removing Scala-signature support before consumer release/adoption.
|
||||
## GuideNH migration
|
||||
|
||||
GuideNH `7d8fb44e77b9` explicitly resolves the companion's `create(MicroblockClass, int, boolean)` and invokes it on
|
||||
`MODULE$`. It does not automatically discover the existing static method. Its optional integration can instead cache:
|
||||
`MODULE$`. It does not automatically discover the existing static method. Prefer the direct typed creation example
|
||||
below, with [gated optional integration](../API.md#direct-calls-and-optional-integration). The following cache is only
|
||||
a temporary interoperability option for consumers retaining reflection:
|
||||
|
||||
```java
|
||||
Class<?> generator = Class.forName("codechicken.microblock.MicroblockGenerator");
|
||||
@@ -75,7 +77,7 @@ capturing shape after creation could copy a callback-modified value instead of t
|
||||
Public `setShape` uses the virtual shape setter; GuideNH's old private-field write bypassed that dispatch. Validate
|
||||
custom traits overriding these hooks before adopting the change. Preserve its existing missing/failed-promotion
|
||||
handling, part order, Java collection migration, tile state setup and subsequent loading/notifications. Do not copy
|
||||
the source tile binding to the new part. Private material-field access is a separate remaining GuideNH contract.
|
||||
the source tile binding to the new part. Private material-field access has a separate [typed query guide](MATERIAL_ACCESS.md).
|
||||
|
||||
## Side and validation limits
|
||||
|
||||
|
||||
Reference in new issue
Block a user