From 9a8bbfd7a75766ae8a7f38ebf44d453d8e091c31 Mon Sep 17 00:00:00 2001 From: Algent Date: Mon, 31 Aug 2026 19:12:26 +0200 Subject: [PATCH] refactor: port missing micro material Preserve the singleton ABI, client stripping, and placeholder registration. --- JAVA_MIGRATION.md | 8 ++ JAVA_MIGRATION_DIVERGENCES.md | 39 ++++++++ JAVA_MIGRATION_HANDOFF.md | 25 +++-- JAVA_MIGRATION_MANUAL_CHECKS.md | 1 + .../microblock/DefaultContent.scala | 2 +- .../microblock/ItemMicroPart.scala | 2 +- .../microblock/MissingMicroMaterial$.java | 91 +++++++++++++++++++ .../microblock/MissingMicroMaterial.java | 68 ++++++++++++++ .../microblock/MissingMicroMaterial.scala | 55 ----------- 9 files changed, 224 insertions(+), 67 deletions(-) create mode 100644 src/main/scala/codechicken/microblock/MissingMicroMaterial$.java create mode 100644 src/main/scala/codechicken/microblock/MissingMicroMaterial.java delete mode 100644 src/main/scala/codechicken/microblock/MissingMicroMaterial.scala diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index f4ee39e..ac15205 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -804,3 +804,11 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec reference. Only the unreferenced compiler-generated `$$anonfun$1` closure disappeared. - All 174 plain-JVM tests and all 91 Java 8 Forge dedicated-server tests pass. The next medium-risk target is `MissingMicroMaterial.scala`; its real icon/render paths remain client-manual work. +- Characterized `MissingMicroMaterial` against untouched Scala. Three plain-JVM cases freeze the exact facade and + companion surfaces, `MODULE$`, inert material values, interface defaults and all client-only boundaries. One Forge + case freezes side stripping and the exact singleton registered under the missing-material name and ID. +- Ported the singleton to a Java facade/companion pair and changed both Scala object-value uses to name `MODULE$` + explicitly. The placeholder key, stone item, sound, strength, resistance and missing-texture render pipeline are + unchanged; only the actual client rendering remains manual. +- All 177 plain-JVM and all 92 Java 8 Forge dedicated-server tests pass. This inert singleton is not a meaningful + focused performance target; `DefaultContent.scala` is the next medium-risk target. diff --git a/JAVA_MIGRATION_DIVERGENCES.md b/JAVA_MIGRATION_DIVERGENCES.md index 106880d..c7e6b45 100644 --- a/JAVA_MIGRATION_DIVERGENCES.md +++ b/JAVA_MIGRATION_DIVERGENCES.md @@ -2041,3 +2041,42 @@ other Java-authored Scala-style setters in this migration, newly recompiled Scal - Java 8 Forge dedicated-server suite: 91 tests, 0 failures, 0 errors. - Raw `javap` comparison confirms identical callable public names/descriptors for all three retained types. The sole class-list removal is the unreferenced compiler closure above. + +## 2026-08-31 — MissingMicroMaterial Java port + +The unresolved-material placeholder is now a Java static facade plus a Java companion singleton implementing +`IMicroMaterial`. `DefaultContent` and `ItemMicroPart` name `MissingMicroMaterial$.MODULE$` explicitly where Scala +previously supplied the object value implicitly. + +### Observable behavior + +No known runtime divergence. The registered key remains `forgemicroblock:missing`; the material remains opaque, +non-luminous, strength 1, cutter strength 0, stone-sounding, explosion resistance 6, and supplies a one-item stone +stack. It still inherits render-pass-zero and solid behavior from the Java `IMicroMaterial` defaults. + +On the client, icon loading still asks the proxy renderer for its safe null icon. Breaking returns that icon and face +rendering still applies its `IconTransformation`, lighting and render pipeline in the same order. On a dedicated +server Forge strips the three client methods from both singleton types and the client-only icon field from the +companion before `DefaultContent` registers it. + +### ABI and source compatibility + +`MissingMicroMaterial` retains its exact 12 public static methods. `MissingMicroMaterial$` retains `MODULE$`, +implements `IMicroMaterial`, and retains the matching 12 public instance methods. Both types keep `@SideOnly(CLIENT)` +on `loadIcons`, `getBreakingIcon` and `renderMicroFace`; neither class is itself side-only. Both jars emit exactly +`MissingMicroMaterial.class` and `MissingMicroMaterial$.class`, and no audited shipping consumer references either +type. + +Accepted classfile-only differences are removed Scala signature/marker attributes, a private constructor on the +facade, removal of the companion's private Scala `icon` getter/setter, and a class initializer without Scala's +`ACC_PUBLIC` flag. None is a callable public member. Recompiled Scala source that passes the singleton as a value must +use `MissingMicroMaterial$.MODULE$`; static calls retain their original names and descriptors. + +### Validation + +- `MissingMicroMaterialCharacterizationTest`: 3 plain-JVM tests, unchanged from the Scala baseline. +- `MissingMicroMaterialFunctionalTest`: 1 Forge test, unchanged from the Scala baseline. +- Complete plain-JVM suite: 177 tests, 0 failures, 0 errors. +- Java 8 Forge dedicated-server suite: 92 tests, 0 failures, 0 errors. +- Raw `javap` comparison confirms identical callable public names/descriptors and the emitted class list is unchanged. +- Missing-texture icon loading and face rendering require a client and remain on the manual checklist. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index 66f3793..3bf9c7a 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`. 100 commits including the incremental-version build fix and separate -characterization and port commits for `MultipartSaveLoad`. +Branch: `algent/java`. Base: `master`. 102 commits including the incremental-version build fix and separate +characterization and port commits for `MissingMicroMaterial`. ## The one rule that matters @@ -67,7 +67,7 @@ awk -F'"' '/ MissingMicroMaterial + case null => MissingMicroMaterial$.MODULE$ case mat => mat } } diff --git a/src/main/scala/codechicken/microblock/MissingMicroMaterial$.java b/src/main/scala/codechicken/microblock/MissingMicroMaterial$.java new file mode 100644 index 0000000..824ce2c --- /dev/null +++ b/src/main/scala/codechicken/microblock/MissingMicroMaterial$.java @@ -0,0 +1,91 @@ +package codechicken.microblock; + +import net.minecraft.block.Block; +import net.minecraft.block.Block.SoundType; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import codechicken.lib.render.uv.IconTransformation; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Vector3; +import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial; +import codechicken.microblock.handler.MicroblockProxy$; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public final class MissingMicroMaterial$ implements IMicroMaterial { + + public static final MissingMicroMaterial$ MODULE$ = new MissingMicroMaterial$(); + + private final String key = "forgemicroblock:missing"; + + @SideOnly(Side.CLIENT) + private IIcon icon; + + private MissingMicroMaterial$() {} + + public String key() { + return key; + } + + @Override + @SideOnly(Side.CLIENT) + public void loadIcons() { + icon = MicroblockProxy$.MODULE$.renderBlocks().getIconSafe(null); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getBreakingIcon(int side) { + return icon; + } + + @Override + @SideOnly(Side.CLIENT) + public void renderMicroFace(Vector3 pos, int pass, Cuboid6 bounds) { + MaterialRenderHelper$.MODULE$.start(pos, pass, new IconTransformation(icon)).lighting().render(); + } + + @Override + public boolean isTransparent() { + return false; + } + + @Override + public int getLightValue() { + return 0; + } + + @Override + public float getStrength(EntityPlayer player) { + return 1f; + } + + @Override + public String getLocalizedName() { + return "Missing Material"; + } + + @Override + public ItemStack getItem() { + return new ItemStack(Blocks.stone); + } + + @Override + public int getCutterStrength() { + return 0; + } + + @Override + public SoundType getSound() { + return Block.soundTypeStone; + } + + @Override + public float explosionResistance(Entity entity) { + return 6f; + } +} diff --git a/src/main/scala/codechicken/microblock/MissingMicroMaterial.java b/src/main/scala/codechicken/microblock/MissingMicroMaterial.java new file mode 100644 index 0000000..2a738d8 --- /dev/null +++ b/src/main/scala/codechicken/microblock/MissingMicroMaterial.java @@ -0,0 +1,68 @@ +package codechicken.microblock; + +import net.minecraft.block.Block.SoundType; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Vector3; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public final class MissingMicroMaterial { + + private MissingMicroMaterial() {} + + public static String key() { + return MissingMicroMaterial$.MODULE$.key(); + } + + @SideOnly(Side.CLIENT) + public static void loadIcons() { + MissingMicroMaterial$.MODULE$.loadIcons(); + } + + @SideOnly(Side.CLIENT) + public static IIcon getBreakingIcon(int side) { + return MissingMicroMaterial$.MODULE$.getBreakingIcon(side); + } + + @SideOnly(Side.CLIENT) + public static void renderMicroFace(Vector3 pos, int pass, Cuboid6 bounds) { + MissingMicroMaterial$.MODULE$.renderMicroFace(pos, pass, bounds); + } + + public static boolean isTransparent() { + return MissingMicroMaterial$.MODULE$.isTransparent(); + } + + public static int getLightValue() { + return MissingMicroMaterial$.MODULE$.getLightValue(); + } + + public static float getStrength(EntityPlayer player) { + return MissingMicroMaterial$.MODULE$.getStrength(player); + } + + public static String getLocalizedName() { + return MissingMicroMaterial$.MODULE$.getLocalizedName(); + } + + public static ItemStack getItem() { + return MissingMicroMaterial$.MODULE$.getItem(); + } + + public static int getCutterStrength() { + return MissingMicroMaterial$.MODULE$.getCutterStrength(); + } + + public static SoundType getSound() { + return MissingMicroMaterial$.MODULE$.getSound(); + } + + public static float explosionResistance(Entity entity) { + return MissingMicroMaterial$.MODULE$.explosionResistance(entity); + } +} diff --git a/src/main/scala/codechicken/microblock/MissingMicroMaterial.scala b/src/main/scala/codechicken/microblock/MissingMicroMaterial.scala deleted file mode 100644 index 1812302..0000000 --- a/src/main/scala/codechicken/microblock/MissingMicroMaterial.scala +++ /dev/null @@ -1,55 +0,0 @@ -package codechicken.microblock - -import codechicken.lib.render.uv.IconTransformation -import codechicken.lib.vec.{Cuboid6, Vector3} -import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial -import codechicken.microblock.handler.MicroblockProxy -import cpw.mods.fml.relauncher.{Side, SideOnly} -import net.minecraft.block.Block -import net.minecraft.block.Block.SoundType -import net.minecraft.entity.Entity -import net.minecraft.entity.player.EntityPlayer -import net.minecraft.init.Blocks -import net.minecraft.item.ItemStack -import net.minecraft.util.IIcon - -/** Stand-in for a material whose name could not be resolved at load time. - * Renders the vanilla missing texture (magenta/black checkerboard) and behaves - * inertly. Resolving an unknown name to this placeholder keeps microblocks - * from silently becoming material id 0 (Blood Rune in GTNH). - */ -object MissingMicroMaterial extends IMicroMaterial { - val key = "forgemicroblock:missing" - - @SideOnly(Side.CLIENT) - private var icon: IIcon = _ - - @SideOnly(Side.CLIENT) - override def loadIcons(): Unit = { - icon = MicroblockProxy.renderBlocks.getIconSafe(null) - } - - @SideOnly(Side.CLIENT) - override def getBreakingIcon(side: Int): IIcon = icon - - @SideOnly(Side.CLIENT) - override def renderMicroFace( - pos: Vector3, - pass: Int, - bounds: Cuboid6 - ): Unit = { - MaterialRenderHelper - .start(pos, pass, new IconTransformation(icon)) - .lighting() - .render() - } - - override def isTransparent: Boolean = false - override def getLightValue: Int = 0 - override def getStrength(player: EntityPlayer): Float = 1f - override def getLocalizedName: String = "Missing Material" - override def getItem: ItemStack = new ItemStack(Blocks.stone) - override def getCutterStrength: Int = 0 - override def getSound: SoundType = Block.soundTypeStone - override def explosionResistance(entity: Entity): Float = 6f -}