diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index 9632bb4..4a1a30f 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -1550,3 +1550,25 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec five `@Mod` versions match both packaged jar versions. External Scala-trait tests remain green; existing manual client checks and Java-source model-bridge limitations remain. Next: `getBytes`, `classNode` and `internalDefine` class-byte loading/cache helpers, characterized first and without loader/cache algorithm changes. +- Investigated the 2026-09-03 ProjectRed placement crash on `60d060a`. The failure occurs in multipart TESR rendering, + not registration: the earlier client-trait port (`970e888`) left an `INVOKEVIRTUAL` call to + `TileMultipartClient.hasDynamicParts()Z` in `MultipartRenderer$`, while Forge exposes that type as an interface. + A raw-jar audit of calls/field accesses to all eight Java-authored tile trait inputs found this one unsafe external + call. The recent Scala-trait registration extraction is not its cause. +- Added four Forge regression cases executing the shipped renderer method body against generated client tiles. + Only GL/pass services and the final drawing callback are recorded, because the dedicated server strips the actual + `TMultiPart.renderDynamic` method. Static and empty early returns, non-client rejection, render-state setup and + exact dynamic coordinates/frame/pass are covered. The final tests were rerun against the broken renderer: both + nonempty cases raise the same `IncompatibleClassChangeError` as the supplied crash. This closes the call-site gap + left by earlier client-tile tests, which invoked trait methods through method handles. +- Added a default-false `TileMultipart.hasDynamicParts()` base hook and routed the renderer's flag query through it. + Generated client tiles already supply the overriding getter. The original checked client-trait cast and guards + remain; no generator algorithm or runtime trait interface changes. The additive base method is recorded in the + existing divergence entry. Reference source/jar, reproduction reports and scripts are saved under ignored + `run/renderer-compatibility-review/`; the manual checklist records the failed full-client check and required retest. +- Clean formatting/checkstyle/build and Forge pass after stopping Gradle: 333 JVM / 163 Forge tests, zero + failures/errors/skips. All 455 class APIs match except the new base hook, and 3,713 other method bodies match. + No unsafe external calls/field accesses to the eight transformed Java tile inputs remain. All 40 generated outputs + keep their instructions: 34 names/hashes are exact; six composites are renumbered by the new tests' earlier client + tile construction. The dev config and forced Scala-compilation guard remain unchanged; all five `@Mod` versions + match both packaged jars. Full-client placement/rendering with the fixed jar still needs confirmation. diff --git a/JAVA_MIGRATION_DIVERGENCES.md b/JAVA_MIGRATION_DIVERGENCES.md index 8118b93..60dc329 100644 --- a/JAVA_MIGRATION_DIVERGENCES.md +++ b/JAVA_MIGRATION_DIVERGENCES.md @@ -74,7 +74,7 @@ Other retained `$class` bridges and `MODULE$` companions are not covered by this | `JItemMultiPart` | Static `hitDepth` and `onItemUse(part, ...)` implementations | | `MicroMaterialRegistry` | Static `setupIDMap`, `calcMaxCuttingStrength` and `loadIcons` forwarders | | `PacketScheduler` / `TScheduledPacketPart` | Static `sendScheduled()` on the facade and `readMask(part, packet)` on the interface | -| `TileMultipart` | No-op `renderStatic`, `renderDynamic` and `randomDisplayTick` hooks for dispatching generated overrides through a stable superclass | +| `TileMultipart` | `hasDynamicParts` (false by default), `renderStatic`, `renderDynamic` and `randomDisplayTick` hooks for dispatching generated overrides through a stable superclass | | `MultipartMixinFactory` | Four additional static forwarders: `onCompiled`, `autoCompleteJavaTrait` and the two mangled `ASMMixinFactory` parent helpers. Scala emitted them when the base became Java with its original public JVM access; the Java facade retains them. Existing facade entries are unchanged. | Previously abstract JVM interface methods now have Java defaults, allowing inheritance without Scala forwarders: diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index 912c7b6..3d85bd5 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`. 185 commits including the API-cleanup plan, divergence-log cleanup, ports -through Scala-trait registration metadata, and the ASM characterization backfill and review fixes. +Branch: `algent/java`. Base: `master`. 187 commits including the API-cleanup plan, divergence-log cleanup, ports +through Scala-trait registration metadata, the ASM characterization backfill, and review/client-rendering fixes. The multipart review corrections (`5af333c`) are on `algent/java`; subsequent migration work continues in that branch. @@ -76,7 +76,7 @@ awk -F'"' '/ render(new TileMultipart())); + assertTrue(RenderServices.events.isEmpty()); + } + + private static TileMultipart newClientTile() throws Exception { + assertTrue( + TileMultipartClient.class.isInterface(), + "Exercise the transformed runtime type, not the Java input"); + BitSet traits = new BitSet(); + traits.set(MultipartMixinFactory.getId(TileMultipartClient.class.getName().replace('.', '/'))); + TileMultipart generated = (TileMultipart) MultipartMixinFactory.construct(traits, Nil$.MODULE$); + // Keep the real generated interface/flag getter. Drawing is recorded because Forge strips the actual + // TMultiPart.renderDynamic method on this dedicated server. + ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); + String parent = Type.getInternalName(generated.getClass()); + writer.visit(V1_8, ACC_PUBLIC, "codechicken/multipart/test/RendererRecordingTile", null, parent, null); + MethodVisitor init = writer.visitMethod(ACC_PUBLIC, "", "()V", null, null); + init.visitCode(); + init.visitVarInsn(ALOAD, 0); + init.visitMethodInsn(INVOKESPECIAL, parent, "", "()V", false); + init.visitInsn(RETURN); + init.visitMaxs(0, 0); + init.visitEnd(); + String descriptor = "(Lcodechicken/lib/vec/Vector3;FI)V"; + MethodVisitor draw = writer.visitMethod(ACC_PUBLIC, "renderDynamic", descriptor, null, null); + draw.visitCode(); + draw.visitVarInsn(ALOAD, 1); + draw.visitVarInsn(FLOAD, 2); + draw.visitVarInsn(ILOAD, 3); + draw.visitMethodInsn(INVOKESTATIC, Type.getInternalName(RenderServices.class), "draw", descriptor, false); + draw.visitInsn(RETURN); + draw.visitMaxs(0, 0); + draw.visitEnd(); + writer.visitEnd(); + return (TileMultipart) new BodyLoader().define(writer.toByteArray()).getConstructor().newInstance(); + } + + private static void setParts(TileMultipart tile, TMultiPart... parts) { + tile.partList_$eq(JavaConversions.asScalaBuffer(Arrays.asList(parts)).toList()); + } + + private static void setField(TileMultipart tile, String name, Object value) throws Exception { + Field field = tile.getClass().getSuperclass().getDeclaredField(name); + field.setAccessible(true); + field.set(tile, value); + } + + private static void render(TileEntity tile) throws Exception { + Object renderer = RendererBody.TYPE.getConstructor().newInstance(); + try { + RendererBody.METHOD.invoke(renderer, tile, 1.25, -2.5, 3.75, 0.625F); + } catch (InvocationTargetException failure) { + Throwable cause = failure.getCause(); + if (cause instanceof Error) throw (Error) cause; + if (cause instanceof Exception) throw (Exception) cause; + throw new AssertionError(cause); + } + } + + private static final class RendererBody { + + static final Class TYPE; + static final Method METHOD; + + static { + try { + // Loading the client-only TESR class on a server is forbidden. Copy its actual method body without + // changing any tile casts, field accesses or invocation opcodes; only rendering services are replaced. + ClassNode source = new ClassNode(); + try (InputStream input = MultipartRendererFunctionalTest.class + .getResourceAsStream("/codechicken/multipart/MultipartRenderer$.class")) { + assertNotNull(input); + new ClassReader(input).accept(source, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); + } + ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + String name = "codechicken/multipart/test/HeadlessMultipartRenderer"; + writer.visit(V1_8, ACC_PUBLIC, name, null, "java/lang/Object", null); + MethodVisitor init = writer.visitMethod(ACC_PUBLIC, "", "()V", null, null); + init.visitCode(); + init.visitVarInsn(ALOAD, 0); + init.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); + init.visitInsn(RETURN); + init.visitMaxs(0, 0); + init.visitEnd(); + boolean found = false; + for (MethodNode method : source.methods) { + if (!method.name.equals("renderTileEntityAt")) continue; + assertFalse(found); + found = true; + MethodVisitor target = writer.visitMethod(ACC_PUBLIC, method.name, method.desc, null, null); + method.accept(new RemappingMethodAdapter(ACC_PUBLIC, method.desc, target, new Remapper() { + + @Override + public String map(String internalName) { + if (internalName.equals("codechicken/lib/render/CCRenderState") + || internalName.equals("net/minecraftforge/client/MinecraftForgeClient")) + return Type.getInternalName(RenderServices.class); + return internalName; + } + })); + } + assertTrue(found); + writer.visitEnd(); + TYPE = new BodyLoader().define(writer.toByteArray()); + METHOD = TYPE.getMethod( + "renderTileEntityAt", + TileEntity.class, + double.class, + double.class, + double.class, + float.class); + } catch (Exception failure) { + throw new ExceptionInInitializerError(failure); + } + } + } + + private static final class BodyLoader extends ClassLoader { + + BodyLoader() { + super(MultipartRendererFunctionalTest.class.getClassLoader()); + } + + Class define(byte[] bytes) { + return defineClass(null, bytes, 0, bytes.length); + } + } + + public static final class RenderServices { + + static final RenderServices INSTANCE = new RenderServices(); + static final List events = new ArrayList<>(); + public boolean useNormals; + static int dynamicCalls; + static Vector3 position; + static float frame; + static int pass; + + public static void draw(Vector3 position, float frame, int pass) { + assertTrue(INSTANCE.useNormals); + events.add("tile"); + dynamicCalls++; + RenderServices.position = position; + RenderServices.frame = frame; + RenderServices.pass = pass; + } + + public static RenderServices instance() { + events.add("instance"); + return INSTANCE; + } + + public void resetInstance() { + events.add("reset"); + useNormals = false; + } + + public void pullLightmapInstance() { + events.add("lightmap"); + } + + public static int getRenderPass() { + events.add("pass"); + return 1; + } + } + + private static final class RecordingPart extends TMultiPart { + + @Override + public String getType() { + return "renderer-regression"; + } + + } +} diff --git a/src/main/scala/codechicken/multipart/MultipartRenderer$.java b/src/main/scala/codechicken/multipart/MultipartRenderer$.java index 48c77df..bcd42e8 100644 --- a/src/main/scala/codechicken/multipart/MultipartRenderer$.java +++ b/src/main/scala/codechicken/multipart/MultipartRenderer$.java @@ -39,9 +39,8 @@ public final class MultipartRenderer$ extends TileEntitySpecialRenderer implemen @Override public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f) { - TileMultipartClient client = (TileMultipartClient) t; - TileMultipart tile = (TileMultipart) t; - if (tile.partList().isEmpty() || !client.hasDynamicParts()) { + TileMultipart tile = TileMultipart.class.cast((TileMultipartClient) t); + if (tile.partList().isEmpty() || !tile.hasDynamicParts()) { return; } diff --git a/src/main/scala/codechicken/multipart/TileMultipart.java b/src/main/scala/codechicken/multipart/TileMultipart.java index 2657656..a54f413 100644 --- a/src/main/scala/codechicken/multipart/TileMultipart.java +++ b/src/main/scala/codechicken/multipart/TileMultipart.java @@ -263,6 +263,11 @@ public class TileMultipart extends TileEntity implements IChunkLoadTile { worldObj.func_147479_m(xCoord, yCoord, zCoord); } + /** Stable class-call target for the flag getter generated by the TileMultipartClient runtime interface. */ + public boolean hasDynamicParts() { + return false; + } + /** Client render hook overridden by generated tiles carrying TileMultipartClient. */ public boolean renderStatic(IBlockAccess world, Vector3 position, RenderBlocks renderer) { return false;