mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-20 04:09:45 +00:00
refactor: port MultipartRenderer to Java
Kept in the TickScheduler$ shape: the companion holds the implementation because Forge registers that instance itself, and the plain class holds static forwarders. Both halves are load-bearing for different reasons -- guidenh resolves renderWorldBlock as a static first and falls back to MODULE$ -- and neither has a bytecode consumer, only reflective names. The emitted class list is unchanged. All five rendering callbacks keep their signatures, MODULE$ keeps its type and flags, and both classes keep class-level @SideOnly(CLIENT). Only three Scala forwarders for inherited TileEntitySpecialRenderer members and the companion clinit's ACC_PUBLIC differ. The render id is still claimed in the singleton's initialiser, matching the reference's first-access timing. The breaking-overlay branch moved to a private helper that checks the erased Tuple2 and the boxed index before unboxing, which is what the reference's pattern match compiled to. 125 plain-JVM tests and 22 Forge server tests pass, none changed by the port. This class needs a client, so it adds nothing to either suite and everything to the manual checklist.
This commit is contained in:
1 parent
da472f1fd3
commit
fa976c2002
7 files changed
+236
-109
No files matched your search
@@ -0,0 +1,121 @@
|
||||
package codechicken.multipart;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
|
||||
import codechicken.lib.raytracer.ExtendedMOP;
|
||||
import codechicken.lib.render.CCRenderState;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import scala.Tuple2;
|
||||
|
||||
/**
|
||||
* Internal class for rendering callbacks. Should be moved to the handler package.
|
||||
* <p>
|
||||
* This is the Scala companion singleton, and it is not a mere forwarder: Forge registers this instance itself, through
|
||||
* both {@code RenderingRegistry.registerBlockHandler} and {@code ClientRegistry.bindTileEntitySpecialRenderer}, so the
|
||||
* implementation has to live here. guidenh also reads {@code MODULE$} as its fallback path.
|
||||
* <p>
|
||||
* Claiming the render id in the constructor preserves the reference's timing: a Scala object runs its body on first
|
||||
* access, and this class is first touched from the client proxy's postInit.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public final class MultipartRenderer$ extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler {
|
||||
|
||||
public static final MultipartRenderer$ MODULE$ = new MultipartRenderer$();
|
||||
|
||||
private MultipartRenderer$() {
|
||||
TileMultipart.renderID_$eq(RenderingRegistry.getNextAvailableRenderId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f) {
|
||||
TileMultipartClient client = (TileMultipartClient) t;
|
||||
TileMultipart tile = (TileMultipart) t;
|
||||
if (tile.jPartList().isEmpty() || !client.hasDynamicParts()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CCRenderState state = CCRenderState.instance();
|
||||
state.resetInstance();
|
||||
state.pullLightmapInstance();
|
||||
state.useNormals = true;
|
||||
|
||||
client.renderDynamic(new Vector3(x, y, z), f, MinecraftForgeClient.getRenderPass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return TileMultipart.renderID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
|
||||
RenderBlocks renderer) {
|
||||
TileEntity t = world.getTileEntity(x, y, z);
|
||||
if (!(t instanceof TileMultipartClient)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileMultipartClient client = (TileMultipartClient) t;
|
||||
TileMultipart tile = (TileMultipart) t;
|
||||
if (tile.jPartList().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (renderer.hasOverrideBlockTexture()) {
|
||||
drawBreakingPart(tile, x, y, z, renderer);
|
||||
return false;
|
||||
}
|
||||
|
||||
CCRenderState state = CCRenderState.instance();
|
||||
state.resetInstance();
|
||||
state.lightMatrix.locate(world, x, y, z);
|
||||
boolean b = client.renderStatic(world, new Vector3(x, y, z), renderer);
|
||||
state.lightMatrix.access = null;
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* The hit data is a Scala Tuple2 whose first member is the struck part's index. It arrives erased, so both the
|
||||
* tuple and the index are checked before use, exactly as the reference's pattern match did.
|
||||
*/
|
||||
private static void drawBreakingPart(TileMultipart tile, int x, int y, int z, RenderBlocks renderer) {
|
||||
MovingObjectPosition hit = Minecraft.getMinecraft().objectMouseOver;
|
||||
if (hit == null || hit.blockX != x || hit.blockY != y || hit.blockZ != z) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object data = ExtendedMOP.getData(hit);
|
||||
if (!(data instanceof Tuple2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object index = ((Tuple2<?, ?>) data)._1();
|
||||
if (!(index instanceof Integer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int i = (Integer) index;
|
||||
if (i >= 0 && i < tile.jPartList().size()) {
|
||||
tile.jPartList().get(i).drawBreaking(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int meta, int modelId, RenderBlocks renderer) {}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int modelId) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package codechicken.multipart;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Static forwarders for {@link MultipartRenderer$}, which holds the implementation. guidenh resolves renderWorldBlock
|
||||
* here first and only falls back to the companion's MODULE$, so these must keep their exact signatures.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public final class MultipartRenderer {
|
||||
|
||||
private MultipartRenderer() {}
|
||||
|
||||
public static void renderTileEntityAt(TileEntity t, double x, double y, double z, float f) {
|
||||
MultipartRenderer$.MODULE$.renderTileEntityAt(t, x, y, z, f);
|
||||
}
|
||||
|
||||
public static int getRenderId() {
|
||||
return MultipartRenderer$.MODULE$.getRenderId();
|
||||
}
|
||||
|
||||
public static boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
|
||||
RenderBlocks renderer) {
|
||||
return MultipartRenderer$.MODULE$.renderWorldBlock(world, x, y, z, block, modelId, renderer);
|
||||
}
|
||||
|
||||
public static void renderInventoryBlock(Block block, int meta, int modelId, RenderBlocks renderer) {
|
||||
MultipartRenderer$.MODULE$.renderInventoryBlock(block, meta, modelId, renderer);
|
||||
}
|
||||
|
||||
public static boolean shouldRender3DInInventory(int modelId) {
|
||||
return MultipartRenderer$.MODULE$.shouldRender3DInInventory(modelId);
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
package codechicken.multipart
|
||||
|
||||
import codechicken.lib.render.CCRenderState
|
||||
import codechicken.lib.vec.Vector3
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.client.renderer.{Tessellator, RenderBlocks}
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraftforge.client.ForgeHooksClient
|
||||
import net.minecraftforge.client.MinecraftForgeClient
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import codechicken.lib.raytracer.ExtendedMOP
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
import com.gtnewhorizons.angelica.api.ThreadSafeISBRH
|
||||
|
||||
/** Internal class for rendering callbacks. Should be moved to the handler
|
||||
* package
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
object MultipartRenderer
|
||||
extends TileEntitySpecialRenderer
|
||||
with ISimpleBlockRenderingHandler {
|
||||
TileMultipart.renderID_$eq(RenderingRegistry.getNextAvailableRenderId)
|
||||
|
||||
override def renderTileEntityAt(
|
||||
t: TileEntity,
|
||||
x: Double,
|
||||
y: Double,
|
||||
z: Double,
|
||||
f: Float
|
||||
) {
|
||||
val tmpart = t.asInstanceOf[TileMultipartClient]
|
||||
if (tmpart.partList.isEmpty | !tmpart.hasDynamicParts)
|
||||
return
|
||||
|
||||
val state = CCRenderState.instance
|
||||
state.resetInstance()
|
||||
state.pullLightmapInstance()
|
||||
state.useNormals = true
|
||||
|
||||
val pos = new Vector3(x, y, z)
|
||||
tmpart.renderDynamic(pos, f, MinecraftForgeClient.getRenderPass)
|
||||
}
|
||||
|
||||
override def getRenderId = TileMultipart.renderID
|
||||
|
||||
override def renderWorldBlock(
|
||||
world: IBlockAccess,
|
||||
x: Int,
|
||||
y: Int,
|
||||
z: Int,
|
||||
block: Block,
|
||||
modelId: Int,
|
||||
renderer: RenderBlocks
|
||||
): Boolean = {
|
||||
val t = world.getTileEntity(x, y, z)
|
||||
if (!t.isInstanceOf[TileMultipartClient])
|
||||
return false
|
||||
|
||||
val tmpart = t.asInstanceOf[TileMultipartClient]
|
||||
if (tmpart.partList.isEmpty)
|
||||
return false
|
||||
|
||||
if (renderer.hasOverrideBlockTexture) {
|
||||
val hit = Minecraft.getMinecraft.objectMouseOver
|
||||
if (
|
||||
hit != null && hit.blockX == x && hit.blockY == y && hit.blockZ == z && ExtendedMOP
|
||||
.getData(hit)
|
||||
.isInstanceOf[(_, _)]
|
||||
) {
|
||||
val hitInfo: (Int, _) = ExtendedMOP.getData(hit)
|
||||
if (
|
||||
hitInfo._1.isInstanceOf[
|
||||
Int
|
||||
] && hitInfo._1 >= 0 && hitInfo._1 < tmpart.partList.size
|
||||
)
|
||||
tmpart.partList.apply(hitInfo._1).drawBreaking(renderer)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
val state = CCRenderState.instance
|
||||
state.resetInstance()
|
||||
state.lightMatrix.locate(world, x, y, z)
|
||||
val b = tmpart.renderStatic(world, new Vector3(x, y, z), renderer)
|
||||
state.lightMatrix.access = null
|
||||
b
|
||||
}
|
||||
|
||||
override def renderInventoryBlock(
|
||||
block: Block,
|
||||
meta: Int,
|
||||
modelId: Int,
|
||||
renderer: RenderBlocks
|
||||
) {}
|
||||
|
||||
def shouldRender3DInInventory(modelId: Int) = false
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class MultipartProxy_clientImpl extends MultipartProxy_serverImpl {
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def postInit() {
|
||||
super.postInit()
|
||||
RenderingRegistry.registerBlockHandler(MultipartRenderer)
|
||||
RenderingRegistry.registerBlockHandler(MultipartRenderer$.MODULE$)
|
||||
PacketCustom.assignHandler(MultipartCPH.channel, MultipartCPH)
|
||||
PacketCustom.assignHandler(MultipartCPH.registryChannel, MultipartCPH)
|
||||
|
||||
@@ -112,7 +112,7 @@ class MultipartProxy_clientImpl extends MultipartProxy_serverImpl {
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def onTileClassBuilt(t: Class[_ <: TileEntity]) {
|
||||
super.onTileClassBuilt(t)
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(t, MultipartRenderer)
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(t, MultipartRenderer$.MODULE$)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user