mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-21 20:52:21 +00:00
refactor: port common microblock logic to Java
Retain Scala trait declarations and helper bridges for inherited mixin registration and existing consumers.
This commit is contained in:
1 parent
d6eb56b56f
commit
d89aaeacf3
6 files changed
+148
-60
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package codechicken.microblock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.microblock.MicroMaterialRegistry.IMicroMaterial;
|
||||
import scala.Predef$;
|
||||
import scala.collection.JavaConversions;
|
||||
import scala.collection.Seq;
|
||||
import scala.collection.Seq$;
|
||||
|
||||
/** Implementation behind the Scala trait declarations needed by inherited and external mixins. */
|
||||
final class MicroblockTraitLogic {
|
||||
|
||||
private MicroblockTraitLogic() {}
|
||||
|
||||
static IIcon getBrokenIcon(MicroblockClient part, int side) {
|
||||
IMicroMaterial material = ((Microblock) part).getIMaterial();
|
||||
return material == null ? Blocks.stone.getIcon(0, 0) : material.getBreakingIcon(side);
|
||||
}
|
||||
|
||||
static boolean renderStatic(MicroblockClient part, Vector3 pos, int pass) {
|
||||
if (((Microblock) part).getIMaterial().canRenderInPass(pass)) {
|
||||
part.render(pos, pass);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static Cuboid6 getRenderBounds(MicroblockClient part) {
|
||||
return part.getBounds();
|
||||
}
|
||||
|
||||
static void render(CommonMicroblockClient part, Vector3 pos, int pass) {
|
||||
if (pass < 0) {
|
||||
MicroblockRender.renderCuboid(pos, ((Microblock) part).getIMaterial(), pass, part.getBounds(), 0);
|
||||
} else {
|
||||
MicroblockRender.renderCuboid(
|
||||
pos,
|
||||
((Microblock) part).getIMaterial(),
|
||||
pass,
|
||||
part.renderBounds(),
|
||||
part.renderMask());
|
||||
}
|
||||
}
|
||||
|
||||
static int getSlot(CommonMicroblock part) {
|
||||
return ((Microblock) part).getShape();
|
||||
}
|
||||
|
||||
static int getSlotMask(CommonMicroblock part) {
|
||||
return 1 << part.getSlot();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static List<Cuboid6> getPartialOcclusionBoxes(CommonMicroblock part) {
|
||||
return JavaConversions.seqAsJavaList(
|
||||
(Seq<Cuboid6>) Seq$.MODULE$.apply(Predef$.MODULE$.wrapRefArray(new Cuboid6[] { part.getBounds() })));
|
||||
}
|
||||
|
||||
static int itemClassID(CommonMicroblock part) {
|
||||
return part.microClass().getClassId();
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,14 @@ import codechicken.multipart.{
|
||||
TSlottedPart
|
||||
}
|
||||
import net.minecraft.client.particle.EffectRenderer
|
||||
import net.minecraft.init.Blocks
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
// Keep Scala inheritance metadata and helper bridges while derived and external mixins use Scala registration.
|
||||
trait MicroblockClient
|
||||
extends Microblock
|
||||
with TIconHitEffects
|
||||
with IMicroMaterialRender {
|
||||
def getBrokenIcon(side: Int) = getIMaterial match {
|
||||
case null => Blocks.stone.getIcon(0, 0)
|
||||
case mat => mat.getBreakingIcon(side)
|
||||
}
|
||||
def getBrokenIcon(side: Int) = MicroblockTraitLogic.getBrokenIcon(this, side)
|
||||
|
||||
// TIconHitEffects is a Java interface, so these must be declared explicitly or TMultiPart's empty versions win.
|
||||
override def addHitEffects(
|
||||
@@ -30,35 +26,20 @@ trait MicroblockClient
|
||||
override def addDestroyEffects(effectRenderer: EffectRenderer) =
|
||||
IconHitEffects.addDestroyEffects(this, effectRenderer)
|
||||
|
||||
override def renderStatic(pos: Vector3, pass: Int) = {
|
||||
if (getIMaterial.canRenderInPass(pass)) {
|
||||
render(pos, pass)
|
||||
true
|
||||
} else
|
||||
false
|
||||
}
|
||||
override def renderStatic(pos: Vector3, pass: Int) =
|
||||
MicroblockTraitLogic.renderStatic(this, pos, pass)
|
||||
|
||||
def render(pos: Vector3, pass: Int)
|
||||
|
||||
override def getRenderBounds = getBounds
|
||||
override def getRenderBounds = MicroblockTraitLogic.getRenderBounds(this)
|
||||
}
|
||||
|
||||
trait CommonMicroblockClient
|
||||
extends CommonMicroblock
|
||||
with MicroblockClient
|
||||
with TMicroOcclusionClient {
|
||||
def render(pos: Vector3, pass: Int) {
|
||||
if (pass < 0)
|
||||
MicroblockRender.renderCuboid(pos, getIMaterial, pass, getBounds, 0)
|
||||
else
|
||||
MicroblockRender.renderCuboid(
|
||||
pos,
|
||||
getIMaterial,
|
||||
pass,
|
||||
renderBounds,
|
||||
renderMask
|
||||
)
|
||||
}
|
||||
def render(pos: Vector3, pass: Int) =
|
||||
MicroblockTraitLogic.render(this, pos, pass)
|
||||
}
|
||||
|
||||
trait CommonMicroblock
|
||||
@@ -68,9 +49,10 @@ trait CommonMicroblock
|
||||
with TSlottedPart {
|
||||
def microClass: CommonMicroClass
|
||||
|
||||
def getSlot = getShape
|
||||
def getSlotMask = 1 << getSlot
|
||||
def getPartialOcclusionBoxes = Seq(getBounds)
|
||||
def getSlot = MicroblockTraitLogic.getSlot(this)
|
||||
def getSlotMask = MicroblockTraitLogic.getSlotMask(this)
|
||||
def getPartialOcclusionBoxes =
|
||||
MicroblockTraitLogic.getPartialOcclusionBoxes(this)
|
||||
|
||||
override def itemClassID = microClass.getClassId
|
||||
override def itemClassID = MicroblockTraitLogic.itemClassID(this)
|
||||
}
|
||||
Reference in new issue
Block a user