2013-12-27 23:59:59 +01:00
|
|
|
package appeng.client.render;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.item.Item;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.client.IItemRenderer;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import appeng.api.parts.IFacadePart;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.parts.IPartItem;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.client.ClientHelper;
|
|
|
|
import appeng.facade.IFacadeItem;
|
|
|
|
import appeng.util.Platform;
|
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 BusRenderer implements IItemRenderer
|
|
|
|
{
|
|
|
|
|
|
|
|
public static final BusRenderer instance = new BusRenderer();
|
|
|
|
|
|
|
|
public RenderBlocksWorkaround renderer = new RenderBlocksWorkaround();
|
|
|
|
public static final HashMap<Integer, IPart> renderPart = new HashMap();
|
|
|
|
|
|
|
|
public IPart getRenderer(ItemStack is, IPartItem c)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
int id = (Item.getIdFromItem( is.getItem() ) << Platform.DEF_OFFSET) | is.getItemDamage();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
IPart part = renderPart.get( id );
|
|
|
|
if ( part == null )
|
|
|
|
{
|
|
|
|
part = c.createPartFromItemStack( is );
|
2014-01-28 23:30:14 +01:00
|
|
|
if ( part != null )
|
|
|
|
renderPart.put( id, part );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean handleRenderType(ItemStack item, ItemRenderType type)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
|
|
|
|
{
|
2014-01-28 23:30:14 +01:00
|
|
|
if ( item == null )
|
|
|
|
return;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
GL11.glPushMatrix();
|
2014-02-09 02:34:52 +01:00
|
|
|
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
|
|
|
|
GL11.glEnable( GL11.GL_ALPHA_TEST );
|
|
|
|
GL11.glEnable( GL11.GL_DEPTH_TEST );
|
2014-02-14 06:31:26 +01:00
|
|
|
GL11.glEnable( GL11.GL_TEXTURE_2D );
|
|
|
|
GL11.glEnable( GL11.GL_LIGHTING );
|
2014-02-10 01:27:01 +01:00
|
|
|
GL11.glDisable( GL11.GL_BLEND );
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2014-02-12 03:44:23 +01:00
|
|
|
if ( type == ItemRenderType.EQUIPPED_FIRST_PERSON )
|
2014-02-12 06:42:55 +01:00
|
|
|
{
|
2014-02-12 03:44:23 +01:00
|
|
|
GL11.glTranslatef( -0.2f, -0.1f, -0.3f );
|
2014-02-12 06:42:55 +01:00
|
|
|
}
|
2014-02-12 03:44:23 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( type == ItemRenderType.ENTITY )
|
2014-02-20 05:20:38 +01:00
|
|
|
{
|
|
|
|
GL11.glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );
|
|
|
|
GL11.glScalef( 0.8f, 0.8f, 0.8f );
|
|
|
|
GL11.glTranslatef( -0.8f, -0.87f, -0.7f );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( type == ItemRenderType.INVENTORY )
|
|
|
|
GL11.glTranslatef( 0.0f, -0.1f, 0.0f );
|
|
|
|
|
2014-01-26 07:44:50 +01:00
|
|
|
GL11.glTranslated( 0.2, 0.3, 0.1 );
|
|
|
|
GL11.glScaled( 1.2, 1.2, 1. );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
GL11.glColor4f( 1, 1, 1, 1 );
|
|
|
|
Tessellator.instance.setColorOpaque_F( 1, 1, 1 );
|
2014-02-14 06:31:26 +01:00
|
|
|
Tessellator.instance.setBrightness( 14 << 20 | 14 << 4 );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
BusRenderHelper.instance.setBounds( 0, 0, 0, 1, 1, 1 );
|
|
|
|
BusRenderHelper.instance.setTexture( null );
|
|
|
|
BusRenderHelper.instance.setInvColor( 0xffffff );
|
|
|
|
renderer.blockAccess = ClientHelper.proxy.getWorld();
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
BusRenderHelper.instance.ax = ForgeDirection.EAST;
|
|
|
|
BusRenderHelper.instance.ay = ForgeDirection.UP;
|
|
|
|
BusRenderHelper.instance.az = ForgeDirection.SOUTH;
|
|
|
|
|
2014-02-14 03:26:32 +01:00
|
|
|
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
2014-02-14 06:31:26 +01:00
|
|
|
renderer.useInventoryTint = false;
|
2014-03-15 07:58:21 +01:00
|
|
|
renderer.overrideBlockTexture = null;
|
2014-02-14 03:26:32 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( item.getItem() instanceof IFacadeItem )
|
|
|
|
{
|
|
|
|
IFacadeItem fi = (IFacadeItem) item.getItem();
|
|
|
|
IFacadePart fp = fi.createPartFromItemStack( item, ForgeDirection.SOUTH );
|
|
|
|
|
2014-02-12 06:42:55 +01:00
|
|
|
if ( type == ItemRenderType.EQUIPPED_FIRST_PERSON )
|
|
|
|
{
|
|
|
|
GL11.glRotatef( 160.0f, 0.0f, 1.0f, 0.0f );
|
|
|
|
GL11.glTranslated( -0.4, 0.1, -1.6 );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( fp != null )
|
|
|
|
fp.renderInventory( BusRenderHelper.instance, renderer );
|
|
|
|
}
|
|
|
|
else
|
2014-01-28 23:30:14 +01:00
|
|
|
{
|
|
|
|
IPart ip = getRenderer( item, (IPartItem) item.getItem() );
|
2014-02-20 05:20:38 +01:00
|
|
|
|
|
|
|
if ( type == ItemRenderType.ENTITY )
|
|
|
|
{
|
|
|
|
int depth = ip.cableConnectionRenderTo();
|
|
|
|
GL11.glTranslatef( 0.0f, 0.0f, -0.04f * (8 - depth) - 0.06f );
|
|
|
|
}
|
|
|
|
|
2014-01-28 23:30:14 +01:00
|
|
|
if ( ip != null )
|
|
|
|
ip.renderInventory( BusRenderHelper.instance, renderer );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-14 03:26:32 +01:00
|
|
|
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
GL11.glPopAttrib();
|
2013-12-27 23:59:59 +01:00
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|