mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-26 15:03:18 +00:00
refactor: port microblock event handler
Preserve the client-only ABI and dedicated-server side stripping.
This commit is contained in:
1 parent
cd84c140ae
commit
1c91fbb4c9
8 files changed
+143
-56
No files matched your search
@@ -772,3 +772,15 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
Scala cannot apply property-assignment syntax to a Java-authored setter. The compiled accessor ABI is unchanged.
|
||||
- All 162 plain-JVM and all 85 Java 8 Forge dedicated-server tests pass. Startup and lifecycle dispatch are not a
|
||||
meaningful focused throughput or allocation target; `MicroblockEventHandler.scala` is the next target.
|
||||
- Reproduced the reported stale incremental `@Mod(version)` failure immediately after a commit. Gradle reran
|
||||
`compileScala`, but Zinc retained the joint-compiled Java classes that had inlined the previous `Tags.VERSION`.
|
||||
- Configured `compileScala` to force Zinc recompilation whenever Gradle schedules the task. The focused version test
|
||||
passes without cleaning both before and after a commit changes the generated version, so the assertion remains.
|
||||
- Characterized `MicroblockEventHandler` against untouched Scala. Two plain-JVM cases freeze both singleton types, all
|
||||
four public event methods, normal event metadata and both client-only boundaries. One Forge case freezes companion
|
||||
registration and complete method stripping on a dedicated server.
|
||||
- Ported the handler to a Java facade/companion pair and changed the one Scala registration to name `MODULE$`
|
||||
explicitly. Texture-atlas filtering, highlight guards, matrix/render sequence and cancellation behavior are
|
||||
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.
|
||||
@@ -1917,3 +1917,43 @@ constructor. Neither changes runtime annotation data or the callable public surf
|
||||
lifecycle, initializes every proxy item and builds a usable material ID map before shutting down cleanly.
|
||||
- Raw `javap` comparison confirms identical callable public names/descriptors; reflection confirms identical FML
|
||||
annotations, and the emitted class list is unchanged.
|
||||
|
||||
## 2026-08-30 — MicroblockEventHandler Java port
|
||||
|
||||
The ForgeMicroblock client event handler is now a Java facade/companion pair. The server proxy explicitly registers
|
||||
`MicroblockEventHandler$.MODULE$`, preserving the Scala object's identity.
|
||||
|
||||
### Observable behavior
|
||||
|
||||
No known runtime divergence. Post-stitch handling still reloads material icons only for texture-map type zero.
|
||||
Highlight handling retains the same ordered guards for a non-null current stack, the microblock item, a non-null hit
|
||||
and a block hit. It then pushes the GL matrix, translates to world coordinates, delegates to the item renderer, cancels
|
||||
only when that renderer succeeds, and pops the matrix in the same sequence.
|
||||
|
||||
Both handlers remain client-only. On a dedicated server Forge strips both methods from both singleton types before
|
||||
the proxy registers the companion. Registration still reaches the event bus and records the same companion owner, but
|
||||
there are correctly no server-side subscribers.
|
||||
|
||||
### ABI, annotations and source compatibility
|
||||
|
||||
`MicroblockEventHandler` retains the exact two public static methods. `MicroblockEventHandler$` retains `MODULE$` and
|
||||
the matching two public instance methods. Every method still carries `@SubscribeEvent` with `NORMAL` priority and
|
||||
`receiveCanceled = false`, plus `@SideOnly(CLIENT)`; neither class is itself side-only. Public names and descriptors are
|
||||
identical to the reference, and both jars emit exactly `MicroblockEventHandler.class` and
|
||||
`MicroblockEventHandler$.class`.
|
||||
|
||||
The in-repo Scala registration now spells the object value as `MicroblockEventHandler$.MODULE$`. Compiled external
|
||||
callers and event-bus identity are unchanged, and no frozen binary or audited source consumer names either type.
|
||||
|
||||
Accepted divergence: Scala signature/marker attributes disappear, and the static Java facade gains only a private
|
||||
constructor. Neither changes runtime annotations or the callable public surface.
|
||||
|
||||
### Validation
|
||||
|
||||
- `MicroblockEventHandlerCharacterizationTest`: 2 plain-JVM tests, unchanged from the Scala baseline.
|
||||
- `MicroblockEventHandlerFunctionalTest`: 1 Forge test, unchanged from the Scala baseline.
|
||||
- Complete plain-JVM suite: 164 tests, 0 failures, 0 errors.
|
||||
- Java 8 Forge dedicated-server suite: 86 tests, 0 failures, 0 errors.
|
||||
- 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.
|
||||
+19
-10
@@ -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`. 93 commits including separate characterization and port commits for
|
||||
`MicroblockMod`.
|
||||
Branch: `algent/java`. Base: `master`. 96 commits including the incremental-version build fix and separate
|
||||
characterization and port commits for `MicroblockEventHandler`.
|
||||
|
||||
## 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: **162 plain-JVM tests, 85 Forge server tests, all passing at their last completed runs.**
|
||||
Current baseline: **164 plain-JVM tests, 86 Forge server tests, all passing at their last completed runs.**
|
||||
|
||||
### ABI diff against the reference
|
||||
|
||||
@@ -156,6 +156,11 @@ raw jar but inherits `@SideOnly(CLIENT)` from the client override, so Forge stri
|
||||
and a Java call fails with `NoSuchMethodError`. Call `MultipartProxy$.MODULE$.postInit()` as the Scala reference did;
|
||||
after side stripping, virtual resolution reaches the server superclass implementation.
|
||||
|
||||
**Generated version constants require full Zinc recompilation.** `Tags.VERSION` is a compile-time constant embedded in
|
||||
the joint-compiled Java `@Mod` annotations. Gradle notices the generated classpath change, but Zinc does not invalidate
|
||||
those Java consumers. `compileScala.scalaCompileOptions.force = true` keeps incremental jars current; do not remove the
|
||||
version assertions or this build guard without replacing both with an equivalent mechanism.
|
||||
|
||||
**Classes that cannot class-initialize headless make good probes.** `MultipartSaveLoad` reflects into `TileEntity`'s
|
||||
static maps through `ObfMapping` and always throws under a plain JVM. That turns "did this branch reach the loader?"
|
||||
into an assertion: returning normally proves the guard short-circuited, and `assertThrows(LinkageError.class, ...)`
|
||||
@@ -236,7 +241,7 @@ 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`, and `MicroblockMod`.
|
||||
`MultipartEventHandler`, `MicroblockMod`, and `MicroblockEventHandler`.
|
||||
|
||||
Plus the six marker interfaces: `TSlottedPart`, `IRandomDisplayTick`, `INeighborTileChange`, `TRandomUpdateTick`,
|
||||
`ISidedHollowConnect`, `IMicroMaterialRender`, plus `MultipartHelper`, `TileCache`, `PacketScheduler` and the `ControlKeyModifer` pair.
|
||||
@@ -251,7 +256,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.
|
||||
|
||||
101 Java files, 34 Scala files, ~5,112 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
103 Java files, 33 Scala files, ~5,071 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
|
||||
## What is left, and in what order
|
||||
|
||||
@@ -353,6 +358,11 @@ lifecycle/IMC methods, the mutable `angelicaCompat` accessors and `MODULE$` reta
|
||||
annotations. FML still uses the companion as its mod instance and completes the full microblock server lifecycle. Two
|
||||
plain-JVM and one Forge test freeze the shape, shared compatibility hook, companion identity and initialized registry.
|
||||
|
||||
`MicroblockEventHandler` is now Java. Both singleton class names, all four public event methods, both event annotations
|
||||
and both client-only boundaries retain their exact shape. The proxy registers `MicroblockEventHandler$.MODULE$`
|
||||
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.
|
||||
|
||||
**Medium.** The `handler` packages on both sides, `ItemMicroPart`,
|
||||
`MicroblockPlacement`, `PlacementGrids`, `BlockMicroMaterial`, `MissingMicroMaterial`, `ConfigContent`,
|
||||
`DefaultContent`.
|
||||
@@ -361,11 +371,10 @@ plain-JVM and one Forge test freeze the shape, shared compatibility hook, compan
|
||||
narrow generator relaxation: Java-trait parent linearization, explicit field-accessor recognition, and exclusion of
|
||||
transient runtime caches from generated copying.
|
||||
|
||||
Take `microblock/handler/MicroblockEventHandler.scala` next. Freeze both singleton class names and all four public
|
||||
event-method descriptors, both `@SubscribeEvent` annotations and both `@SideOnly(CLIENT)` boundaries. Preserve the
|
||||
companion identity registered on `MinecraftForge.EVENT_BUS`; the dedicated server can verify registration and safe
|
||||
side stripping, while texture stitching and highlight rendering remain client-only manual checks. Keep the
|
||||
characterization and port commits separate.
|
||||
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.
|
||||
|
||||
**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.
|
||||
|
||||
@@ -14,7 +14,8 @@ release that includes those ports.
|
||||
| Hit a part repeatedly without breaking it | Hit particles spawn on the struck face, using that face's icon | `IconHitEffects.addHitEffects` |
|
||||
| Break a part fully | Destroy particles use all six side icons and are scaled to the part's bounds | `IconHitEffects.addDestroyEffects` |
|
||||
| Break a hollow cover | Destroy particles use the full block bounds, not the part bounds | `addDestroyEffects` scaleDensity false |
|
||||
| Hover a microblock placement target | The placement highlight renders, and a mod supplying its own highlight renderer overrides it | `MicroMaterialRegistry.renderHighlight` |
|
||||
| Hover a microblock placement target | The placement highlight renders, and a mod supplying its own highlight renderer overrides it | `MicroblockEventHandler.drawBlockHighlight` / `MicroMaterialRegistry.renderHighlight` |
|
||||
| Reload client resources after placing several microblock materials | The texture atlas reloads every material icon without missing textures | `MicroblockEventHandler.postTextureStitch` |
|
||||
| Look at a saw in inventory and in hand | The saw item renders with its custom transform | `ItemSaw` `IItemRenderer` |
|
||||
| Place microblocks of several materials, including glass | Transparent materials render in the correct pass and are not opaque | `IMicroMaterial.canRenderInPass` |
|
||||
| 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 |
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package codechicken.microblock.handler;
|
||||
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.render.RenderUtils;
|
||||
import codechicken.microblock.ItemMicroPartRenderer$;
|
||||
import codechicken.microblock.MicroMaterialRegistry;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public final class MicroblockEventHandler$ {
|
||||
|
||||
public static final MicroblockEventHandler$ MODULE$ = new MicroblockEventHandler$();
|
||||
|
||||
private MicroblockEventHandler$() {}
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void postTextureStitch(TextureStitchEvent.Post event) {
|
||||
if (event.map.getTextureType() == 0) {
|
||||
MicroMaterialRegistry.loadIcons();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void drawBlockHighlight(DrawBlockHighlightEvent event) {
|
||||
if (event.currentItem != null && event.currentItem.getItem() == MicroblockProxy$.MODULE$.itemMicro()
|
||||
&& event.target != null
|
||||
&& event.target.typeOfHit == MovingObjectType.BLOCK) {
|
||||
GL11.glPushMatrix();
|
||||
RenderUtils.translateToWorldCoords(event.player, event.partialTicks);
|
||||
if (ItemMicroPartRenderer$.MODULE$.renderHighlight(event.player, event.currentItem, event.target)) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package codechicken.microblock.handler;
|
||||
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public final class MicroblockEventHandler {
|
||||
|
||||
private MicroblockEventHandler() {}
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void postTextureStitch(TextureStitchEvent.Post event) {
|
||||
MicroblockEventHandler$.MODULE$.postTextureStitch(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void drawBlockHighlight(DrawBlockHighlightEvent event) {
|
||||
MicroblockEventHandler$.MODULE$.drawBlockHighlight(event);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package codechicken.microblock.handler
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import net.minecraftforge.client.event.TextureStitchEvent
|
||||
import codechicken.microblock.MicroMaterialRegistry
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent
|
||||
import org.lwjgl.opengl.GL11
|
||||
import codechicken.lib.render.RenderUtils
|
||||
import codechicken.microblock.ItemMicroPartRenderer
|
||||
import cpw.mods.fml.common.Loader
|
||||
import cpw.mods.fml.common.LoaderState
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType
|
||||
|
||||
object MicroblockEventHandler {
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
def postTextureStitch(event: TextureStitchEvent.Post) {
|
||||
if (event.map.getTextureType == 0)
|
||||
MicroMaterialRegistry.loadIcons()
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
def drawBlockHighlight(event: DrawBlockHighlightEvent) {
|
||||
if (
|
||||
event.currentItem != null && event.currentItem.getItem == MicroblockProxy.itemMicro &&
|
||||
event.target != null && event.target.typeOfHit == MovingObjectType.BLOCK
|
||||
) {
|
||||
GL11.glPushMatrix()
|
||||
RenderUtils.translateToWorldCoords(event.player, event.partialTicks)
|
||||
if (
|
||||
ItemMicroPartRenderer.renderHighlight(
|
||||
event.player,
|
||||
event.currentItem,
|
||||
event.target
|
||||
)
|
||||
)
|
||||
event.setCanceled(true)
|
||||
GL11.glPopMatrix()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class MicroblockProxy_serverImpl {
|
||||
GameRegistry.registerItem(stoneRod, "stoneRod")
|
||||
|
||||
OreDictionary.registerOre("rodStone", stoneRod)
|
||||
MinecraftForge.EVENT_BUS.register(MicroblockEventHandler)
|
||||
MinecraftForge.EVENT_BUS.register(MicroblockEventHandler$.MODULE$)
|
||||
|
||||
useSawIcons = config
|
||||
.getTag("useSawIcons")
|
||||
|
||||
Reference in new issue
Block a user