2013-12-27 23:59:59 +01:00
|
|
|
package appeng.client.render;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
2014-03-02 09:35:11 +01:00
|
|
|
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.block.AEBaseBlock;
|
2014-02-24 18:27:26 +01:00
|
|
|
import appeng.core.AELog;
|
2013-12-27 23:59:59 +01:00
|
|
|
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
|
|
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
2014-02-07 06:51:19 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public class WorldRender implements ISimpleBlockRenderingHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
private RenderBlocks renderer = new RenderBlocks();
|
|
|
|
final int renderID = RenderingRegistry.getNextAvailableRenderId();
|
|
|
|
public static final WorldRender instance = new WorldRender();
|
2014-03-22 19:27:44 +01:00
|
|
|
boolean hasErrored = false;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public HashMap<AEBaseBlock, BaseBlockRender> blockRenders = new HashMap();
|
|
|
|
|
|
|
|
void setRender(AEBaseBlock in, BaseBlockRender r)
|
|
|
|
{
|
|
|
|
blockRenders.put( in, r );
|
|
|
|
}
|
|
|
|
|
|
|
|
private WorldRender() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer)
|
|
|
|
{
|
|
|
|
// wtf is this for?
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
|
|
|
|
{
|
|
|
|
AEBaseBlock blk = (AEBaseBlock) block;
|
|
|
|
renderer.setRenderBoundsFromBlock( block );
|
|
|
|
return getRender( blk ).renderInWorld( blk, world, x, y, z, renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean shouldRender3DInInventory(int modelId)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRenderId()
|
|
|
|
{
|
|
|
|
return renderID;
|
|
|
|
}
|
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
public void renderItemBlock(ItemStack item, ItemRenderType type, Object[] data)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-24 18:27:26 +01:00
|
|
|
Block blk = Block.getBlockFromItem( item.getItem() );
|
|
|
|
if ( blk instanceof AEBaseBlock )
|
|
|
|
{
|
2014-03-02 09:35:11 +01:00
|
|
|
AEBaseBlock block = (AEBaseBlock) blk;
|
2014-02-24 18:27:26 +01:00
|
|
|
renderer.setRenderBoundsFromBlock( block );
|
2014-03-02 09:35:11 +01:00
|
|
|
|
2014-02-24 18:27:26 +01:00
|
|
|
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
2014-03-05 04:12:23 +01:00
|
|
|
getRender( block ).renderInventory( block, item, renderer, type, data );
|
2014-02-24 18:27:26 +01:00
|
|
|
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-22 19:27:44 +01:00
|
|
|
if ( !hasErrored )
|
|
|
|
{
|
|
|
|
hasErrored = true;
|
|
|
|
AELog.severe( "Invalid render - item/block mismatch" );
|
|
|
|
AELog.severe( " item: " + item.getUnlocalizedName() );
|
|
|
|
AELog.severe( " block: " + blk.getUnlocalizedName() );
|
|
|
|
}
|
2014-02-24 18:27:26 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private BaseBlockRender getRender(AEBaseBlock block)
|
|
|
|
{
|
|
|
|
return block.getRendererInstance().rendererInstance;
|
|
|
|
}
|
|
|
|
}
|