mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-19 03:49:05 +00:00
refactor: port microblock packet handlers
Preserve the registry channel, singleton ABI, client skip, and handshake payload.
This commit is contained in:
1 parent
7152b5e394
commit
471c767d33
10 files changed
+209
-87
No files matched your search
+13
-1
@@ -30,7 +30,9 @@ and lifecycle rewriting, `TRedstoneTile` removed the measured redstone allocatio
|
||||
state plus inherited access, `TFluidHandlerTile` preserved ordered Forge fluid distribution, and
|
||||
`TIInventoryTile`/`JInventoryTile` preserved AE2's direct rebuild linkage plus flattened sided inventory routing.
|
||||
`TileMultipartClient` and `TRandomDisplayTickTile` complete the built-in trait queue with their render-cache and random
|
||||
display-tick behavior intact. All retain their exact runtime interfaces. See `JAVA_MIGRATION_PROFILE.md`.
|
||||
display-tick behavior intact. The first handler wave now also includes both mod entry points, both event handlers and
|
||||
the ForgeMicroblock registry packet handlers. All retain their exact runtime interfaces. See
|
||||
`JAVA_MIGRATION_PROFILE.md`.
|
||||
|
||||
That audit found and this branch has now repaired one existing regression: Schematica 1.12.6 reflects the original private
|
||||
`MultiPartRegistry$` field `codechicken$multipart$MultiPartRegistry$$typeMap` and casts it to a Scala mutable map. The
|
||||
@@ -784,3 +786,13 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
unchanged; their actual rendering remains on the client manual checklist.
|
||||
- All 164 plain-JVM and all 86 Java 8 Forge dedicated-server tests pass. This event-only adapter is not a meaningful
|
||||
focused performance target; `microblock/handler/packethandlers.scala` is next.
|
||||
- Characterized the ForgeMicroblock packet-handler unit against untouched Scala. Seven plain-JVM cases freeze the
|
||||
shared channel base, both facade/companion surfaces and exact packet interfaces, the integrated-server registry
|
||||
skip, ordered missing-material disconnect, unknown-type `MatchError` and no-op server callback. One Forge case
|
||||
freezes the handshake channel, type and complete material-ID payload.
|
||||
- Ported all five emitted packet-handler classes to Java and changed the two Scala proxy registrations to pass the
|
||||
companion singletons explicitly. Every callable public member and the emitted class list match the reference; the
|
||||
registry channel and wire format are unchanged.
|
||||
- All 171 plain-JVM tests pass. The Java 8 Forge source set and new handshake case compile, but this checkout's server
|
||||
run stopped before mod loading because the Minecraft EULA has not been accepted; the last completed Forge baseline
|
||||
remains 86 tests until that user-controlled prerequisite is satisfied.
|
||||
@@ -1957,3 +1957,47 @@ constructor. Neither changes runtime annotations or the callable public surface.
|
||||
- Raw `javap` comparison confirms identical callable public members, reflection confirms identical annotations, and
|
||||
the emitted class list is unchanged.
|
||||
- Texture stitching and placement-highlight rendering require a client and remain on the manual checklist.
|
||||
|
||||
## 2026-08-31 — ForgeMicroblock packet-handler Java port
|
||||
|
||||
The shared packet-handler base and both client/server facade-companion pairs are now Java. Scala proxy code registers
|
||||
`MicroblockCPH$.MODULE$` and `MicroblockSPH$.MODULE$` explicitly, preserving the singleton objects CodeChickenLib
|
||||
receives.
|
||||
|
||||
### Observable behavior
|
||||
|
||||
No known runtime divergence. The registry channel remains `ForgeMicroblock`. Client packet type 1 still skips the
|
||||
material-map read in an integrated single-player game, avoiding mutation of the registry shared with the server. A
|
||||
multiplayer client still reads the complete map and disconnects with translation key `microblock.missing` plus the
|
||||
ordered, comma-separated missing names. Unknown client packet types still throw `scala.MatchError`.
|
||||
|
||||
The server packet callback remains a no-op. The handshake still sends packet type 1 on `ForgeMicroblock`, followed by
|
||||
the material count and every registered material name in ID order.
|
||||
|
||||
### ABI and source compatibility
|
||||
|
||||
`MicroblockPH` retains its public constructor and `registryChannel()` accessor. `MicroblockCPH` and `MicroblockSPH`
|
||||
retain their exact static forwarders. Their companion classes retain `MODULE$`, extend `MicroblockPH`, implement the
|
||||
same CodeChickenLib packet interfaces in the same order, and expose the same instance methods. No audited shipping
|
||||
consumer references these types.
|
||||
|
||||
Both jars emit exactly `MicroblockPH.class`, `MicroblockCPH.class`, `MicroblockCPH$.class`, `MicroblockSPH.class` and
|
||||
`MicroblockSPH$.class`. Accepted classfile-only differences are the removed Scala signature/marker attributes, private
|
||||
constructors on the static facades, and companion class initializers without Scala's `ACC_PUBLIC` flag. A class
|
||||
initializer is invoked only by the JVM and cannot be named by caller bytecode.
|
||||
|
||||
Recompiled in-repo Scala now passes `MicroblockCPH$.MODULE$` and `MicroblockSPH$.MODULE$` where the object values were
|
||||
previously implicit, and calls the Java no-arg channel accessors with parentheses. Compiled external callers still
|
||||
target the same classes, fields, method names and descriptors.
|
||||
|
||||
### Validation
|
||||
|
||||
- `MicroblockPacketHandlerCharacterizationTest` and `MicroblockPacketHandlerBehaviorTest`: 7 plain-JVM tests,
|
||||
unchanged from the Scala baseline.
|
||||
- `MicroblockPacketHandlerFunctionalTest`: 1 Forge handshake test, unchanged from the Scala baseline and compiled into
|
||||
the functional-test jar.
|
||||
- Complete plain-JVM suite: 171 tests, 0 failures, 0 errors.
|
||||
- Raw `javap` comparison confirms identical callable public names/descriptors and interface order for all five types;
|
||||
the emitted class list is unchanged.
|
||||
- The Java 8 Forge run is pending: `runFunctionalTestServer` stopped before mod loading because this checkout has not
|
||||
accepted the Minecraft EULA. The last completed server baseline remains 86 passing tests.
|
||||
+21
-11
@@ -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`. 96 commits including the incremental-version build fix and separate
|
||||
characterization and port commits for `MicroblockEventHandler`.
|
||||
Branch: `algent/java`. Base: `master`. 98 commits including the incremental-version build fix and separate
|
||||
characterization and port commits for the ForgeMicroblock packet handlers.
|
||||
|
||||
## The one rule that matters
|
||||
|
||||
@@ -67,7 +67,9 @@ 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: **164 plain-JVM tests, 86 Forge server tests, all passing at their last completed runs.**
|
||||
Current baseline: **171 plain-JVM tests passing.** The last completed Forge server run has **86 passing tests**; the
|
||||
new handshake test compiles, but this checkout currently stops before mod loading because its Minecraft EULA has not
|
||||
been accepted.
|
||||
|
||||
### ABI diff against the reference
|
||||
|
||||
@@ -241,7 +243,8 @@ All eight load-bearing `$class` helpers from the inventory, both registries, and
|
||||
`IRedstonePart`/`RedstoneInteractions` unit, `MicroRecipe`, and the `TPartialOcclusionTile`, `TSlottedTile`, and
|
||||
`TRedstoneTile`, `TTileChangeTile`, `TFluidHandlerTile`, `TIInventoryTile`/`JInventoryTile`, `TileMultipartClient`, and
|
||||
`TRandomDisplayTickTile` Java-trait ports, plus `MultipartCompatiblity`/`MCPCCompatModule`, `MultipartMod`,
|
||||
`MultipartEventHandler`, `MicroblockMod`, and `MicroblockEventHandler`.
|
||||
`MultipartEventHandler`, `MicroblockMod`, `MicroblockEventHandler`, and the complete `MicroblockPH`/
|
||||
`MicroblockCPH`/`MicroblockSPH` packet-handler unit.
|
||||
|
||||
Plus the six marker interfaces: `TSlottedPart`, `IRandomDisplayTick`, `INeighborTileChange`, `TRandomUpdateTick`,
|
||||
`ISidedHollowConnect`, `IMicroMaterialRender`, plus `MultipartHelper`, `TileCache`, `PacketScheduler` and the `ControlKeyModifer` pair.
|
||||
@@ -256,7 +259,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.
|
||||
|
||||
103 Java files, 33 Scala files, ~5,071 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
108 Java files, 32 Scala files, ~5,008 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
|
||||
## What is left, and in what order
|
||||
|
||||
@@ -363,6 +366,12 @@ and both client-only boundaries retain their exact shape. The proxy registers `M
|
||||
explicitly. Two plain-JVM tests freeze the raw ABI; one Forge test proves the client methods are stripped on a
|
||||
dedicated server while the companion still reaches event-bus registration.
|
||||
|
||||
The ForgeMicroblock packet-handler unit is now Java. `MicroblockPH` keeps its channel accessor; both static facades,
|
||||
both companion singletons and their three CodeChickenLib packet interfaces retain their exact public descriptors.
|
||||
Seven plain-JVM tests freeze the raw ABI, integrated-server skip, ordered disconnect, unknown-type failure and no-op
|
||||
server callback. The Forge handshake test freezes the exact channel, type and material-ID payload; it compiles but
|
||||
still needs the EULA-gated server run in this checkout.
|
||||
|
||||
**Medium.** The `handler` packages on both sides, `ItemMicroPart`,
|
||||
`MicroblockPlacement`, `PlacementGrids`, `BlockMicroMaterial`, `MissingMicroMaterial`, `ConfigContent`,
|
||||
`DefaultContent`.
|
||||
@@ -371,10 +380,11 @@ dedicated server while the companion still reaches event-bus registration.
|
||||
narrow generator relaxation: Java-trait parent linearization, explicit field-accessor recognition, and exclusion of
|
||||
transient runtime caches from generated copying.
|
||||
|
||||
Take `microblock/handler/packethandlers.scala` next; at 66 nonblank lines it is the smallest remaining handler unit.
|
||||
Freeze `MicroblockPH.registryChannel`, both packet-handler facade/companion surfaces and their exact interfaces before
|
||||
changing it. Cover the single-player client skip, missing-material disconnect, server handshake channel/type and ID-map
|
||||
payload, and the no-op server packet callback. Keep the characterization and port commits separate.
|
||||
Take `multipart/handler/MultipartSaveLoad.scala` next once the Forge harness can run; at 89 nonblank lines it is the
|
||||
smallest remaining handler unit. Its `MultipartSaveLoad$.MODULE$` and `loadingWorld()` accessor are load-bearing for
|
||||
ProjectRed, so freeze the facade/companion shape, mutable converter-list identity, `TileNBTContainer`, reflective map
|
||||
hooks and all replace/remove branches before changing it. Existing helper and event-handler Forge tests cover several
|
||||
paths but are not a substitute for a dedicated untouched-Scala characterization commit.
|
||||
|
||||
**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.
|
||||
@@ -394,8 +404,8 @@ all of `multipart/asm/`. The ASM subsystem should be last; freeze generated-clas
|
||||
jar instead sees concrete Java mixin inputs and can emit class/field opcodes that are invalid after Forge rewrites
|
||||
them to interfaces. Provide a transformed compile stub or downstream source guidance before claiming
|
||||
source-compatible rebuilds.
|
||||
- Microblock-specific NBT and packet payloads still need characterization immediately before that subsystem changes;
|
||||
the compact core tile/part fixture is complete.
|
||||
- Microblock-specific NBT still needs characterization immediately before that subsystem changes. The registry
|
||||
handshake packet's channel, type, count and ordered material names are now frozen.
|
||||
- `TileMultipart` still republishes an immutable Scala `Seq` on every mutation. Its internal read paths now avoid Java
|
||||
list copies and wrappers; the remaining mutable snapshots at add/remove sites are intentional.
|
||||
- The focused synthetic redstone allocation is resolved (80.5 B to 0.0 B per three-query iteration). A representative
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package codechicken.microblock.handler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
import net.minecraft.network.play.server.S40PacketDisconnect;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import codechicken.lib.packet.PacketCustom;
|
||||
import codechicken.lib.packet.PacketCustom.IClientPacketHandler;
|
||||
import codechicken.microblock.MicroMaterialRegistry;
|
||||
import scala.MatchError;
|
||||
|
||||
public final class MicroblockCPH$ extends MicroblockPH implements IClientPacketHandler {
|
||||
|
||||
public static final MicroblockCPH$ MODULE$ = new MicroblockCPH$();
|
||||
|
||||
private MicroblockCPH$() {}
|
||||
|
||||
@Override
|
||||
public void handlePacket(PacketCustom packet, Minecraft minecraft, INetHandlerPlayClient netHandler) {
|
||||
int type = packet.getType();
|
||||
if (type == 1) {
|
||||
if (!minecraft.isSingleplayer()) {
|
||||
handleMaterialRegistration(packet, netHandler);
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new MatchError(type);
|
||||
}
|
||||
|
||||
public void handleMaterialRegistration(PacketCustom packet, INetHandlerPlayClient netHandler) {
|
||||
List<String> missing = MicroMaterialRegistry.readIDMap(packet);
|
||||
if (!missing.isEmpty()) {
|
||||
netHandler.handleDisconnect(
|
||||
new S40PacketDisconnect(
|
||||
new ChatComponentTranslation("microblock.missing", String.join(", ", missing))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package codechicken.microblock.handler;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.play.INetHandlerPlayClient;
|
||||
|
||||
import codechicken.lib.packet.PacketCustom;
|
||||
|
||||
public final class MicroblockCPH {
|
||||
|
||||
private MicroblockCPH() {}
|
||||
|
||||
public static String registryChannel() {
|
||||
return MicroblockCPH$.MODULE$.registryChannel();
|
||||
}
|
||||
|
||||
public static void handlePacket(PacketCustom packet, Minecraft minecraft, INetHandlerPlayClient netHandler) {
|
||||
MicroblockCPH$.MODULE$.handlePacket(packet, minecraft, netHandler);
|
||||
}
|
||||
|
||||
public static void handleMaterialRegistration(PacketCustom packet, INetHandlerPlayClient netHandler) {
|
||||
MicroblockCPH$.MODULE$.handleMaterialRegistration(packet, netHandler);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package codechicken.microblock.handler;
|
||||
|
||||
public class MicroblockPH {
|
||||
|
||||
private final String registryChannel = "ForgeMicroblock";
|
||||
|
||||
public String registryChannel() {
|
||||
return registryChannel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package codechicken.microblock.handler;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.play.INetHandlerPlayServer;
|
||||
|
||||
import codechicken.lib.packet.PacketCustom;
|
||||
import codechicken.lib.packet.PacketCustom.IHandshakeHandler;
|
||||
import codechicken.lib.packet.PacketCustom.IServerPacketHandler;
|
||||
import codechicken.microblock.MicroMaterialRegistry;
|
||||
|
||||
public final class MicroblockSPH$ extends MicroblockPH implements IServerPacketHandler, IHandshakeHandler {
|
||||
|
||||
public static final MicroblockSPH$ MODULE$ = new MicroblockSPH$();
|
||||
|
||||
private MicroblockSPH$() {}
|
||||
|
||||
@Override
|
||||
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer netHandler) {}
|
||||
|
||||
@Override
|
||||
public void handshakeRecieved(NetHandlerPlayServer netHandler) {
|
||||
PacketCustom packet = new PacketCustom(registryChannel(), 1);
|
||||
MicroMaterialRegistry.writeIDMap(packet);
|
||||
netHandler.sendPacket(packet.toPacket());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package codechicken.microblock.handler;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.play.INetHandlerPlayServer;
|
||||
|
||||
import codechicken.lib.packet.PacketCustom;
|
||||
|
||||
public final class MicroblockSPH {
|
||||
|
||||
private MicroblockSPH() {}
|
||||
|
||||
public static String registryChannel() {
|
||||
return MicroblockSPH$.MODULE$.registryChannel();
|
||||
}
|
||||
|
||||
public static void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer netHandler) {
|
||||
MicroblockSPH$.MODULE$.handlePacket(packet, sender, netHandler);
|
||||
}
|
||||
|
||||
public static void handshakeRecieved(NetHandlerPlayServer netHandler) {
|
||||
MicroblockSPH$.MODULE$.handshakeRecieved(netHandler);
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
package codechicken.microblock.handler
|
||||
|
||||
import codechicken.lib.packet.PacketCustom.{
|
||||
IHandshakeHandler,
|
||||
IClientPacketHandler,
|
||||
IServerPacketHandler
|
||||
}
|
||||
import codechicken.lib.packet.PacketCustom
|
||||
import net.minecraft.client.Minecraft
|
||||
import codechicken.microblock.MicroMaterialRegistry
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.minecraft.network.play.{INetHandlerPlayServer, INetHandlerPlayClient}
|
||||
import net.minecraft.network.play.server.S40PacketDisconnect
|
||||
import net.minecraft.util.ChatComponentTranslation
|
||||
import net.minecraft.network.NetHandlerPlayServer
|
||||
|
||||
class MicroblockPH {
|
||||
val registryChannel =
|
||||
"ForgeMicroblock" // Must use the 250 system for ID registry as the NetworkMod idMap hasn't been properly initialized from the server yet.
|
||||
}
|
||||
|
||||
object MicroblockCPH extends MicroblockPH with IClientPacketHandler {
|
||||
def handlePacket(
|
||||
packet: PacketCustom,
|
||||
mc: Minecraft,
|
||||
netHandler: INetHandlerPlayClient
|
||||
) {
|
||||
packet.getType match {
|
||||
// In singleplayer the integrated server and this client share the one
|
||||
// static registry, so the id-map packet is redundant. Skipping it avoids
|
||||
// rebuilding (clearing) the shared maps on the netty thread while the
|
||||
// server thread reads them - the race that turned microblocks into Blood
|
||||
// Rune slabs.
|
||||
case 1 =>
|
||||
if (!mc.isSingleplayer)
|
||||
handleMaterialRegistration(packet, netHandler)
|
||||
}
|
||||
}
|
||||
|
||||
def handleMaterialRegistration(
|
||||
packet: PacketCustom,
|
||||
netHandler: INetHandlerPlayClient
|
||||
) {
|
||||
val missing = MicroMaterialRegistry.readIDMap(packet)
|
||||
if (!missing.isEmpty)
|
||||
netHandler.handleDisconnect(
|
||||
new S40PacketDisconnect(
|
||||
new ChatComponentTranslation(
|
||||
"microblock.missing",
|
||||
String.join(", ", missing)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object MicroblockSPH
|
||||
extends MicroblockPH
|
||||
with IServerPacketHandler
|
||||
with IHandshakeHandler {
|
||||
def handlePacket(
|
||||
packet: PacketCustom,
|
||||
sender: EntityPlayerMP,
|
||||
netHandler: INetHandlerPlayServer
|
||||
) {}
|
||||
|
||||
def handshakeRecieved(netHandler: NetHandlerPlayServer) {
|
||||
val packet = new PacketCustom(registryChannel, 1)
|
||||
MicroMaterialRegistry.writeIDMap(packet)
|
||||
netHandler.sendPacket(packet.toPacket)
|
||||
}
|
||||
}
|
||||
@@ -108,8 +108,8 @@ class MicroblockProxy_serverImpl {
|
||||
def postInit() {
|
||||
MicroMaterialRegistry.calcMaxCuttingStrength()
|
||||
PacketCustom.assignHandshakeHandler(
|
||||
MicroblockSPH.registryChannel,
|
||||
MicroblockSPH
|
||||
MicroblockSPH.registryChannel(),
|
||||
MicroblockSPH$.MODULE$
|
||||
)
|
||||
if (Loader.isModLoaded("postea")) {
|
||||
PosteaCompat.registerTransformers()
|
||||
@@ -126,7 +126,10 @@ class MicroblockProxy_clientImpl extends MicroblockProxy_serverImpl {
|
||||
super.postInit()
|
||||
MicroMaterialRegistry.loadIcons()
|
||||
MinecraftForgeClient.registerItemRenderer(itemMicro, ItemMicroPartRenderer)
|
||||
PacketCustom.assignHandler(MicroblockCPH.registryChannel, MicroblockCPH)
|
||||
PacketCustom.assignHandler(
|
||||
MicroblockCPH.registryChannel(),
|
||||
MicroblockCPH$.MODULE$
|
||||
)
|
||||
|
||||
if (Loader.isModLoaded("angelica"))
|
||||
MicroblockMod.angelicaCompat_$eq(new AngelicaCompat)
|
||||
|
||||
Reference in new issue
Block a user