refactor: port multipart proxy to java

This commit is contained in:
Algent committed 2026-09-01 00:08:20 +02:00
1 parent e6278a8d14
commit 0f84ff203e
11 files changed
+311 -139

No files matched your search

+12
View File
@@ -1022,3 +1022,15 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
Extra Utilities is the sole exception and is constrained rather than fixed. The pattern is a three-step ratchet:
FMP adds a supported equivalent (additive, safe now), the consumer is patched and released, then FMP drops the
private shape in a release allowed to break that ABI.
### 2026-09-01
- Characterized `MultipartProxy` against untouched Scala. Four plain-JVM cases freeze the four-type hierarchy, exact
facade/companion surfaces, mutable singleton accessors, client-only boundaries and both chunk-index conversions. One
Forge case freezes dedicated-server stripping, virtual fallback to the server implementation and initialized proxy
state.
- Ported the hierarchy and facade to four Java types without changing their emitted names or callable public
descriptors. Common generated-tile registration now names `MultipartProxy$.MODULE$` explicitly so it still reaches
the inherited server method after Forge strips the client override and its static forwarder.
- All 187 plain-JVM and all 96 Java 8 Forge dedicated-server tests pass. Startup registration and two bit-packing
helpers are not a meaningful focused performance target; `microblock/handler/proxies.scala` is next.
+49
View File
@@ -2156,3 +2156,52 @@ methods remain common-side and therefore survive dedicated-server stripping, mat
- Java 8 Forge dedicated-server suite: 95 tests, 0 failures, 0 errors.
- A clean build followed by raw `javap` comparison confirms identical callable public names/descriptors and emitted
classes. The clean step is material: Zinc otherwise retained and packaged the deleted Scala class files.
## 2026-09-01 — MultipartProxy Java port
The multipart server/client proxy hierarchy is now Java, including the static facade and load-bearing companion
singleton. ProjectRed's direct `MultipartProxy$.MODULE$` block access and BuildCraftCompat/Iguana Tweaks' static
`MultipartProxy.block()`/`config()` calls therefore keep the same owners and descriptors.
### Observable behavior
No known runtime divergence. Pre-init still records the logger, opens `multipart.cfg`, registers the same eight
generated-tile traits in the same order, registers and resolves the multipart block, then hooks saved-tile loading.
Post-init still registers the same event-handler singleton on both buses, assigns both server packet handlers, starts
the tick scheduler and chunk-load hook, and loads compatibility hooks in the same order.
Client post-init still follows common post-init with the multipart block renderer, both client packet channels, and
the control-key event/key-binding registrations. Generated tile classes are still registered for save/load before a
client renderer is bound. The two chunk-index conversions retain their exact bit packing, including signed input.
On a dedicated server Forge strips `postInit` and `onTileClassBuilt` from `MultipartProxy_clientImpl` and strips their
static facade forwarders. `MultipartProxy$.MODULE$` then resolves both calls to `MultipartProxy_serverImpl`, exactly as
the Scala hierarchy did. The common `MultipartGenerator` callback now spells that companion call explicitly; calling
the stripped facade would fail after the Java port even though its raw dev-jar ABI is correct.
### ABI, annotations and source compatibility
All four emitted types remain: `MultipartProxy_serverImpl`, `MultipartProxy_clientImpl`, `MultipartProxy`, and
`MultipartProxy$`. The inheritance and final flags are unchanged. The server implementation retains its exact ten
public methods and three private fields; the client implementation declares only its two overrides; the facade keeps
all twelve public static forwarders; and the companion declares only `MODULE$` plus both instance index conversions.
Every callable public descriptor matches the reference.
Only the two client overrides and their facade forwarders retain `@SideOnly(CLIENT)`; no class is side-only. The
facade and companion still share mutable block/config/logger state while separately constructed server proxies remain
independent.
Accepted classfile-only differences are removed Scala signature/marker attributes, a private constructor on the
static facade, and a companion class initializer without Scala's `ACC_PUBLIC` flag. Both jars emit exactly the same
four proxy classes. An unused Scala wildcard import was removed from the packet-handler source.
### Validation
- `MultipartProxyCharacterizationTest`: 4 plain-JVM tests, unchanged from the Scala baseline.
- `MultipartProxyFunctionalTest`: 1 Forge test, unchanged from the Scala baseline.
- Complete plain-JVM suite: 187 tests, 0 failures, 0 errors.
- Java 8 Forge dedicated-server suite: 96 tests, 0 failures, 0 errors.
- A clean build followed by raw `javap` comparison confirms identical emitted classes, hierarchy, fields, callable
public names/descriptors and client-only method annotations.
- Client renderer, packet, key-binding and generated-tile renderer registration require a client and remain on the
manual checklist.
+17 -9
View File
@@ -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`. 106 commits including the incremental-version build fix and separate
characterization and port commits for `GrassMicroMaterial`/`TopMicroMaterial`.
Branch: `algent/java`. Base: `master`. 109 commits including the API-cleanup plan and separate characterization and
port commits for `MultipartProxy`.
## The one rule that matters
@@ -67,7 +67,7 @@ awk -F'"' '/<testsuite /{t+=$4;f+=$8;e+=$10} END{print "tests="t" failures="f" e
grep -o 'tests="[0-9]*" skipped="[0-9]*" failures="[0-9]*" errors="[0-9]*"' run/server/junit-out/TEST-*.xml
```
Current baseline: **183 plain-JVM tests and 95 Java 8 Forge dedicated-server tests passing.** The ignored local server
Current baseline: **187 plain-JVM tests and 96 Java 8 Forge dedicated-server tests passing.** The ignored local server
EULA is accepted in this checkout.
### ABI diff against the reference
@@ -251,6 +251,7 @@ All eight load-bearing `$class` helpers from the inventory, both registries, and
`MultipartEventHandler`, `MicroblockMod`, `MicroblockEventHandler`, and the complete `MicroblockPH`/
`MicroblockCPH`/`MicroblockSPH` packet-handler unit, plus `MultipartSaveLoad`, `MissingMicroMaterial`,
`DefaultContent`, and `GrassMicroMaterial`/`TopMicroMaterial`.
The complete `MultipartProxy` server/client hierarchy and static facade are also Java.
Plus the six marker interfaces: `TSlottedPart`, `IRandomDisplayTick`, `INeighborTileChange`, `TRandomUpdateTick`,
`ISidedHollowConnect`, `IMicroMaterialRender`, plus `MultipartHelper`, `TileCache`, `PacketScheduler` and the `ControlKeyModifer` pair.
@@ -265,7 +266,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.
117 Java files, 28 Scala files, ~4,760 Scala lines left (non-blank; that is the metric this figure has always used).
121 Java files, 27 Scala files, ~4,647 Scala lines left (non-blank; that is the metric this figure has always used).
## What is left, and in what order
@@ -400,6 +401,13 @@ descriptors. Five plain-JVM tests freeze horizontal/side UV routing, grass base/
and raw ABI; one Forge test freezes registration and the methods that remain after dedicated-server stripping. Actual
icons, tint and face output remain client-manual.
`MultipartProxy` is now Java. The server/client inheritance, three mutable fields and Scala-style accessors, static
facade, `MODULE$` companion and both index conversions retain their exact callable public shape. ProjectRed,
BuildCraftCompat and Iguana Tweaks keep their load-bearing block/config access. Forge strips the two client overrides
and matching static forwarders on a dedicated server; common generated-tile registration therefore calls the
companion directly and resolves to the inherited server implementation. Client renderer, packet, key-binding and
generated-tile renderer registration remain on the manual checklist.
**Medium.** The `handler` packages on both sides, `ItemMicroPart`,
`MicroblockPlacement`, `PlacementGrids`, `BlockMicroMaterial`, `ConfigContent`,
and the remaining material/render units.
@@ -408,11 +416,11 @@ and the remaining material/render units.
narrow generator relaxation: Java-trait parent linearization, explicit field-accessor recognition, and exclusion of
transient runtime caches from generated copying.
Take `multipart/handler/proxies.scala` next. At 112 nonblank lines it is the smaller remaining handler proxy unit and
owns load-bearing `MultipartProxy.block`/`config` access used by ProjectRed, BuildCraftCompat and Iguana Tweaks. Freeze
the server/client inheritance, mutable accessors, static facade plus `MODULE$`, both chunk-index conversions, common
registration order and the client-only overrides/side stripping. Keep client renderer, packet and key-binding
registration on the manual checklist, and keep the characterization and port commits separate.
Take `microblock/handler/proxies.scala` next. At 127 nonblank lines it is the other remaining handler proxy unit and
owns load-bearing `MicroblockProxy` item/saw access used by Iguana Tweaks and in-repo rendering/recipes. Freeze the
server/client inheritance, all mutable accessors, protected saw collection, static facade plus `MODULE$`, item/recipe
registration order and the lazy client renderer with its side stripping. Keep item renderers, packet registration and
Angelica integration on the manual checklist, and keep the characterization and port commits separate.
**Phase 6/7, last.** `Microblock` and the microblock shape hierarchy, `MicroblockGenerator`, `MultipartGenerator`, and
all of `multipart/asm/`. The ASM subsystem should be last; freeze generated-class fixtures before touching it.
+1
View File
@@ -22,6 +22,7 @@ release that includes those ports.
| Load a saved microblock whose material is no longer installed | The part remains present and renders the magenta/black missing texture instead of becoming material ID 0 | `MissingMicroMaterial` |
| Change a mixed multipart tile containing static and dynamically rendered parts | Static parts remain in the block render, dynamic parts remain in the TESR pass, and neither disappears after a part update | `TileMultipartClient` render caches |
| Watch a multipart torch long enough to emit display particles | Only parts implementing `IRandomDisplayTick` emit particles, with no duplicate or missing callbacks | `TRandomDisplayTickTile.randomDisplayTick` |
| Start a client, join a server, place/update a multipart and use the multipart control key | Block and generated-tile rendering work, client packets arrive, and control-key state changes are sent once without duplicate registrations | `MultipartProxy_clientImpl.postInit` / `onTileClassBuilt` |
## Placement and interaction
@@ -3,7 +3,7 @@ package codechicken.multipart
import net.minecraft.tileentity.TileEntity
import net.minecraft.world.World
import codechicken.lib.vec.BlockCoord
import codechicken.multipart.handler.MultipartProxy
import codechicken.multipart.handler.{MultipartProxy, MultipartProxy$}
import codechicken.lib.packet.PacketCustom
import net.minecraft.network.play.server.S23PacketBlockChange
import java.util.BitSet
@@ -235,6 +235,6 @@ object MultipartGenerator extends ScratchBitSet {
traits: BitSet
) {
tileTraitMap.put(clazz, traits.copy)
MultipartProxy.onTileClassBuilt(clazz)
MultipartProxy$.MODULE$.onTileClassBuilt(clazz)
}
}
@@ -0,0 +1,23 @@
package codechicken.multipart.handler;
import net.minecraft.world.ChunkCoordIntPair;
import codechicken.lib.vec.BlockCoord;
public final class MultipartProxy$ extends MultipartProxy_clientImpl {
public static final MultipartProxy$ MODULE$ = new MultipartProxy$();
private MultipartProxy$() {}
public BlockCoord indexInChunk(ChunkCoordIntPair chunk, int index) {
return new BlockCoord(
chunk.chunkXPos << 4 | index & 0xF,
index >> 8 & 0xFF,
chunk.chunkZPos << 4 | (index & 0xF0) >> 4);
}
public int indexInChunk(BlockCoord pos) {
return pos.x & 0xF | pos.y << 8 | (pos.z & 0xF) << 4;
}
}
@@ -0,0 +1,69 @@
package codechicken.multipart.handler;
import java.io.File;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.ChunkCoordIntPair;
import org.apache.logging.log4j.Logger;
import codechicken.lib.config.ConfigFile;
import codechicken.lib.vec.BlockCoord;
import codechicken.multipart.BlockMultipart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public final class MultipartProxy {
private MultipartProxy() {}
public static BlockMultipart block() {
return MultipartProxy$.MODULE$.block();
}
public static void block_$eq(BlockMultipart block) {
MultipartProxy$.MODULE$.block_$eq(block);
}
public static ConfigFile config() {
return MultipartProxy$.MODULE$.config();
}
public static void config_$eq(ConfigFile config) {
MultipartProxy$.MODULE$.config_$eq(config);
}
public static Logger logger() {
return MultipartProxy$.MODULE$.logger();
}
public static void logger_$eq(Logger logger) {
MultipartProxy$.MODULE$.logger_$eq(logger);
}
public static void preInit(File cfgdir, Logger logger) {
MultipartProxy$.MODULE$.preInit(cfgdir, logger);
}
public static void init() {
MultipartProxy$.MODULE$.init();
}
@SideOnly(Side.CLIENT)
public static void postInit() {
MultipartProxy$.MODULE$.postInit();
}
@SideOnly(Side.CLIENT)
public static void onTileClassBuilt(Class<? extends TileEntity> type) {
MultipartProxy$.MODULE$.onTileClassBuilt(type);
}
public static BlockCoord indexInChunk(ChunkCoordIntPair chunk, int index) {
return MultipartProxy$.MODULE$.indexInChunk(chunk, index);
}
public static int indexInChunk(BlockCoord pos) {
return MultipartProxy$.MODULE$.indexInChunk(pos);
}
}
@@ -0,0 +1,34 @@
package codechicken.multipart.handler;
import net.minecraft.tileentity.TileEntity;
import codechicken.lib.packet.PacketCustom;
import codechicken.multipart.ControlKeyHandler;
import codechicken.multipart.MultipartRenderer$;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class MultipartProxy_clientImpl extends MultipartProxy_serverImpl {
@Override
@SideOnly(Side.CLIENT)
public void postInit() {
super.postInit();
RenderingRegistry.registerBlockHandler(MultipartRenderer$.MODULE$);
PacketCustom.assignHandler(MultipartCPH$.MODULE$.channel(), MultipartCPH$.MODULE$);
PacketCustom.assignHandler(MultipartCPH$.MODULE$.registryChannel(), MultipartCPH$.MODULE$);
FMLCommonHandler.instance().bus().register(ControlKeyHandler.INSTANCE);
ClientRegistry.registerKeyBinding(ControlKeyHandler.INSTANCE);
}
@Override
@SideOnly(Side.CLIENT)
public void onTileClassBuilt(Class<? extends TileEntity> type) {
super.onTileClassBuilt(type);
ClientRegistry.bindTileEntitySpecialRenderer(type, MultipartRenderer$.MODULE$);
}
}
@@ -0,0 +1,104 @@
package codechicken.multipart.handler;
import java.io.File;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.Logger;
import codechicken.lib.config.ConfigFile;
import codechicken.lib.packet.PacketCustom;
import codechicken.lib.world.TileChunkLoadHook;
import codechicken.lib.world.WorldExtensionManager;
import codechicken.multipart.BlockMultipart;
import codechicken.multipart.MultipartGenerator;
import codechicken.multipart.TickScheduler$;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.GameRegistry;
public class MultipartProxy_serverImpl {
private BlockMultipart block;
private ConfigFile config;
private Logger logger;
public BlockMultipart block() {
return block;
}
public void block_$eq(BlockMultipart block) {
this.block = block;
}
public ConfigFile config() {
return config;
}
public void config_$eq(ConfigFile config) {
this.config = config;
}
public Logger logger() {
return logger;
}
public void logger_$eq(Logger logger) {
this.logger = logger;
}
public void preInit(File cfgdir, Logger logger) {
this.logger = logger;
config = new ConfigFile(new File(cfgdir, "multipart.cfg")).setComment("Multipart API config file");
MultipartGenerator
.registerTrait("codechicken.multipart.TSlottedPart", "codechicken.multipart.scalatraits.TSlottedTile");
MultipartGenerator.registerTrait(
"net.minecraftforge.fluids.IFluidHandler",
"codechicken.multipart.scalatraits.TFluidHandlerTile");
MultipartGenerator.registerTrait(
"net.minecraft.inventory.IInventory",
"codechicken.multipart.scalatraits.JInventoryTile");
MultipartGenerator.registerTrait(
"net.minecraft.inventory.ISidedInventory",
"codechicken.multipart.scalatraits.JInventoryTile");
MultipartGenerator.registerTrait(
"codechicken.multipart.JPartialOcclusion",
"codechicken.multipart.scalatraits.TPartialOcclusionTile");
MultipartGenerator.registerTrait(
"codechicken.multipart.IRedstonePart",
"codechicken.multipart.scalatraits.TRedstoneTile");
MultipartGenerator.registerTrait(
"codechicken.multipart.IRandomDisplayTick",
"codechicken.multipart.scalatraits.TRandomDisplayTickTile",
null);
MultipartGenerator.registerTrait(
"codechicken.multipart.INeighborTileChange",
null,
"codechicken.multipart.scalatraits.TTileChangeTile");
GameRegistry.registerBlock(new BlockMultipart().setBlockName("multipart"), null, "block");
block = (BlockMultipart) Block.blockRegistry.getObject("ForgeMultipart:block");
MultipartSaveLoad.hookLoader();
}
public void init() {}
public void postInit() {
FMLCommonHandler.instance().bus().register(MultipartEventHandler$.MODULE$);
MinecraftForge.EVENT_BUS.register(MultipartEventHandler$.MODULE$);
PacketCustom.assignHandler(MultipartSPH$.MODULE$.channel(), MultipartSPH$.MODULE$);
PacketCustom.assignHandshakeHandler(MultipartSPH$.MODULE$.registryChannel(), MultipartSPH$.MODULE$);
WorldExtensionManager.registerWorldExtension(TickScheduler$.MODULE$);
TileChunkLoadHook.init();
MultipartCompatiblity.load();
}
public void onTileClassBuilt(Class<? extends TileEntity> type) {
MultipartSaveLoad.registerTileClass(type);
}
}
@@ -23,7 +23,6 @@ import codechicken.lib.data.MCDataOutputWrapper
import java.io.DataOutputStream
import java.io.ByteArrayOutputStream
import net.minecraft.world.ChunkCoordIntPair
import MultipartProxy._
import codechicken.multipart.PacketScheduler
import java.util.LinkedList
import scala.collection.JavaConversions._
@@ -1,127 +0,0 @@
package codechicken.multipart.handler
import codechicken.multipart._
import cpw.mods.fml.client.registry.RenderingRegistry
import cpw.mods.fml.client.registry.ClientRegistry
import net.minecraft.tileentity.TileEntity
import codechicken.lib.config.ConfigFile
import java.io.File
import net.minecraftforge.common.MinecraftForge
import cpw.mods.fml.relauncher.SideOnly
import cpw.mods.fml.relauncher.Side
import codechicken.lib.packet.PacketCustom
import net.minecraft.world.ChunkCoordIntPair
import codechicken.lib.vec.BlockCoord
import codechicken.lib.world.{TileChunkLoadHook, WorldExtensionManager}
import cpw.mods.fml.common.FMLCommonHandler
import cpw.mods.fml.common.registry.GameRegistry
import net.minecraft.block.Block
import org.apache.logging.log4j.Logger
class MultipartProxy_serverImpl {
var block: BlockMultipart = _
var config: ConfigFile = _
var logger: Logger = _
def preInit(cfgdir: File, logger: Logger) {
this.logger = logger
config = new ConfigFile(new File(cfgdir, "multipart.cfg"))
.setComment("Multipart API config file")
MultipartGenerator.registerTrait(
"codechicken.multipart.TSlottedPart",
"codechicken.multipart.scalatraits.TSlottedTile"
)
MultipartGenerator.registerTrait(
"net.minecraftforge.fluids.IFluidHandler",
"codechicken.multipart.scalatraits.TFluidHandlerTile"
)
MultipartGenerator.registerTrait(
"net.minecraft.inventory.IInventory",
"codechicken.multipart.scalatraits.JInventoryTile"
)
MultipartGenerator.registerTrait(
"net.minecraft.inventory.ISidedInventory",
"codechicken.multipart.scalatraits.JInventoryTile"
)
MultipartGenerator.registerTrait(
"codechicken.multipart.JPartialOcclusion",
"codechicken.multipart.scalatraits.TPartialOcclusionTile"
)
MultipartGenerator.registerTrait(
"codechicken.multipart.IRedstonePart",
"codechicken.multipart.scalatraits.TRedstoneTile"
)
MultipartGenerator.registerTrait(
"codechicken.multipart.IRandomDisplayTick",
"codechicken.multipart.scalatraits.TRandomDisplayTickTile",
null
)
MultipartGenerator.registerTrait(
"codechicken.multipart.INeighborTileChange",
null,
"codechicken.multipart.scalatraits.TTileChangeTile"
)
GameRegistry.registerBlock(
new BlockMultipart().setBlockName("multipart"),
null,
"block"
)
block = Block.blockRegistry
.getObject("ForgeMultipart:block")
.asInstanceOf[BlockMultipart]
MultipartSaveLoad.hookLoader()
}
def init() {}
def postInit() {
FMLCommonHandler.instance().bus().register(MultipartEventHandler$.MODULE$)
MinecraftForge.EVENT_BUS.register(MultipartEventHandler$.MODULE$)
PacketCustom.assignHandler(MultipartSPH.channel, MultipartSPH)
PacketCustom.assignHandshakeHandler(
MultipartSPH.registryChannel,
MultipartSPH
)
WorldExtensionManager.registerWorldExtension(TickScheduler$.MODULE$)
TileChunkLoadHook.init()
MultipartCompatiblity.load()
}
def onTileClassBuilt(t: Class[_ <: TileEntity]) {
MultipartSaveLoad.registerTileClass(t)
}
}
class MultipartProxy_clientImpl extends MultipartProxy_serverImpl {
@SideOnly(Side.CLIENT)
override def postInit() {
super.postInit()
RenderingRegistry.registerBlockHandler(MultipartRenderer$.MODULE$)
PacketCustom.assignHandler(MultipartCPH.channel, MultipartCPH)
PacketCustom.assignHandler(MultipartCPH.registryChannel, MultipartCPH)
FMLCommonHandler.instance().bus().register(ControlKeyHandler.INSTANCE)
ClientRegistry.registerKeyBinding(ControlKeyHandler.INSTANCE)
}
@SideOnly(Side.CLIENT)
override def onTileClassBuilt(t: Class[_ <: TileEntity]) {
super.onTileClassBuilt(t)
ClientRegistry.bindTileEntitySpecialRenderer(t, MultipartRenderer$.MODULE$)
}
}
object MultipartProxy extends MultipartProxy_clientImpl {
def indexInChunk(cc: ChunkCoordIntPair, i: Int) = new BlockCoord(
cc.chunkXPos << 4 | i & 0xf,
(i >> 8) & 0xff,
cc.chunkZPos << 4 | (i & 0xf0) >> 4
)
def indexInChunk(pos: BlockCoord) =
pos.x & 0xf | pos.y << 8 | (pos.z & 0xf) << 4
}