mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-20 20:22:15 +00:00
feat: add Java box occlusion API
This commit is contained in:
1 parent
c7a3ed982e
commit
9a06eac87f
11 files changed
+193
-24
No files matched your search
+4
-2
@@ -532,7 +532,7 @@ Each row keeps its existing descriptor for binary compatibility and gains a Java
|
||||
| `MicroMaterialRegistry.getIdMap(): scala.Tuple2[]` | `materialCount(): int` plus existing `materialName(int)` and `getMaterial(int)` | Implemented with static/companion deprecation; [guide and compiling example](docs/api/MATERIAL_ENUMERATION.md). Consumer release/adoption remains pending |
|
||||
| `TileMultipart.operate(scala.Function1<TMultiPart, BoxedUnit>)` | `forEachPart(java.util.function.Consumer<TMultiPart>)` | Implemented through the legacy virtual hook; preserves captured traversal, detached-part filtering and callback failures. Lifecycle still calls `operate` |
|
||||
| `TileMultipart.occlusionTest(scala.collection.Seq, TMultiPart)` | `testOcclusion(Collection<? extends TMultiPart>, TMultiPart)` | Implemented with an input snapshot and legacy virtual dispatch, including generated partial occlusion; [guide](docs/api/OCCLUSION.md). Distinct Java name avoids Scala overload resolution |
|
||||
| `NormalOcclusionTest.apply(scala.collection.Traversable<Cuboid6>, scala.collection.Traversable<Cuboid6>)` and companion entry | Java box-versus-box entry, with a distinct name to be chosen after characterization | Still used by ForgeRelocationFMP and OpenComputers. The existing Java `test(Iterable, Iterable)` loop is private; its public part-based sibling does not replace this box-list contract |
|
||||
| `NormalOcclusionTest.apply(scala.collection.Traversable<Cuboid6>, scala.collection.Traversable<Cuboid6>)` and companion entry | `testBoxes(Iterable<? extends Cuboid6>, Iterable<? extends Cuboid6>)` | Implemented over the existing Java loop; both inputs snapshotted before geometry tests. [Guide and compiling example](docs/api/OCCLUSION.md#box-versus-box-queries). ForgeRelocationFMP/OpenComputers adoption remains pending |
|
||||
| `TileMultipart.loadParts(scala.collection.Iterable)` | `loadPartList(Collection<TMultiPart>)` | Implemented through the legacy virtual hook; binding, world notifications, input iteration and partial failure retained. [Loading guide](docs/api/PART_LOADING.md) |
|
||||
| `TileMultipart.partList_$eq(scala.collection.Seq)` | `setPartList(List<TMultiPart>)` | Implemented through the legacy setter; Java list copied without binding, null sentinel supported. GuideNH's old reflective name remains supported |
|
||||
| `TileMultipart.renderID()` / `renderID_$eq(int)` | `getRenderID()` / `setRenderID(int)` | |
|
||||
@@ -552,10 +552,12 @@ same-name overload there invites a silent wrong-overload bind.
|
||||
lifecycle contracts, and generated server/client tile checks; [guide](docs/api/PART_LOADING.md), [API index](docs/API.md).
|
||||
- [x] Add `testOcclusion(Collection, candidate)` with snapshot ownership, subtype inputs, legacy hook dispatch and
|
||||
generated partial-occlusion coverage; [guide and compiling example](docs/api/OCCLUSION.md).
|
||||
- [x] Add direct `testBoxes(Iterable, Iterable)` with eager input snapshots, ordered intersection callbacks and retained
|
||||
static/companion bridges; [migration guide](docs/api/OCCLUSION.md#box-versus-box-queries).
|
||||
- [ ] For remaining siblings, compile external Java examples with Scala excluded from the compile classpath before
|
||||
finalizing names. The proposed `loadParts(Collection)` overload required `scala.collection.Iterable` during javac
|
||||
overload resolution; the implemented `loadPartList(Collection)` avoids that dependency. Apply this gate to the
|
||||
remaining occlusion and registration overloads as well as checking the emitted consumer bytecode.
|
||||
remaining registration overloads as well as checking the emitted consumer bytecode.
|
||||
- [ ] Mark the remaining legacy entries above `@Deprecated` with javadoc naming a working replacement.
|
||||
- [ ] Confirm every original descriptor still exists in the ABI fixture after the change.
|
||||
- [ ] Document the supported API with compiling usage examples and an old-to-new migration guide. Validate Java
|
||||
|
||||
@@ -131,6 +131,11 @@ This is a much smaller surface than the plan assumed. `TileMultipart.jPartList()
|
||||
widely used accessor (ProjectBlue, WitchingGadgets, buildcraft-compat, extrautilities, gregtech, matter-manipulator),
|
||||
so the Java-first collection API mostly exists already and the Scala overloads are a thin retained shell.
|
||||
|
||||
The branch now supplies `NormalOcclusionTest.testBoxes(java.lang.Iterable, java.lang.Iterable)` for the box-list
|
||||
contract. Both old `apply(Traversable, Traversable)` entries remain, with deprecations pointing to the Java entry.
|
||||
The shipping ForgeRelocationFMP/OpenComputers companion calls still require their exact descriptor until adoption;
|
||||
see the [migration guide](docs/api/OCCLUSION.md#box-versus-box-queries) and consumer ledger.
|
||||
|
||||
`IDWriter`, ported on this branch, has **zero** downstream references. Its four deprecated Scala function accessors
|
||||
are not load-bearing and can be dropped.
|
||||
|
||||
|
||||
@@ -491,7 +491,7 @@ behavior:
|
||||
## Java API adoption ledger
|
||||
|
||||
This ledger tracks migration of a specific legacy contract, not completion of an entire consumer's migration.
|
||||
Material enumeration, tile collection/traversal access, tile loading/storage assignment and collection occlusion queries are implemented on
|
||||
Material enumeration, tile collection/traversal access, tile loading/storage assignment, tile occlusion and box queries are implemented on
|
||||
`algent/java`. The [API index](docs/API.md) links the guides and compiling Java examples. These additions are not yet
|
||||
tied to a released minimum dependency version. Unlisted contracts remain governed by the inventories above.
|
||||
|
||||
@@ -505,6 +505,8 @@ tied to a released minimum dependency version. Unlisted contracts remain governe
|
||||
| `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 map and generator reflection remain separate contracts | No migrated pack version verified; retain the Scala loader 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 |
|
||||
|
||||
Evidence for the FMP addition is under ignored `run/migration-material-enumeration-reference/`. The original
|
||||
reference-compiled Scala consumer still exercises the companion and tuple-array descriptor. The new compiling Java
|
||||
@@ -548,9 +550,17 @@ likewise contains no direct reference to that tile descriptor. The legacy hook i
|
||||
ProjectRed and ForgeRelocationFMP's `canReplacePart` callers need no rename and must retain outgoing-part exclusion.
|
||||
The new collection query is not a blanket replacement for placement checks or the part-level `occlusionTest` hook.
|
||||
`NormalOcclusionTest$.apply(Traversable, Traversable)` remains a separate box-list bridge used by ForgeRelocationFMP
|
||||
and OpenComputers. Its Java replacement is now explicit in the plan; completion of the tile query does not retire it.
|
||||
and OpenComputers. Its `testBoxes(Iterable, Iterable)` replacement is now implemented; adoption of either query does
|
||||
not retire the other contract.
|
||||
Evidence for this slice is under ignored `run/migration-part-occlusion-reference/`; reference checkouts remain unchanged.
|
||||
|
||||
The box-query slice retains eager left-then-right input collection, shallow snapshots, ordered/short-circuit intersection
|
||||
calls, touching tolerance and original input/callback exceptions. Both legacy entries are deprecated without changing
|
||||
their descriptors or bodies. The Java example compiles with Scala excluded; the shared private copy helper only widens
|
||||
its generic input to accept box subclasses. The source check found the three box-list calls listed above and no
|
||||
`testBoxes` collision. The installed `+719` rescan retains all 386 member/type/reflection rows from `+678` across 27
|
||||
consumers. Evidence: `run/migration-box-occlusion-reference/`; [guide](docs/api/OCCLUSION.md#box-versus-box-queries).
|
||||
|
||||
## Practical priority for the current branch
|
||||
|
||||
1. Keep the existing `+678` ABI fixture as the exact binary floor and correct failures before source cleanup.
|
||||
|
||||
+19
-15
@@ -17,7 +17,7 @@ migration checkout; `codex/tile-compatibility-fixes` was deleted after its fixes
|
||||
|
||||
## Current state and next target
|
||||
|
||||
**556 plain-JVM tests and 243 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **224 Java
|
||||
**563 plain-JVM tests and 243 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **224 Java
|
||||
files and 9 Scala files / 747 nonblank Scala lines**. The packaged inventory has 443 classes.
|
||||
|
||||
Review follow-up: restored packet-scheduler callback mutation behavior with the original Scala hash-map traversal,
|
||||
@@ -32,18 +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: `TileMultipart.testOcclusion(Collection<? extends TMultiPart>, TMultiPart)` copies the input
|
||||
before dispatching through the legacy `occlusionTest(Seq, TMultiPart)` hook. Generated partial-occlusion checks remain
|
||||
in that path; the query is not full placement approval. Three JVM baseline cases and stronger existing Forge
|
||||
assertions were committed first as `6744f5b`. Four further JVM cases, a compiling shape example and one Forge
|
||||
generated-partial case cover the new entry. All 552 pre-change compiled JVM tests pass with their recorded version.
|
||||
All 443 class APIs retain their existing members, with one method added; 17 ScalaSignature payloads, 3,750 existing
|
||||
method bodies and 116 generated dumps are unchanged apart from expected deprecation metadata and build-version
|
||||
literals. Evidence: `run/migration-part-occlusion-reference/`; [guide](docs/api/OCCLUSION.md).
|
||||
Latest API addition: `NormalOcclusionTest.testBoxes(Iterable<? extends Cuboid6>, Iterable<? extends Cuboid6>)` snapshots
|
||||
both inputs before using the existing geometry loop. Three JVM baseline cases were committed first as `c7a3ed9`;
|
||||
four more cases exercise the Java entry and compiling example. All 559 pre-change compiled JVM tests pass with their
|
||||
recorded version. All 443 classes retain their existing members, with one method added and two legacy entries
|
||||
deprecated; 17 ScalaSignature payloads, 3,751 existing method bodies and 116 generated dumps are unchanged apart from
|
||||
expected deprecation metadata and build-version literals. The private copy helper's generic input alone widens to
|
||||
accept box subclasses. Evidence: `run/migration-box-occlusion-reference/`; [guide](docs/api/OCCLUSION.md#box-versus-box-queries).
|
||||
|
||||
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.
|
||||
Keep this compilation gate for remaining occlusion/registration APIs; checking only imports or bytecode is insufficient.
|
||||
Keep this compilation gate for remaining registration APIs; checking only imports or bytecode is insufficient.
|
||||
Internal storage writes and reconstruction still dispatch through the old setter/loader hooks, not the Java siblings.
|
||||
|
||||
The [API index](docs/API.md) orients consumers to entry points, compiling examples and migration status. Material
|
||||
@@ -57,11 +56,16 @@ 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 API candidate is the direct box-versus-box `NormalOcclusionTest` contract. Its public box-list entry
|
||||
still takes Scala `Traversable` on both the static class and companion, while the Java `test(Iterable, Iterable)` loop
|
||||
is private. ForgeRelocationFMP and OpenComputers use the Scala descriptor. Characterize eager input collection,
|
||||
ordering/failures and geometric boundaries before adding a distinctly named Java entry and deprecating the bridges.
|
||||
Verify compilation without Scala. Registry registration guidance and bridges remain another pending slice.
|
||||
The next bounded API candidate is multipart factory registration: characterize the `IPartFactory2`/Scala function
|
||||
entries and their existing Java siblings, verify compilation without Scala before choosing names, and document factory
|
||||
timing/registration semantics with an example and deprecations. Preserve static/companion descriptors for ProjectRed
|
||||
and ForgeRelocationFMP. Registry lookup for Schematica is a separate capability to assess after registration.
|
||||
|
||||
Progress: seven of the ten Phase 9.1 rows now have implemented/documented Java replacements. The remaining rows are
|
||||
registration, render-ID accessors and the tuple-returning tile conversion result. That count excludes supported
|
||||
registry/generator/reflection replacements, 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.
|
||||
|
||||
Pause mechanical extraction of retained Scala shells unless it enables that API, fixes a demonstrated issue or has
|
||||
a measured benefit. `ScalaSignature.ClassSymbolRef.info` remains an optional bounded extraction, not the default next
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ without converting the rest of its code to Java.
|
||||
| Rebuild parts on an already prepared composite tile | `loadPartList(Collection)` — [part loading](api/PART_LOADING.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) |
|
||||
|
||||
Each guide explains ownership, lifecycle, legacy replacements and limitations, and links to a compiling Java example
|
||||
exercised by the test suite. The loading/setter APIs are advanced reconstruction operations; ordinary placement and
|
||||
@@ -47,7 +48,7 @@ Deprecated Scala-facing entry points remain callable, with their descriptors and
|
||||
Follow the method-specific guide: a Java sibling is not automatically a replacement override hook, and reflection
|
||||
must select the intended parameter types when a method is overloaded.
|
||||
|
||||
Direct box-versus-box Java occlusion access, remaining registry bridges/documentation, generator/reflection replacements
|
||||
Remaining registry bridges/documentation, generator/reflection replacements
|
||||
and complete external microblock extension guidance are still pending. In particular, ProjectRed's Scala microblock traits
|
||||
remain a supported dependency; registration signatures alone do not prove a complete Java replacement.
|
||||
|
||||
|
||||
+55
-2
@@ -1,10 +1,12 @@
|
||||
# Testing part occlusion from Java
|
||||
# Testing occlusion from Java
|
||||
|
||||
[API index](../API.md)
|
||||
|
||||
The `algent/java` branch adds `TileMultipart.testOcclusion(Collection<? extends TMultiPart>, TMultiPart)`.
|
||||
It tests a supplied collection of parts through the tile's existing occlusion hook, including generated
|
||||
partial-occlusion checks. This addition is not yet tied to a minimum published dependency version.
|
||||
For raw geometry, `NormalOcclusionTest.testBoxes(Iterable<? extends Cuboid6>, Iterable<? extends Cuboid6>)` tests
|
||||
two groups of bounding boxes without constructing parts. See [box-versus-box queries](#box-versus-box-queries).
|
||||
|
||||
## Example
|
||||
|
||||
@@ -67,7 +69,54 @@ pair, following the [loader compilation finding](PART_LOADING.md#overrides-and-r
|
||||
No direct consumer calls or overrides of the two-argument tile hook were found in the supplied source/ABI audit.
|
||||
Consumers such as ProjectRed and ForgeRelocationFMP already use the Java-typed `canReplacePart` API and need no rename
|
||||
for that contract. Part-level `occlusionTest(TMultiPart)` remains supported as-is. The Scala `NormalOcclusionTest.apply`
|
||||
box-versus-box entry is a separate, still-used contract whose Java replacement remains pending.
|
||||
box-versus-box entry is a separate, still-used contract with the Java replacement below.
|
||||
|
||||
## Box-versus-box queries
|
||||
|
||||
Use `NormalOcclusionTest.testBoxes` when you already have box iterables, including `getOcclusionBoxes()` results:
|
||||
|
||||
```java
|
||||
public static boolean fitsBounds(Iterable<? extends Cuboid6> occupied, Cuboid6 candidate) {
|
||||
return NormalOcclusionTest.testBoxes(occupied, Collections.singletonList(candidate));
|
||||
}
|
||||
```
|
||||
|
||||
The [complete example](../../src/test/java/codechicken/multipart/examples/BoxOcclusionExample.java) compiles without
|
||||
Scala on its classpath. Both arguments accept box subclasses and need only implement Java `Iterable`.
|
||||
|
||||
The query fully consumes the first input, then the second, requesting each input's iterator once. It takes shallow
|
||||
snapshots before testing any pairs, even when one input is empty or the first pair will overlap. Iteration failures
|
||||
therefore take precedence over geometry results; a failure in the first input prevents reading the second. Input
|
||||
collections can change during intersection callbacks without changing the captured membership, but boxes themselves
|
||||
are shared: coordinate changes remain visible. Supply finite iterables and use the game thread for live geometry.
|
||||
|
||||
Each first-group box calls `intersects` on second-group boxes in encounter order. Duplicates participate; the first
|
||||
intersection returns `false`. No intersections returns `true`. The existing `Cuboid6.intersects` tolerance is retained:
|
||||
touching faces and sub-tolerance overlaps are allowed. Only cross-group pairs are tested, not pairs within one group.
|
||||
Neither input nor its boxes is modified by the helper; custom iterators or `intersects` overrides can have side effects.
|
||||
|
||||
Null inputs fail during copying. Null box entries are not eagerly rejected: an empty opposite group never uses them,
|
||||
and an earlier intersection may avoid them. A reached intersection involving an ordinary null box fails. Iterator and
|
||||
intersection exceptions propagate unchanged, without undoing callback side effects.
|
||||
|
||||
This does not run part callbacks, generated aggregate partial-occlusion checks, slot checks or placement logic.
|
||||
Use `tile.testOcclusion` for the tile's occlusion protocol, and the placement/replacement APIs for their wider checks.
|
||||
The existing `NormalOcclusionTest.apply(JNormalOcclusion, TMultiPart)` part helper remains unchanged.
|
||||
|
||||
Both Scala box-list `apply(Traversable, Traversable)` entries, static and companion, are deprecated with their original
|
||||
descriptors and bodies retained. OpenComputers' cable/network checks can pass `getOcclusionBoxes()` directly as the
|
||||
second argument; their Scala `ownBounds` collection needs a Java adapter:
|
||||
|
||||
```scala
|
||||
import scala.collection.JavaConverters._
|
||||
NormalOcclusionTest.testBoxes(ownBounds.asJava, otherBounds)
|
||||
```
|
||||
|
||||
ForgeRelocationFMP can similarly adapt its assembled Scala `boxes` sequence and pass its existing Java
|
||||
`getOcclusionBoxes` iterable directly. Keep its combined normal, partial and collision boxes and caller order intact.
|
||||
These are migration directions, not changes to the reference checkouts. Consumer releases and pack adoption remain
|
||||
pending, and the new method has no published minimum dependency version yet. Scala consumers can adopt this FMP API
|
||||
while keeping their own Scala code.
|
||||
|
||||
## Validation
|
||||
|
||||
@@ -76,3 +125,7 @@ subtype/non-list collections, override routing and the shape example. A Forge te
|
||||
partial trait rejects overlapping partial parts that plain pair tests accept. Existing descriptors, generated output,
|
||||
and frozen pre-change callers are checked separately. Actual client previews and full-pack adoption remain covered
|
||||
by the [manual release checks](../../JAVA_MIGRATION_MANUAL_CHECKS.md).
|
||||
|
||||
Box-query tests run the same snapshot, input-failure, ordering, null and exception contracts against both legacy entries
|
||||
and the Java entry. The compiling example also covers touching tolerance and containment; frozen pre-change tests
|
||||
retain calls to both old descriptors.
|
||||
@@ -1806,3 +1806,22 @@ differences belong in the [divergence ledger](../../JAVA_MIGRATION_DIVERGENCES.m
|
||||
with the new name was found. The separately load-bearing Scala box-list `NormalOcclusionTest.apply` contract now
|
||||
has an explicit plan row and is the next candidate. Reference checkouts remain unchanged; client previews and
|
||||
consumer release/adoption remain separate gates. Evidence: `run/migration-part-occlusion-reference/`.
|
||||
|
||||
### 2026-09-05 — Java box-versus-box occlusion query
|
||||
|
||||
- Committed three JVM baseline cases as `c7a3ed9` before changing production code. Both static and companion entries
|
||||
are checked for eager input collection, shallow snapshots, duplicate/callback order, short-circuiting, null handling
|
||||
and original failures. Saved the pre-API jar, sources, all 559 compiled JVM tests, reports and 116 generated dumps.
|
||||
- Added `NormalOcclusionTest.testBoxes(Iterable<? extends Cuboid6>, Iterable<? extends Cuboid6>)` over the existing
|
||||
private Java copy/intersection helpers. The copy helper's private generic input now accepts subtypes; its body and
|
||||
descriptor are unchanged. Both legacy Scala box entries are deprecated without changing their bodies/descriptors.
|
||||
- Four further JVM cases run the same contracts against the new entry and exercise a compiling geometry example,
|
||||
including touching tolerance and containment. The Java example compiles without Scala on its classpath.
|
||||
- Normal/clean build and style checks pass: 563 JVM tests, 243 Forge tests and 559 frozen pre-change JVM tests.
|
||||
All 443 existing classes, 17 ScalaSignature payloads, 3,751 existing method bodies and 116 generated dumps remain;
|
||||
exactly one public method and two deprecations are added. Build versions and the private helper's generic widening
|
||||
are the only other expected metadata differences.
|
||||
- Updated the API guide/index, ABI notes and adoption ledger for OpenComputers' two connection checks and
|
||||
ForgeRelocationFMP's combined geometry check. The installed `+719` rescan retains all 386 ABI/reflection rows across
|
||||
27 consumers. Reference checkouts are unchanged; consumer release/adoption and manual client/pack checks remain
|
||||
pending. Next: multipart factory registration. Evidence: `run/migration-box-occlusion-reference/`.
|
||||
@@ -12,6 +12,11 @@ public final class NormalOcclusionTest$ {
|
||||
|
||||
private NormalOcclusionTest$() {}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link NormalOcclusionTest#testBoxes(Iterable, Iterable)} with Java iterables. This companion
|
||||
* entry remains available to previously compiled Scala callers.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean apply(Traversable<Cuboid6> boxes1, Traversable<Cuboid6> boxes2) {
|
||||
return NormalOcclusionTest.apply(boxes1, boxes2);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,35 @@ public final class NormalOcclusionTest {
|
||||
|
||||
private NormalOcclusionTest() {}
|
||||
|
||||
/** Performs the test, returns true if the parts may coexist. */
|
||||
/**
|
||||
* Tests two groups of boxes, returning true if no cross-group pair intersects according to
|
||||
* {@link Cuboid6#intersects(Cuboid6)}, including its existing tolerance for touching bounds.
|
||||
*
|
||||
* <p>
|
||||
* Fully consumes the first input, then the second, once each, before testing any pairs. These shallow snapshots
|
||||
* preserve order, duplicates, null entries and box identities. The first input is the outer loop; the first
|
||||
* intersection returns false. Input and intersection exceptions propagate unchanged. Null inputs fail during
|
||||
* copying; null entries fail only if an intersection call uses them. Empty inputs allow all boxes in the other
|
||||
* group, but both inputs are still consumed.
|
||||
*
|
||||
* <p>
|
||||
* This only tests supplied geometry. It does not invoke part callbacks, perform aggregate partial-occlusion checks
|
||||
* or approve placement. Boxes remain shared and mutable; changing their coordinates can affect the query.
|
||||
*/
|
||||
public static boolean testBoxes(Iterable<? extends Cuboid6> boxes1, Iterable<? extends Cuboid6> boxes2) {
|
||||
List<Cuboid6> first = new ArrayList<>();
|
||||
addAll(first, boxes1);
|
||||
List<Cuboid6> second = new ArrayList<>();
|
||||
addAll(second, boxes2);
|
||||
return test(first, second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the test, returns true if the parts may coexist.
|
||||
*
|
||||
* @deprecated Use {@link #testBoxes(Iterable, Iterable)} with Java iterables. Retained for existing Scala callers.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean apply(Traversable<Cuboid6> boxes1, Traversable<Cuboid6> boxes2) {
|
||||
return test(collect(boxes1), collect(boxes2));
|
||||
}
|
||||
@@ -54,7 +82,7 @@ public final class NormalOcclusionTest {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void addAll(List<Cuboid6> target, Iterable<Cuboid6> boxes) {
|
||||
private static void addAll(List<Cuboid6> target, Iterable<? extends Cuboid6> boxes) {
|
||||
for (Cuboid6 box : boxes) {
|
||||
target.add(box);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.function.BiFunction;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.multipart.examples.BoxOcclusionExample;
|
||||
import scala.collection.JavaConversions;
|
||||
import scala.collection.Traversable;
|
||||
|
||||
@@ -40,6 +41,31 @@ class NormalOcclusionBoxTest {
|
||||
LEGACY.forEach(NormalOcclusionBoxTest::assertNullsAndGeometryFailures);
|
||||
}
|
||||
|
||||
@Test
|
||||
void javaEntrySnapshotsSinglePassInputsBeforeOrderedShortCircuiting() {
|
||||
assertSnapshotAndOrder(NormalOcclusionTest::testBoxes);
|
||||
}
|
||||
|
||||
@Test
|
||||
void javaEntryPropagatesInputFailuresBeforeTestingGeometry() {
|
||||
assertInputFailures(NormalOcclusionTest::testBoxes);
|
||||
}
|
||||
|
||||
@Test
|
||||
void javaEntryKeepsLazyNullBoxesAndOriginalGeometryFailures() {
|
||||
assertNullsAndGeometryFailures(NormalOcclusionTest::testBoxes);
|
||||
}
|
||||
|
||||
@Test
|
||||
void javaExampleKeepsTouchingToleranceAndOverlapRules() {
|
||||
List<Cuboid6> occupied = Collections.singletonList(new Cuboid6(0, 0, 0, 0.5, 1, 1));
|
||||
assertTrue(BoxOcclusionExample.fitsBounds(occupied, new Cuboid6(0.5, 0, 0, 1, 1, 1)));
|
||||
assertTrue(BoxOcclusionExample.fitsBounds(occupied, new Cuboid6(0.499995, 0, 0, 1, 1, 1)));
|
||||
assertFalse(BoxOcclusionExample.fitsBounds(occupied, new Cuboid6(0.49998, 0, 0, 1, 1, 1)));
|
||||
assertFalse(BoxOcclusionExample.fitsBounds(occupied, new Cuboid6(0.1, 0.1, 0.1, 0.2, 0.2, 0.2)));
|
||||
assertTrue(BoxOcclusionExample.fitsBounds(Collections.emptyList(), occupied.get(0)));
|
||||
}
|
||||
|
||||
private static void assertSnapshotAndOrder(BiFunction<Iterable<Cuboid6>, Iterable<Cuboid6>, Boolean> query) {
|
||||
List<String> calls = new ArrayList<>();
|
||||
List<Cuboid6> left = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package codechicken.multipart.examples;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.multipart.NormalOcclusionTest;
|
||||
|
||||
/** Compiling example for docs/api/OCCLUSION.md; supplied bounds do not imply full placement approval. */
|
||||
public final class BoxOcclusionExample {
|
||||
|
||||
private BoxOcclusionExample() {}
|
||||
|
||||
public static boolean fitsBounds(Iterable<? extends Cuboid6> occupied, Cuboid6 candidate) {
|
||||
return NormalOcclusionTest.testBoxes(occupied, Collections.singletonList(candidate));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user