mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-21 20:52:21 +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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user