From df212470e6e4a4f74f926e1576170a571ca1d91e Mon Sep 17 00:00:00 2001 From: Algent Date: Wed, 2 Sep 2026 01:00:12 +0200 Subject: [PATCH] refactor: port edge and post factories --- JAVA_MIGRATION.md | 9 + JAVA_MIGRATION_DIVERGENCES.md | 52 ++++ JAVA_MIGRATION_HANDOFF.md | 26 +- JAVA_MIGRATION_MANUAL_CHECKS.md | 3 +- .../microblock/EdgeMicroClass$.java | 69 ++++++ .../microblock/EdgeMicroClass.java | 76 ++++++ .../microblock/EdgeMicroblock.scala | 230 ------------------ .../microblock/EdgeMicroblockTraits.scala | 126 ++++++++++ .../microblock/EdgePlacement$.java | 57 +++++ .../codechicken/microblock/EdgePlacement.java | 30 +++ .../microblock/PostMicroClass$.java | 53 ++++ .../microblock/PostMicroClass.java | 60 +++++ 12 files changed, 550 insertions(+), 241 deletions(-) create mode 100644 src/main/scala/codechicken/microblock/EdgeMicroClass$.java create mode 100644 src/main/scala/codechicken/microblock/EdgeMicroClass.java delete mode 100644 src/main/scala/codechicken/microblock/EdgeMicroblock.scala create mode 100644 src/main/scala/codechicken/microblock/EdgeMicroblockTraits.scala create mode 100644 src/main/scala/codechicken/microblock/EdgePlacement$.java create mode 100644 src/main/scala/codechicken/microblock/EdgePlacement.java create mode 100644 src/main/scala/codechicken/microblock/PostMicroClass$.java create mode 100644 src/main/scala/codechicken/microblock/PostMicroClass.java diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index 4a01ffe..eb2ca18 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -1173,3 +1173,12 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec - A clean build passes all 248 plain-JVM tests and the Java 8 Forge server passes all 105 tests. Recompiled Scala must spell the Java array getter as `CornerMicroClass.aBounds()(index)`; existing binaries still link unchanged. `microblock/EdgeMicroblock.scala` is next as one Edge/Post source unit. +- Characterized the combined Edge/Post unit against untouched Scala. Two plain-JVM cases freeze all twelve retained + public surfaces, state/super accessors and edge-opposite mappings. Three Forge cases freeze both factories, all 84 + edge and 12 post bounds, generated behavior, even-size post placement and matching-post expansion. +- Ported the six concrete facade/companion types directly to Java while retaining `EdgeMicroblock`, + `PostMicroblock`, and stateful `PostMicroblockClient` in `EdgeMicroblockTraits.scala`. ProjectRed and + UtilitiesInExcess class-ID linkage remains exact; the Post client traversal closure and all trait helpers remain. +- A clean build passes all 250 plain-JVM tests and the Java 8 Forge server passes all 108 tests. All callable public + descriptors match the reference; only four private bounds-initializer closures disappear. + `microblock/HollowMicroblock.scala` is next. diff --git a/JAVA_MIGRATION_DIVERGENCES.md b/JAVA_MIGRATION_DIVERGENCES.md index de0c794..facca1c 100644 --- a/JAVA_MIGRATION_DIVERGENCES.md +++ b/JAVA_MIGRATION_DIVERGENCES.md @@ -2845,3 +2845,55 @@ The six supported runtime types remain. - Raw `javap` comparison confirms identical callable public names/descriptors for both facades, both companions, the trait and its `$class` helper. - Actual corner rendering and highlight geometry remain covered by the existing manual checklist entries. + +## 2026-09-02 — Edge/Post microblock factory Java port + +The Edge placement/factory and Post factory facades/companions are now Java. `EdgeMicroblock`, `PostMicroblock`, and +the stateful `PostMicroblockClient` remain Scala in `EdgeMicroblockTraits.scala`; their multiple-inheritance and +generated state/super-accessor surfaces need no generator changes for this concrete port. + +### Observable behavior + +No known runtime divergence. Edge opposite selection still preserves negative custom slots and toggles the packed +edge bit for the clicked axis. Custom placement still creates posts only for even sizes, yields to normal edge +placement outside the grid centre, expands only a matching-material post whose combined size is below eight, and +retains the same internal/opposite/external precedence. + +The Edge bounds table remains a mutable 256-entry array with exactly 84 populated entries (`size` 1 through 7 over 12 +edges). The Post table likewise retains exactly 12 entries (even sizes 2, 4, 6 over three axes). Generated edges keep +their `slot - 15` shape encoding. Generated posts keep the Edge item class ID, one-element occlusion list, partial and +normal occlusion behavior, resistance and axis-zero torch support. + +The Post client trait's two mutable render bounds, lifecycle recalculation, face/post shrinking order and transparency/ +size/axis tie-break remain the original Scala implementation. Actual client rendering remains a manual check. + +### ABI and reflection compatibility + +All twelve retained facade, companion, trait and `$class` types keep their hierarchy and callable public +names/descriptors. ProjectRed's load-bearing `EdgeMicroClass$.MODULE$.getClassId()` and UtilitiesInExcess's static +`EdgeMicroClass.getClassId()` calls are unchanged. The stable `"mcr_edge"` ID used by both BuildCraft and +MatterManipulator, and BuildCraft's `"mcr_post"` ID, are unchanged. + +Recompiled Scala source must use `EdgeMicroClass.aBounds()(index)` and `PostMicroClass.aBounds()(index)` because Java +facades do not carry Scala property metadata. Existing bytecode still performs the same zero-argument getter followed +by an array load. Both companion `baseTrait` generic signatures widen to `Class` in Java; their +raw JVM descriptors remain `()Ljava/lang/Class;`, and both static facades retain their consumer-facing trait type. + +Accepted classfile-only differences also include ordinary Java companion class-initializer flags and removed Scala +signature/marker attributes from the six Java types. + +### Compiler artifacts + +The two `EdgeMicroClass$$anonfun$1...` and two `PostMicroClass$$anonfun$2...` bounds-initializer classes disappear. +Direct nested Java loops need none of them, and the downstream inventory contains no references. The stateful +`PostMicroblockClient$$anonfun$recalcBounds$1` class remains and its complete private surface matches the reference. + +### Validation + +- `EdgeMicroblockCharacterizationTest`: 2 plain-JVM tests, unchanged from the Scala baseline. +- Clean complete plain-JVM suite: 250 tests, 0 failures, 0 errors. +- Java 8 Forge dedicated-server suite: 108 tests, 0 failures, 0 errors, including both generated families, all 96 + populated bounds, even/odd custom placement and in-place Post expansion. +- Raw `javap` comparison confirms identical callable public names/descriptors for all twelve supported types and an + exact private-surface match for the retained Post client traversal closure. +- Actual Edge/Post rendering and neighbour-driven Post shrink geometry remain on the manual checklist. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index 06464ee..db78fd4 100644 --- a/JAVA_MIGRATION_HANDOFF.md +++ b/JAVA_MIGRATION_HANDOFF.md @@ -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`. 140 commits including the API-cleanup plan and separate characterization and -port commits through the corner-microblock factory. +Branch: `algent/java`. Base: `master`. 142 commits including the API-cleanup plan and separate characterization and +port commits through the Edge/Post microblock factories. ## The one rule that matters @@ -67,7 +67,7 @@ awk -F'"' '/ ... }` needs an explicit `AbstractFunction1`. A Java static array getter -also loses Scala property/indexing composition: `FaceMicroClass.aBounds(index)` and -`CornerMicroClass.aBounds(index)` need an extra empty argument list before the index when recompiling, while existing -bytecode remains compatible. +also loses Scala property/indexing composition: the converted Face, Corner, Edge, and Post bounds facades need an +extra empty argument list before the index when recompiling, while existing bytecode remains compatible. **A companion object can be load-bearing without a single bytecode reference.** The inventory's 17 `MODULE$` list is not the whole test — check the reflective string constants too. `MultipartHelper$` is in neither the `MODULE$` list nor @@ -273,7 +272,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. -175 Java files, 16 Scala files, ~3,083 Scala lines left (non-blank; that is the metric this figure has always used). +181 Java files, 16 Scala files, ~3,001 Scala lines left (non-blank; that is the metric this figure has always used). ## What is left, and in what order @@ -507,9 +506,16 @@ bounds, factory identity and generated shape/slot behavior. `CornerMicroblock` d `CornerMicroClass$.MODULE$.getClassId()` call remains exact. Existing binaries retain the same bounds getter; only the two private bounds-initializer closures disappear. -**Medium/high.** `EdgeMicroblock.scala` is next. Treat its Edge and Post families as one source unit: characterize both -factories, placement/custom-post behavior, both bounds tables and all three generated traits before splitting concrete -facade/companion code from retained Scala traits. Do not combine it with `TMicroOcclusion` or generator work. +The Edge/Post source unit is now six Java facade/companion types plus three retained Scala traits. Two plain-JVM cases +freeze all twelve public surfaces, including Post client state and super accessors. Three Forge cases freeze the 84 +edge bounds, 12 post bounds, generated behavior, even-size centre placement and matching-post expansion. ProjectRed's +`EdgeMicroClass$.MODULE$.getClassId()` and UtilitiesInExcess's static `EdgeMicroClass.getClassId()` calls remain exact. +The stateful `PostMicroblockClient` traversal closure remains an exact private-surface match; only four private bounds +initializer closures disappear. + +**High.** `HollowMicroblock.scala` is next. Characterize its placement/factory surfaces, bounds and all hollow-size/ +side geometry plus the large stateful client-render trait before splitting only the concrete facade/companion code. +Keep both generated traits Scala and do not combine this with `TMicroOcclusion` or generator work. **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 diff --git a/JAVA_MIGRATION_MANUAL_CHECKS.md b/JAVA_MIGRATION_MANUAL_CHECKS.md index 20dbb05..88cbe4a 100644 --- a/JAVA_MIGRATION_MANUAL_CHECKS.md +++ b/JAVA_MIGRATION_MANUAL_CHECKS.md @@ -30,6 +30,7 @@ below its table. | [ ] | Start a client with 3D saws enabled, inspect all three saw tiers and the microblock item, then repeat with Angelica installed | Each renderer is registered once, saw models use the correct tier, microblock icons load, client packets register, and the Angelica hook initializes without errors | `MicroblockProxy_clientImpl.init` / `postInit` | | [ ] | Render several block micro-materials with Angelica shaders enabled, then render an unrelated block | Each face receives the matching block/meta shader material and the override is reset after the microblock draw | `MaterialRenderHelper.blockAndMeta` / `render` | | [ ] | Inspect face, hollow, edge and corner microblocks in inventory and as dropped entities | Every size/material combination uses the correct localized name and centered shape/material render | `ItemMicroPart` / `ItemMicroPartRenderer` / `MicroblockRender.renderItem` | +| [ ] | Place crossing posts of different sizes/transparency beside face covers, then add and remove neighbours | Post segments shrink and split at intersections without missing sections or stale render bounds | `PostMicroblockClient.recalcBounds` / `shrinkFace` / `shrinkPost` | ## Placement and interaction @@ -47,7 +48,7 @@ below its table. | Done | Check | Expected | From | | --- | --- | --- | --- | -| [ ] | Load the pack with ProjRed installed and place face and corner illumar lamp microblocks | The lamps generate, use the correct bounds, render and light correctly | `MicroblockGenerator.registerTrait` Scala trait path / `FaceMicroClass` and `CornerMicroClass` facades | +| [ ] | Load the pack with ProjRed installed and place face, corner, edge and post illumar lamp microblocks | The lamps generate, use the correct bounds, render and light correctly | `MicroblockGenerator.registerTrait` Scala trait path / shape factory facades | | [ ] | 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, `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`, `Microblock.microClass/material/shape`, `partList_$eq`, and `BlockMicroMaterial` mixin fields | diff --git a/src/main/scala/codechicken/microblock/EdgeMicroClass$.java b/src/main/scala/codechicken/microblock/EdgeMicroClass$.java new file mode 100644 index 0000000..e15b45b --- /dev/null +++ b/src/main/scala/codechicken/microblock/EdgeMicroClass$.java @@ -0,0 +1,69 @@ +package codechicken.microblock; + +import codechicken.lib.vec.AxisCycle; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Scale; +import codechicken.lib.vec.Transformation; +import codechicken.lib.vec.TransformationList; +import codechicken.lib.vec.Vector3; + +public final class EdgeMicroClass$ extends CommonMicroClass { + + public static final EdgeMicroClass$ MODULE$ = new EdgeMicroClass$(); + + private Cuboid6[] aBounds = new Cuboid6[256]; + + private EdgeMicroClass$() { + for (int edge = 0; edge < 12; edge++) { + int scaleX = (edge & 2) == 0 ? 1 : -1; + int scaleZ = (edge & 1) == 0 ? 1 : -1; + Transformation transform = new TransformationList( + new Scale(new Vector3(scaleX, 1, scaleZ)), + AxisCycle.cycles[edge >> 2]).at(Vector3.center); + + for (int size = 1; size < 8; size++) { + double distance = size / 8D; + aBounds[size << 4 | edge] = new Cuboid6(0, 0, 0, distance, 1, distance).apply(transform); + } + } + } + + public Cuboid6[] aBounds() { + return aBounds; + } + + public void aBounds_$eq(Cuboid6[] bounds) { + aBounds = bounds; + } + + @Override + public int itemSlot() { + return 15; + } + + @Override + public String getName() { + return "mcr_edge"; + } + + @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Class baseTrait() { + return (Class) EdgeMicroblock.class; + } + + @Override + public Class clientTrait() { + return CommonMicroblockClient.class; + } + + @Override + public EdgePlacement$ placementProperties() { + return EdgePlacement$.MODULE$; + } + + @Override + public float getResistanceFactor() { + return 0.5F; + } +} diff --git a/src/main/scala/codechicken/microblock/EdgeMicroClass.java b/src/main/scala/codechicken/microblock/EdgeMicroClass.java new file mode 100644 index 0000000..f10e8a1 --- /dev/null +++ b/src/main/scala/codechicken/microblock/EdgeMicroClass.java @@ -0,0 +1,76 @@ +package codechicken.microblock; + +import net.minecraft.nbt.NBTTagCompound; + +import codechicken.lib.data.MCDataInput; +import codechicken.lib.vec.Cuboid6; + +public final class EdgeMicroClass { + + private EdgeMicroClass() {} + + public static int baseTraitId() { + return EdgeMicroClass$.MODULE$.baseTraitId(); + } + + public static int clientTraitId() { + return EdgeMicroClass$.MODULE$.clientTraitId(); + } + + public static void register() { + EdgeMicroClass$.MODULE$.register(); + } + + public static Microblock create(boolean client, int material) { + return EdgeMicroClass$.MODULE$.create(client, material); + } + + public static Microblock createPart(String name, MCDataInput packet) { + return EdgeMicroClass$.MODULE$.createPart(name, packet); + } + + public static Microblock createPart(String name, NBTTagCompound nbt) { + return EdgeMicroClass$.MODULE$.createPart(name, nbt); + } + + public static int getClassId() { + return EdgeMicroClass$.MODULE$.getClassId(); + } + + public static void register(int id) { + EdgeMicroClass$.MODULE$.register(id); + } + + public static Cuboid6[] aBounds() { + return EdgeMicroClass$.MODULE$.aBounds(); + } + + public static void aBounds_$eq(Cuboid6[] bounds) { + EdgeMicroClass$.MODULE$.aBounds_$eq(bounds); + } + + public static int itemSlot() { + return EdgeMicroClass$.MODULE$.itemSlot(); + } + + public static String getName() { + return EdgeMicroClass$.MODULE$.getName(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static Class baseTrait() { + return (Class) EdgeMicroClass$.MODULE$.baseTrait(); + } + + public static Class clientTrait() { + return EdgeMicroClass$.MODULE$.clientTrait(); + } + + public static EdgePlacement$ placementProperties() { + return EdgeMicroClass$.MODULE$.placementProperties(); + } + + public static float getResistanceFactor() { + return EdgeMicroClass$.MODULE$.getResistanceFactor(); + } +} diff --git a/src/main/scala/codechicken/microblock/EdgeMicroblock.scala b/src/main/scala/codechicken/microblock/EdgeMicroblock.scala deleted file mode 100644 index 84eaed1..0000000 --- a/src/main/scala/codechicken/microblock/EdgeMicroblock.scala +++ /dev/null @@ -1,230 +0,0 @@ -package codechicken.microblock - -import codechicken.lib.vec.Cuboid6 -import codechicken.lib.vec.Scale -import codechicken.lib.vec.Vector3 -import codechicken.lib.vec.TransformationList -import codechicken.lib.vec.AxisCycle -import codechicken.lib.vec.Rotation -import Vector3._ -import Rotation._ -import codechicken.multipart.TMultiPart -import codechicken.multipart.TNormalOcclusion -import codechicken.multipart.NormalOcclusionTest -import codechicken.multipart.JPartialOcclusion -import codechicken.multipart.TileMultipart -import codechicken.multipart.MultiPartRegistry -import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial -import codechicken.lib.raytracer.ExtendedMOP -import codechicken.multipart.TEdgePart -import scala.collection.JavaConversions._ -import codechicken.lib.data.MCDataInput -import codechicken.lib.lighting.LightMatrix - -object EdgePlacement extends PlacementProperties { - import codechicken.multipart.PartMap._ - - def microClass = EdgeMicroClass - - def placementGrid = EdgePlacementGrid$.MODULE$ - - def opposite(slot: Int, side: Int): Int = { - if (slot < 0) // custom placement - return slot - val e = slot - 15 - return 15 + packEdgeBits(e, unpackEdgeBits(e) ^ (1 << (side >> 1))) - } - - override def customPlacement( - pmt: MicroblockPlacement - ): ExecutablePlacement = { - if (pmt.size % 2 == 1) return null - - val part = PostMicroClass.create(pmt.world.isRemote, pmt.material) - part.setShape(pmt.size, pmt.hit.sideHit >> 1) - if (pmt.doExpand) { - val hpart = - pmt.htile.partList.apply(ExtendedMOP.getData[(Int, _)](pmt.hit)._1) - if (hpart.getType == PostMicroClass.getName) { - val mpart = hpart.asInstanceOf[Microblock] - if (mpart.material == pmt.material && mpart.getSize + pmt.size < 8) { - part.shape_$eq( - ((mpart.getSize + pmt.size) << 4 | mpart.getShape).toByte - ) - return pmt.expand(mpart, part) - } - } - } - - if (pmt.slot >= 0) - return null - - if (pmt.internal && !pmt.oppMod) - return pmt.internalPlacement(pmt.htile.asInstanceOf[TileMultipart], part) - - return pmt.externalPlacement(part) - } -} - -object EdgeMicroClass extends CommonMicroClass { - var aBounds: Array[Cuboid6] = new Array(256) - - for (s <- 0 until 12) { - val rx = if ((s & 2) != 0) -1 else 1 - val rz = if ((s & 1) != 0) -1 else 1 - val transform = new TransformationList( - new Scale(new Vector3(rx, 1, rz)), - AxisCycle.cycles(s >> 2) - ).at(center) - - for (t <- 1 until 8) { - val d = t / 8d - aBounds(t << 4 | s) = new Cuboid6(0, 0, 0, d, 1, d).apply(transform) - } - } - - override def itemSlot = 15 - - def getName = "mcr_edge" - - def baseTrait = classOf[EdgeMicroblock] - def clientTrait = classOf[CommonMicroblockClient] - - def placementProperties = EdgePlacement - - def getResistanceFactor = 0.5f -} - -trait EdgeMicroblock extends CommonMicroblock with TEdgePart { - override def setShape(size: Int, slot: Int) = shape_$eq( - (size << 4 | (slot - 15)).toByte - ) - - def microClass = EdgeMicroClass - - def getBounds = EdgeMicroClass.aBounds(shape) - - override def getSlot = getShape + 15 -} - -object PostMicroClass extends MicroblockClass { - var aBounds: Array[Cuboid6] = new Array(256) - - for (s <- 0 until 3) { - val transform = sideRotations(s << 1).at(center) - for (t <- 2 until 8 by 2) { - val d1 = 0.5 - t / 16d - val d2 = 0.5 + t / 16d - aBounds(t << 4 | s) = new Cuboid6(d1, 0, d1, d2, 1, d2).apply(transform) - } - } - - def getName = "mcr_post" - - def baseTrait = classOf[PostMicroblock] - def clientTrait = classOf[PostMicroblockClient] - - def getResistanceFactor = 0.5f -} - -trait PostMicroblockClient extends PostMicroblock with MicroblockClient { - var renderBounds1: Cuboid6 = _ - var renderBounds2: Cuboid6 = _ - - override def render(pos: Vector3, pass: Int) { - val mat = getIMaterial - if (pass == -1) - MicroblockRender.renderCuboid(pos, mat, pass, getBounds, 0) - else { - MicroblockRender.renderCuboid(pos, mat, pass, renderBounds1, 0) - if (renderBounds2 != null) - MicroblockRender.renderCuboid(pos, mat, pass, renderBounds2, 0) - } - } - - override def onPartChanged(part: TMultiPart) { - recalcBounds() - } - - override def onAdded() { - super.onAdded() - recalcBounds() - } - - override def read(packet: MCDataInput) { - super.read(packet) - recalcBounds() - } - - def recalcBounds() { - renderBounds1 = getBounds.copy - renderBounds2 = null - - shrinkFace(getShape << 1) - shrinkFace(getShape << 1 | 1) - - tile.partList.foreach(p => - if (p.isInstanceOf[PostMicroblock] && p != this) - shrinkPost(p.asInstanceOf[PostMicroblock]) - ) - } - - def shrinkFace(fside: Int) { - val part = tile.partMap(fside) - if (part != null && part.getType.equals("mcr_face")) - MicroOcclusion.shrink( - renderBounds1, - part.asInstanceOf[CommonMicroblock].getBounds, - fside - ) - } - - def shrinkPost(post: PostMicroblock) { - if (post == this) - return - - if (thisShrinks(post)) { - if (renderBounds2 == null) - renderBounds2 = getBounds.copy - MicroOcclusion.shrink(renderBounds1, post.getBounds, getShape << 1 | 1) - MicroOcclusion.shrink(renderBounds2, post.getBounds, getShape << 1) - } - } - - def thisShrinks(other: PostMicroblock): Boolean = { - if (getSize != other.getSize) return getSize < other.getSize - if (isTransparent != other.isTransparent) return isTransparent - return getShape > other.getShape - } -} - -trait PostMicroblock - extends Microblock - with JPartialOcclusion - with TNormalOcclusion { - def microClass = PostMicroClass - - def getBounds = PostMicroClass.aBounds(shape) - - def getOcclusionBoxes = Seq(getBounds) - - def getPartialOcclusionBoxes = getOcclusionBoxes - - override def itemClassID = EdgeMicroClass.getClassId - - override def occlusionTest(npart: TMultiPart): Boolean = { - if (npart.isInstanceOf[PostMicroblock]) - return npart.asInstanceOf[PostMicroblock].getShape != getShape - - if (npart.getType.equals("mcr_face")) - if (npart.asInstanceOf[CommonMicroblock].getSlot >> 1 == getShape) - return true - - // TNormalOcclusion is a Java interface, so its box test must be applied here rather than by the super chain. - return NormalOcclusionTest.apply(this, npart) && super.occlusionTest(npart) - } - - def getResistanceFactor = PostMicroClass.getResistanceFactor - - override def canPlaceTorchOnTop = getShape == 0 -} diff --git a/src/main/scala/codechicken/microblock/EdgeMicroblockTraits.scala b/src/main/scala/codechicken/microblock/EdgeMicroblockTraits.scala new file mode 100644 index 0000000..c917edc --- /dev/null +++ b/src/main/scala/codechicken/microblock/EdgeMicroblockTraits.scala @@ -0,0 +1,126 @@ +package codechicken.microblock + +import codechicken.lib.data.MCDataInput +import codechicken.lib.vec.{Cuboid6, Vector3} +import codechicken.multipart.{ + JPartialOcclusion, + NormalOcclusionTest, + TEdgePart, + TMultiPart, + TNormalOcclusion +} +import scala.collection.JavaConversions._ + +trait EdgeMicroblock extends CommonMicroblock with TEdgePart { + override def setShape(size: Int, slot: Int) = shape_$eq( + (size << 4 | (slot - 15)).toByte + ) + + def microClass = EdgeMicroClass$.MODULE$ + + def getBounds = EdgeMicroClass.aBounds()(shape) + + override def getSlot = getShape + 15 +} + +trait PostMicroblockClient extends PostMicroblock with MicroblockClient { + var renderBounds1: Cuboid6 = _ + var renderBounds2: Cuboid6 = _ + + override def render(pos: Vector3, pass: Int) { + val mat = getIMaterial + if (pass == -1) + MicroblockRender.renderCuboid(pos, mat, pass, getBounds, 0) + else { + MicroblockRender.renderCuboid(pos, mat, pass, renderBounds1, 0) + if (renderBounds2 != null) + MicroblockRender.renderCuboid(pos, mat, pass, renderBounds2, 0) + } + } + + override def onPartChanged(part: TMultiPart) { + recalcBounds() + } + + override def onAdded() { + super.onAdded() + recalcBounds() + } + + override def read(packet: MCDataInput) { + super.read(packet) + recalcBounds() + } + + def recalcBounds() { + renderBounds1 = getBounds.copy + renderBounds2 = null + + shrinkFace(getShape << 1) + shrinkFace(getShape << 1 | 1) + + tile.partList.foreach(p => + if (p.isInstanceOf[PostMicroblock] && p != this) + shrinkPost(p.asInstanceOf[PostMicroblock]) + ) + } + + def shrinkFace(fside: Int) { + val part = tile.partMap(fside) + if (part != null && part.getType.equals("mcr_face")) + MicroOcclusion.shrink( + renderBounds1, + part.asInstanceOf[CommonMicroblock].getBounds, + fside + ) + } + + def shrinkPost(post: PostMicroblock) { + if (post == this) + return + + if (thisShrinks(post)) { + if (renderBounds2 == null) + renderBounds2 = getBounds.copy + MicroOcclusion.shrink(renderBounds1, post.getBounds, getShape << 1 | 1) + MicroOcclusion.shrink(renderBounds2, post.getBounds, getShape << 1) + } + } + + def thisShrinks(other: PostMicroblock): Boolean = { + if (getSize != other.getSize) return getSize < other.getSize + if (isTransparent != other.isTransparent) return isTransparent + return getShape > other.getShape + } +} + +trait PostMicroblock + extends Microblock + with JPartialOcclusion + with TNormalOcclusion { + def microClass = PostMicroClass$.MODULE$ + + def getBounds = PostMicroClass.aBounds()(shape) + + def getOcclusionBoxes = Seq(getBounds) + + def getPartialOcclusionBoxes = getOcclusionBoxes + + override def itemClassID = EdgeMicroClass.getClassId() + + override def occlusionTest(npart: TMultiPart): Boolean = { + if (npart.isInstanceOf[PostMicroblock]) + return npart.asInstanceOf[PostMicroblock].getShape != getShape + + if (npart.getType.equals("mcr_face")) + if (npart.asInstanceOf[CommonMicroblock].getSlot >> 1 == getShape) + return true + + // TNormalOcclusion is a Java interface, so its box test must be applied here rather than by the super chain. + return NormalOcclusionTest.apply(this, npart) && super.occlusionTest(npart) + } + + def getResistanceFactor = PostMicroClass.getResistanceFactor() + + override def canPlaceTorchOnTop = getShape == 0 +} diff --git a/src/main/scala/codechicken/microblock/EdgePlacement$.java b/src/main/scala/codechicken/microblock/EdgePlacement$.java new file mode 100644 index 0000000..8b1c54c --- /dev/null +++ b/src/main/scala/codechicken/microblock/EdgePlacement$.java @@ -0,0 +1,57 @@ +package codechicken.microblock; + +import java.util.Objects; + +import codechicken.lib.raytracer.ExtendedMOP; +import codechicken.multipart.PartMap; +import codechicken.multipart.TMultiPart; +import scala.Tuple2; + +public final class EdgePlacement$ extends PlacementProperties { + + public static final EdgePlacement$ MODULE$ = new EdgePlacement$(); + + private EdgePlacement$() {} + + @Override + public EdgeMicroClass$ microClass() { + return EdgeMicroClass$.MODULE$; + } + + @Override + public EdgePlacementGrid$ placementGrid() { + return EdgePlacementGrid$.MODULE$; + } + + @Override + public int opposite(int slot, int side) { + if (slot < 0) return slot; + int edge = slot - 15; + return 15 + PartMap.packEdgeBits(edge, PartMap.unpackEdgeBits(edge) ^ (1 << (side >> 1))); + } + + @Override + public ExecutablePlacement customPlacement(MicroblockPlacement placement) { + if ((placement.size() & 1) != 0) return null; + + Microblock part = PostMicroClass.create(placement.world().isRemote, placement.material()); + part.setShape(placement.size(), placement.hit().sideHit >> 1); + if (placement.doExpand()) { + Tuple2 data = ExtendedMOP.getData(placement.hit()); + TMultiPart hitPart = placement.htile().partList().apply((Integer) data._1()); + if (Objects.equals(hitPart.getType(), PostMicroClass.getName())) { + Microblock microPart = (Microblock) hitPart; + if (microPart.material() == placement.material() && microPart.getSize() + placement.size() < 8) { + part.shape_$eq((byte) ((microPart.getSize() + placement.size()) << 4 | microPart.getShape())); + return placement.expand(microPart, part); + } + } + } + + if (placement.slot() >= 0) return null; + if (placement.internal() && !placement.oppMod()) { + return placement.internalPlacement(placement.htile(), part); + } + return placement.externalPlacement(part); + } +} diff --git a/src/main/scala/codechicken/microblock/EdgePlacement.java b/src/main/scala/codechicken/microblock/EdgePlacement.java new file mode 100644 index 0000000..62f4a99 --- /dev/null +++ b/src/main/scala/codechicken/microblock/EdgePlacement.java @@ -0,0 +1,30 @@ +package codechicken.microblock; + +public final class EdgePlacement { + + private EdgePlacement() {} + + public static ExecutablePlacement customPlacement(MicroblockPlacement placement) { + return EdgePlacement$.MODULE$.customPlacement(placement); + } + + public static EdgeMicroClass$ microClass() { + return EdgePlacement$.MODULE$.microClass(); + } + + public static EdgePlacementGrid$ placementGrid() { + return EdgePlacement$.MODULE$.placementGrid(); + } + + public static int opposite(int slot, int side) { + return EdgePlacement$.MODULE$.opposite(slot, side); + } + + public static boolean expand(int slot, int side) { + return EdgePlacement$.MODULE$.expand(slot, side); + } + + public static boolean sneakOpposite(int slot, int side) { + return EdgePlacement$.MODULE$.sneakOpposite(slot, side); + } +} diff --git a/src/main/scala/codechicken/microblock/PostMicroClass$.java b/src/main/scala/codechicken/microblock/PostMicroClass$.java new file mode 100644 index 0000000..88a78d4 --- /dev/null +++ b/src/main/scala/codechicken/microblock/PostMicroClass$.java @@ -0,0 +1,53 @@ +package codechicken.microblock; + +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Rotation; +import codechicken.lib.vec.Transformation; +import codechicken.lib.vec.Vector3; + +public final class PostMicroClass$ extends MicroblockClass { + + public static final PostMicroClass$ MODULE$ = new PostMicroClass$(); + + private Cuboid6[] aBounds = new Cuboid6[256]; + + private PostMicroClass$() { + for (int axis = 0; axis < 3; axis++) { + Transformation transform = Rotation.sideRotations[axis << 1].at(Vector3.center); + for (int size = 2; size < 8; size += 2) { + double min = 0.5 - size / 16D; + double max = 0.5 + size / 16D; + aBounds[size << 4 | axis] = new Cuboid6(min, 0, min, max, 1, max).apply(transform); + } + } + } + + public Cuboid6[] aBounds() { + return aBounds; + } + + public void aBounds_$eq(Cuboid6[] bounds) { + aBounds = bounds; + } + + @Override + public String getName() { + return "mcr_post"; + } + + @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Class baseTrait() { + return (Class) PostMicroblock.class; + } + + @Override + public Class clientTrait() { + return PostMicroblockClient.class; + } + + @Override + public float getResistanceFactor() { + return 0.5F; + } +} diff --git a/src/main/scala/codechicken/microblock/PostMicroClass.java b/src/main/scala/codechicken/microblock/PostMicroClass.java new file mode 100644 index 0000000..939d2ac --- /dev/null +++ b/src/main/scala/codechicken/microblock/PostMicroClass.java @@ -0,0 +1,60 @@ +package codechicken.microblock; + +import net.minecraft.nbt.NBTTagCompound; + +import codechicken.lib.data.MCDataInput; +import codechicken.lib.vec.Cuboid6; + +public final class PostMicroClass { + + private PostMicroClass() {} + + public static int baseTraitId() { + return PostMicroClass$.MODULE$.baseTraitId(); + } + + public static int clientTraitId() { + return PostMicroClass$.MODULE$.clientTraitId(); + } + + public static void register() { + PostMicroClass$.MODULE$.register(); + } + + public static Microblock create(boolean client, int material) { + return PostMicroClass$.MODULE$.create(client, material); + } + + public static Microblock createPart(String name, MCDataInput packet) { + return PostMicroClass$.MODULE$.createPart(name, packet); + } + + public static Microblock createPart(String name, NBTTagCompound nbt) { + return PostMicroClass$.MODULE$.createPart(name, nbt); + } + + public static Cuboid6[] aBounds() { + return PostMicroClass$.MODULE$.aBounds(); + } + + public static void aBounds_$eq(Cuboid6[] bounds) { + PostMicroClass$.MODULE$.aBounds_$eq(bounds); + } + + public static String getName() { + return PostMicroClass$.MODULE$.getName(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static Class baseTrait() { + return (Class) PostMicroClass$.MODULE$.baseTrait(); + } + + public static Class clientTrait() { + return PostMicroClass$.MODULE$.clientTrait(); + } + + public static float getResistanceFactor() { + return PostMicroClass$.MODULE$.getResistanceFactor(); + } +}