refactor: port post microblock client to Java

Retain Scala state and lifecycle bridges with ordered virtual dispatch.
This commit is contained in:
Algent committed 2026-09-03 22:57:12 +02:00
1 parent 47885d15a8
commit 556fd519bb
7 files changed
+135 -68

No files matched your search

@@ -25,16 +25,8 @@ trait PostMicroblockClient extends PostMicroblock with MicroblockClient {
var renderBounds1: Cuboid6 = _
var renderBounds2: Cuboid6 = _
override def render(pos: Vector3, pass: Int) {
val mat = getIMaterial
if (pass == -1)
MicroblockRender.renderCuboid(pos, mat, pass, getBounds, 0)
else {
MicroblockRender.renderCuboid(pos, mat, pass, renderBounds1, 0)
if (renderBounds2 != null)
MicroblockRender.renderCuboid(pos, mat, pass, renderBounds2, 0)
}
}
override def render(pos: Vector3, pass: Int) =
PostMicroblockClientLogic.render(this, pos, pass)
override def onPartChanged(part: TMultiPart) {
recalcBounds()
@@ -50,46 +42,15 @@ trait PostMicroblockClient extends PostMicroblock with MicroblockClient {
recalcBounds()
}
def recalcBounds() {
renderBounds1 = getBounds.copy
renderBounds2 = null
def recalcBounds() = PostMicroblockClientLogic.recalcBounds(this)
shrinkFace(getShape << 1)
shrinkFace(getShape << 1 | 1)
def shrinkFace(fside: Int) = PostMicroblockClientLogic.shrinkFace(this, fside)
tile.partList.foreach(p =>
if (p.isInstanceOf[PostMicroblock] && p != this)
shrinkPost(p.asInstanceOf[PostMicroblock])
)
}
def shrinkPost(post: PostMicroblock) =
PostMicroblockClientLogic.shrinkPost(this, post)
def shrinkFace(fside: Int) {
val part = tile.partMap(fside)
if (part != null && part.getType.equals("mcr_face"))
MicroOcclusion.shrink(
renderBounds1,
part.asInstanceOf[CommonMicroblock].getBounds,
fside
)
}
def shrinkPost(post: PostMicroblock) {
if (post == this)
return
if (thisShrinks(post)) {
if (renderBounds2 == null)
renderBounds2 = getBounds.copy
MicroOcclusion.shrink(renderBounds1, post.getBounds, getShape << 1 | 1)
MicroOcclusion.shrink(renderBounds2, post.getBounds, getShape << 1)
}
}
def thisShrinks(other: PostMicroblock): Boolean = {
if (getSize != other.getSize) return getSize < other.getSize
if (isTransparent != other.isTransparent) return isTransparent
return getShape > other.getShape
}
def thisShrinks(other: PostMicroblock): Boolean =
PostMicroblockClientLogic.thisShrinks(this, other)
}
trait PostMicroblock
@@ -0,0 +1,83 @@
package codechicken.microblock;
import codechicken.lib.vec.Vector3;
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial;
import codechicken.multipart.TMultiPart;
import scala.runtime.AbstractFunction1;
import scala.runtime.BoxedUnit;
/** Client behavior behind the retained Scala state, inheritance and lifecycle bridges. */
final class PostMicroblockClientLogic {
private PostMicroblockClientLogic() {}
static void render(PostMicroblockClient part, Vector3 pos, int pass) {
IMicroMaterial material = ((Microblock) part).getIMaterial();
if (pass == -1) {
MicroblockRender.renderCuboid(pos, material, pass, part.getBounds(), 0);
} else {
MicroblockRender.renderCuboid(pos, material, pass, part.renderBounds1(), 0);
if (part.renderBounds2() != null) {
MicroblockRender.renderCuboid(pos, material, pass, part.renderBounds2(), 0);
}
}
}
static void recalcBounds(PostMicroblockClient part) {
part.renderBounds1_$eq(part.getBounds().copy());
part.renderBounds2_$eq(null);
part.shrinkFace(((Microblock) part).getShape() << 1);
part.shrinkFace(((Microblock) part).getShape() << 1 | 1);
((TMultiPart) part).tile().partList().foreach(new ShrinkPosts(part));
}
static void shrinkFace(PostMicroblockClient part, int side) {
TMultiPart other = ((TMultiPart) part).tile().partMap(side);
if (other != null && other.getType().equals("mcr_face")) {
MicroOcclusion.shrink(part.renderBounds1(), ((CommonMicroblock) other).getBounds(), side);
}
}
static void shrinkPost(PostMicroblockClient part, PostMicroblock other) {
// Scala equality calls the left operand's equals even when the references are identical.
if (other == null ? part == null : other.equals(part)) {
return;
}
if (part.thisShrinks(other)) {
if (part.renderBounds2() == null) {
part.renderBounds2_$eq(part.getBounds().copy());
}
MicroOcclusion.shrink(part.renderBounds1(), other.getBounds(), ((Microblock) part).getShape() << 1 | 1);
MicroOcclusion.shrink(part.renderBounds2(), other.getBounds(), ((Microblock) part).getShape() << 1);
}
}
static boolean thisShrinks(PostMicroblockClient part, PostMicroblock other) {
if (((Microblock) part).getSize() != ((Microblock) other).getSize()) {
return ((Microblock) part).getSize() < ((Microblock) other).getSize();
}
if (((Microblock) part).isTransparent() != ((Microblock) other).isTransparent()) {
return ((Microblock) part).isTransparent();
}
return ((Microblock) part).getShape() > ((Microblock) other).getShape();
}
private static final class ShrinkPosts extends AbstractFunction1<TMultiPart, BoxedUnit>
implements scala.Serializable {
private static final long serialVersionUID = 0L;
private final PostMicroblockClient part;
ShrinkPosts(PostMicroblockClient part) {
this.part = part;
}
@Override
public BoxedUnit apply(TMultiPart other) {
if (other instanceof PostMicroblock && !other.equals(part)) {
part.shrinkPost((PostMicroblock) other);
}
return BoxedUnit.UNIT;
}
}
}