refactor: port microblock placement to Java

This commit is contained in:
Algent committed 2026-09-01 10:06:34 +02:00
1 parent e286de3401
commit c20b6bf9d9
11 files changed
+426 -193

No files matched your search

+8
View File
@@ -1061,3 +1061,11 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
- A clean build passes all 208 plain-JVM tests and the Java 8 Forge server passes all 98 tests. The jar retains exactly
the four public ItemMicroPart types; three unreferenced Scala iteration closures disappear.
`microblock/MicroblockPlacement.scala` is next.
- Characterized `MicroblockPlacement` against untouched Scala. Three plain-JVM cases freeze the exact six-type
hierarchy, constructors, fields, callable descriptors, companion and defaults. Four Forge cases freeze external
placement, internal/opposite-slot selection, in-place expansion, custom-placement precedence and consumption.
- Ported the six retained types directly to Java. The only Scala source caller now names
`MicroblockPlacement$.MODULE$` explicitly; no runtime class was added or removed and every callable public member
matches the reference.
- A clean build passes all 211 plain-JVM tests and the Java 8 Forge server passes all 102 tests.
`microblock/PlacementGrids.scala` is next.
+40
View File
@@ -2359,3 +2359,43 @@ downstream inventory contains no reference to those compiler artifacts.
names/descriptors.
- Creative listing, localized names, successful placement/consumption/sound and real client rendering remain on the
manual checklist.
## 2026-09-01 — MicroblockPlacement Java port
The placement decision engine, its executable result hierarchy, property base and companion singleton are now six
Java types. The item and highlight renderer continue to call `MicroblockPlacement$.MODULE$`, preserving the singleton
entry point exposed by the Scala implementation.
### Observable behavior
No known runtime divergence. Custom placement still wins before a rejected grid slot. Expansion still requires an
internal, non-converted tile hit without sneaking or the opposite modifier, then checks part type, material, combined
size, entity collision and replacement compatibility. Successful expansion mutates the original part's shape in
place, notifies its tile and sends the shape update. Internal placement retains the same shallow-hit and control-key
slot selection; external placement retains the same side offset. Addition and expansion each consume one item when
their caller requests consumption.
The Java implementation uses direct conditionals and standard null-safe equality. No focused performance claim is
made because placement is an interactive path rather than a sustained server loop.
### ABI and source compatibility
The retained runtime types are exactly `ExecutablePlacement`, `AdditionPlacement`, `ExpandingPlacement`,
`PlacementProperties`, `MicroblockPlacement`, and `MicroblockPlacement$`. Their hierarchy, constructors, stored-field
names/types/modifiers, `MODULE$`, and every callable public name and descriptor match the Scala reference. No anonymous
or closure classes existed in the reference unit, so the emitted class list is unchanged.
The remaining Scala highlight renderer now spells the companion call as `MicroblockPlacement$.MODULE$.apply(...)`;
Scala's object-application sugar does not recognize a Java-authored companion. Accepted classfile-only differences are
removed Scala signature/marker attributes, a private companion constructor and the companion class initializer without
Scala's `ACC_PUBLIC` flag.
### Validation
- `MicroblockPlacementCharacterizationTest`: 3 plain-JVM tests, unchanged from the Scala baseline.
- `MicroblockPlacementFunctionalTest`: 4 Forge tests, unchanged from the Scala baseline.
- Clean complete plain-JVM suite: 211 tests, 0 failures, 0 errors.
- Java 8 Forge dedicated-server suite: 102 tests, 0 failures, 0 errors.
- Clean reference/port jars contain the same six runtime classes, and raw `javap` comparison confirms identical
callable public names/descriptors.
- Full item-use sound plus client highlight/control-key feedback remain on the manual checklist.
+17 -10
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`. 115 commits including the API-cleanup plan and separate characterization and
port commits through `ItemMicroPart`.
Branch: `algent/java`. Base: `master`. 118 commits including the API-cleanup plan and separate characterization and
port commits through `MicroblockPlacement`.
## 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: **208 plain-JVM tests and 98 Java 8 Forge dedicated-server tests passing.** The ignored local server
Current baseline: **211 plain-JVM tests and 102 Java 8 Forge dedicated-server tests passing.** The ignored local server
EULA is accepted in this checkout.
### ABI diff against the reference
@@ -250,8 +250,8 @@ All eight load-bearing `$class` helpers from the inventory, both registries, and
`TRandomDisplayTickTile` Java-trait ports, plus `MultipartCompatiblity`/`MCPCCompatModule`, `MultipartMod`,
`MultipartEventHandler`, `MicroblockMod`, `MicroblockEventHandler`, and the complete `MicroblockPH`/
`MicroblockCPH`/`MicroblockSPH` and `MultipartPH`/`MultipartCPH`/`MultipartSPH` packet-handler units, plus
`MultipartSaveLoad`, `MissingMicroMaterial`, `DefaultContent`, `GrassMicroMaterial`/`TopMicroMaterial`, and
`ItemMicroPart` plus its renderer.
`MultipartSaveLoad`, `MissingMicroMaterial`, `DefaultContent`, `GrassMicroMaterial`/`TopMicroMaterial`,
`ItemMicroPart` plus its renderer, and `MicroblockPlacement` plus its executable-placement and property types.
The complete `MultipartProxy` and `MicroblockProxy` server/client hierarchies and static facades are also Java.
Plus the six marker interfaces: `TSlottedPart`, `IRandomDisplayTick`, `INeighborTileChange`, `TRandomUpdateTick`,
@@ -267,7 +267,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.
134 Java files, 24 Scala files, ~4,120 Scala lines left (non-blank; that is the metric this figure has always used).
140 Java files, 23 Scala files, ~3,966 Scala lines left (non-blank; that is the metric this figure has always used).
## What is left, and in what order
@@ -431,16 +431,23 @@ IDs and item registration. The Java renderer routes only its transformed `Microb
`MicroblockRender.renderItem`, keeping the call opcode Scala-safe. Creative listing, localized names, actual placement,
sound/consumption and client rendering remain on the manual checklist.
**Medium.** `MicroblockPlacement`, `PlacementGrids`, `BlockMicroMaterial`, `ConfigContent`, and the
`MicroblockPlacement` is now six Java types with the exact retained hierarchy, fields, constructors, companion and
callable descriptors. Three plain-JVM tests freeze that ABI and the property/consumption defaults. Four Forge tests
freeze external placement, internal/opposite-slot selection, expansion in place, custom-placement precedence and
survival consumption using generated face microblocks. The renderer's sole source call now names
`MicroblockPlacement$.MODULE$` explicitly. Full item-use sound and client highlight/control-key feedback remain on the
manual checklist.
**Medium.** `PlacementGrids`, `BlockMicroMaterial`, `ConfigContent`, and the
remaining material/render units.
**Phase 5 is complete.** There are no Scala files left in `multipart/scalatraits/`. The client pair required the first
narrow generator relaxation: Java-trait parent linearization, explicit field-accessor recognition, and exclusion of
transient runtime caches from generated copying.
Take `microblock/MicroblockPlacement.scala` next. It is the placement engine immediately downstream of the completed
item port. Freeze internal-versus-external selection, expansion, opposite-slot modifiers, material consumption and
world mutation before translating it; use the Forge server for the paths that need generated microblock classes.
Take `microblock/PlacementGrids.scala` next. It is the small geometry unit immediately upstream of the completed
placement engine. Freeze every face/corner/edge slot boundary and the retained grid/object surfaces before translating
it; OpenGL guide rendering remains a client-manual boundary.
**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.
@@ -0,0 +1,25 @@
package codechicken.microblock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import codechicken.lib.vec.BlockCoord;
import codechicken.multipart.TileMultipart;
public class AdditionPlacement extends ExecutablePlacement {
public AdditionPlacement(BlockCoord pos, Microblock part) {
super(pos, part);
}
@Override
public void place(World world, EntityPlayer player, ItemStack item) {
TileMultipart.addPart(world, pos(), part());
}
@Override
public void consume(World world, EntityPlayer player, ItemStack item) {
item.stackSize -= 1;
}
}
@@ -0,0 +1,30 @@
package codechicken.microblock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import codechicken.lib.vec.BlockCoord;
public abstract class ExecutablePlacement {
private final BlockCoord pos;
private final Microblock part;
public ExecutablePlacement(BlockCoord pos, Microblock part) {
this.pos = pos;
this.part = part;
}
public BlockCoord pos() {
return pos;
}
public Microblock part() {
return part;
}
public abstract void place(World world, EntityPlayer player, ItemStack item);
public abstract void consume(World world, EntityPlayer player, ItemStack item);
}
@@ -0,0 +1,29 @@
package codechicken.microblock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import codechicken.lib.vec.BlockCoord;
public class ExpandingPlacement extends ExecutablePlacement {
private final Microblock opart;
public ExpandingPlacement(BlockCoord pos, Microblock part, Microblock opart) {
super(pos, part);
this.opart = opart;
}
@Override
public void place(World world, EntityPlayer player, ItemStack item) {
opart.shape_$eq(part().shape());
opart.tile().notifyPartChange(opart);
opart.sendShapeUpdate();
}
@Override
public void consume(World world, EntityPlayer player, ItemStack item) {
item.stackSize -= 1;
}
}
@@ -0,0 +1,16 @@
package codechicken.microblock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MovingObjectPosition;
public final class MicroblockPlacement$ {
public static final MicroblockPlacement$ MODULE$ = new MicroblockPlacement$();
private MicroblockPlacement$() {}
public ExecutablePlacement apply(EntityPlayer player, MovingObjectPosition hit, int size, int material,
boolean checkMaterial, PlacementProperties properties) {
return new MicroblockPlacement(player, hit, size, material, checkMaterial, properties).apply();
}
}
@@ -0,0 +1,238 @@
package codechicken.microblock;
import java.util.Objects;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import codechicken.lib.raytracer.ExtendedMOP;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Rotation;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.ControlKeyModifer;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import scala.Tuple2;
public class MicroblockPlacement {
private final EntityPlayer player;
private final MovingObjectPosition hit;
private final int size;
private final int material;
private final boolean checkMaterial;
private final PlacementProperties pp;
private final World world;
private final MicroblockClass mcrClass;
private final BlockCoord pos;
private final Vector3 vhit;
private final Tuple2<TileMultipart, Object> gtile;
private final TileMultipart htile;
private final int slot;
private final int oslot;
private final double d;
private final boolean useOppMod;
private final boolean oppMod;
private final boolean internal;
private final boolean doExpand;
private final int side;
public MicroblockPlacement(EntityPlayer player, MovingObjectPosition hit, int size, int material,
boolean checkMaterial, PlacementProperties pp) {
this.player = player;
this.hit = hit;
this.size = size;
this.material = material;
this.checkMaterial = checkMaterial;
this.pp = pp;
world = player.worldObj;
mcrClass = pp.microClass();
pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ);
vhit = new Vector3(hit.hitVec).add(-pos.x, -pos.y, -pos.z);
gtile = TileMultipart.getOrConvertTile2(world, pos);
htile = gtile._1();
slot = pp.placementGrid().getHitSlot(vhit, hit.sideHit);
oslot = pp.opposite(slot, hit.sideHit);
d = getHitDepth(vhit, hit.sideHit);
useOppMod = pp.sneakOpposite(slot, hit.sideHit);
oppMod = ControlKeyModifer.isControlDown(player);
internal = d < 1 && htile != null;
doExpand = internal && !(Boolean) gtile._2()
&& !player.isSneaking()
&& !(oppMod && useOppMod)
&& pp.expand(slot, hit.sideHit);
side = hit.sideHit;
}
public EntityPlayer player() {
return player;
}
public MovingObjectPosition hit() {
return hit;
}
public int size() {
return size;
}
public int material() {
return material;
}
public boolean checkMaterial() {
return checkMaterial;
}
public PlacementProperties pp() {
return pp;
}
public World world() {
return world;
}
public MicroblockClass mcrClass() {
return mcrClass;
}
public BlockCoord pos() {
return pos;
}
public Vector3 vhit() {
return vhit;
}
public Tuple2<TileMultipart, Object> gtile() {
return gtile;
}
public TileMultipart htile() {
return htile;
}
public int slot() {
return slot;
}
public int oslot() {
return oslot;
}
public double d() {
return d;
}
public boolean useOppMod() {
return useOppMod;
}
public boolean oppMod() {
return oppMod;
}
public boolean internal() {
return internal;
}
public boolean doExpand() {
return doExpand;
}
public int side() {
return side;
}
public ExecutablePlacement apply() {
ExecutablePlacement customPlacement = pp.customPlacement(this);
if (customPlacement != null) {
return customPlacement;
}
if (slot < 0) {
return null;
}
if (doExpand) {
Tuple2<Object, Object> data = ExtendedMOP.getData(hit);
TMultiPart hitPart = htile.partList().apply((Integer) data._1());
if (Objects.equals(hitPart.getType(), mcrClass.getName())) {
CommonMicroblock commonPart = (CommonMicroblock) hitPart;
Microblock microPart = (Microblock) hitPart;
if (microPart.material() == material && microPart.getSize() + size < 8) {
return expand(commonPart);
}
}
}
if (internal) {
if (d < 0.5 || !useOppMod) {
ExecutablePlacement placement = internalPlacement(htile, slot);
if (placement != null) {
if (!useOppMod || !oppMod) {
return placement;
}
return internalPlacement(htile, oslot);
}
}
if (useOppMod && !oppMod) {
return internalPlacement(htile, oslot);
}
return externalPlacement(slot);
}
if (!useOppMod || !oppMod) {
return externalPlacement(slot);
}
return externalPlacement(oslot);
}
public ExecutablePlacement expand(CommonMicroblock part) {
Microblock microPart = (Microblock) part;
return expand(microPart, create(microPart.getSize() + size, part.getSlot(), microPart.material()));
}
public ExecutablePlacement expand(Microblock part, Microblock newPart) {
BlockCoord partPos = new BlockCoord(part.tile());
if (TileMultipart.checkNoEntityCollision(world, partPos, newPart)
&& part.tile().canReplacePart(part, newPart)) {
return new ExpandingPlacement(partPos, newPart, part);
}
return null;
}
public ExecutablePlacement internalPlacement(TileMultipart tile, int targetSlot) {
return internalPlacement(tile, create(size, targetSlot, material));
}
public ExecutablePlacement internalPlacement(TileMultipart tile, Microblock newPart) {
BlockCoord tilePos = new BlockCoord(tile);
if (TileMultipart.checkNoEntityCollision(world, tilePos, newPart) && tile.canAddPart(newPart)) {
return new AdditionPlacement(tilePos, newPart);
}
return null;
}
public ExecutablePlacement externalPlacement(int targetSlot) {
return externalPlacement(create(size, targetSlot, material));
}
public ExecutablePlacement externalPlacement(Microblock newPart) {
BlockCoord targetPos = pos.copy().offset(side);
if (TileMultipart.canPlacePart(world, targetPos, newPart)) {
return new AdditionPlacement(targetPos, newPart);
}
return null;
}
public double getHitDepth(Vector3 localHit, int hitSide) {
return localHit.copy().scalarProject(Rotation.axes[hitSide]) + (hitSide % 2 ^ 1);
}
public Microblock create(int partSize, int partSlot, int partMaterial) {
Microblock part = mcrClass.create(world.isRemote, partMaterial);
part.setShape(partSize, partSlot);
return part;
}
}
@@ -1,182 +0,0 @@
package codechicken.microblock
import net.minecraft.world.World
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.MovingObjectPosition
import codechicken.lib.vec.Vector3
import codechicken.lib.vec.BlockCoord
import codechicken.lib.vec.Rotation
import codechicken.multipart.ControlKeyModifer
import net.minecraft.item.ItemStack
import codechicken.multipart.TileMultipart
import codechicken.lib.raytracer.ExtendedMOP
abstract class ExecutablePlacement(val pos: BlockCoord, val part: Microblock) {
def place(world: World, player: EntityPlayer, item: ItemStack)
def consume(world: World, player: EntityPlayer, item: ItemStack)
}
class AdditionPlacement($pos: BlockCoord, $part: Microblock)
extends ExecutablePlacement($pos, $part) {
def place(world: World, player: EntityPlayer, item: ItemStack) {
TileMultipart.addPart(world, pos, part)
}
def consume(world: World, player: EntityPlayer, item: ItemStack) {
item.stackSize -= 1
}
}
class ExpandingPlacement($pos: BlockCoord, $part: Microblock, opart: Microblock)
extends ExecutablePlacement($pos, $part) {
def place(world: World, player: EntityPlayer, item: ItemStack) {
opart.shape = part.shape
opart.tile.notifyPartChange(opart)
opart.sendShapeUpdate()
}
def consume(world: World, player: EntityPlayer, item: ItemStack) {
item.stackSize -= 1
}
}
abstract class PlacementProperties {
def opposite(slot: Int, side: Int): Int
def sneakOpposite(slot: Int, side: Int) = true
def expand(slot: Int, side: Int) = true
def microClass: MicroblockClass
def placementGrid: PlacementGrid
def customPlacement(pmt: MicroblockPlacement): ExecutablePlacement = null
}
object MicroblockPlacement {
def apply(
player: EntityPlayer,
hit: MovingObjectPosition,
size: Int,
material: Int,
checkMaterial: Boolean,
pp: PlacementProperties
): ExecutablePlacement =
new MicroblockPlacement(player, hit, size, material, checkMaterial, pp)()
}
class MicroblockPlacement(
val player: EntityPlayer,
val hit: MovingObjectPosition,
val size: Int,
val material: Int,
val checkMaterial: Boolean,
val pp: PlacementProperties
) {
val world = player.worldObj
val mcrClass = pp.microClass
val pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ)
val vhit = new Vector3(hit.hitVec).add(-pos.x, -pos.y, -pos.z)
val gtile = TileMultipart.getOrConvertTile2(world, pos)
val htile = gtile._1
val slot = pp.placementGrid.getHitSlot(vhit, hit.sideHit)
val oslot = pp.opposite(slot, hit.sideHit)
val d = getHitDepth(vhit, hit.sideHit)
val useOppMod = pp.sneakOpposite(slot, hit.sideHit)
val oppMod = ControlKeyModifer.isControlDown(player)
val internal = d < 1 && htile != null
val doExpand =
internal && !gtile._2.asInstanceOf[
Boolean
] && !player.isSneaking && !(oppMod && useOppMod) && pp
.expand(slot, hit.sideHit)
val side = hit.sideHit
def apply(): ExecutablePlacement = {
val customPlacement = pp.customPlacement(this)
if (customPlacement != null)
return customPlacement
if (slot < 0)
return null
if (doExpand) {
val hpart = htile.partList.apply(ExtendedMOP.getData[(Int, _)](hit)._1)
if (hpart.getType == mcrClass.getName) {
val mpart = hpart.asInstanceOf[CommonMicroblock]
if (mpart.material == material && mpart.getSize + size < 8)
return expand(mpart)
}
}
if (internal) {
if (d < 0.5 || !useOppMod) {
val ret = internalPlacement(htile, slot)
if (ret != null) {
if (!useOppMod || !oppMod) return ret
else return internalPlacement(htile, oslot)
}
}
if (useOppMod && !oppMod)
return internalPlacement(htile, oslot)
else
return externalPlacement(slot)
}
if (!useOppMod || !oppMod)
return externalPlacement(slot)
else
return externalPlacement(oslot)
}
def expand(mpart: CommonMicroblock): ExecutablePlacement =
expand(mpart, create(mpart.getSize + size, mpart.getSlot, mpart.material))
def expand(mpart: Microblock, npart: Microblock): ExecutablePlacement = {
val pos = new BlockCoord(mpart.tile)
if (
TileMultipart.checkNoEntityCollision(world, pos, npart) && mpart.tile
.canReplacePart(mpart, npart)
)
return new ExpandingPlacement(pos, npart, mpart)
return null
}
def internalPlacement(htile: TileMultipart, slot: Int): ExecutablePlacement =
internalPlacement(htile, create(size, slot, material))
def internalPlacement(
htile: TileMultipart,
npart: Microblock
): ExecutablePlacement = {
val pos = new BlockCoord(htile)
if (
TileMultipart.checkNoEntityCollision(world, pos, npart) && htile
.canAddPart(npart)
)
return new AdditionPlacement(pos, npart)
return null
}
def externalPlacement(slot: Int): ExecutablePlacement = externalPlacement(
create(size, slot, material)
)
def externalPlacement(npart: Microblock): ExecutablePlacement = {
val pos = this.pos.copy().offset(side)
if (TileMultipart.canPlacePart(world, pos, npart))
return new AdditionPlacement(pos, npart)
return null
}
def getHitDepth(vhit: Vector3, side: Int): Double =
vhit.copy.scalarProject(Rotation.axes(side)) + (side % 2 ^ 1)
def create(size: Int, slot: Int, material: Int) = {
val part = mcrClass.create(world.isRemote, material)
part.setShape(size, slot)
part
}
}
@@ -29,7 +29,7 @@ object MicroblockRender {
mcrClass.placementProperties.placementGrid
.render(new Vector3(hit.hitVec), hit.sideHit)
val placement = MicroblockPlacement(
val placement = MicroblockPlacement$.MODULE$.apply(
player,
hit,
size,
@@ -0,0 +1,22 @@
package codechicken.microblock;
public abstract class PlacementProperties {
public abstract int opposite(int slot, int side);
public boolean sneakOpposite(int slot, int side) {
return true;
}
public boolean expand(int slot, int side) {
return true;
}
public abstract MicroblockClass microClass();
public abstract PlacementGrid placementGrid();
public ExecutablePlacement customPlacement(MicroblockPlacement placement) {
return null;
}
}