2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
2015-05-24 13:36:43 +02:00
|
|
|
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
2014-11-14 12:02:52 +01:00
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.client.render;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.HashMap;
|
2015-03-26 11:13:24 +01:00
|
|
|
import java.util.Map;
|
2015-05-24 13:36:43 +02:00
|
|
|
import javax.annotation.Nullable;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 21:59:05 +01:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.client.IItemRenderer;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
2014-12-29 21:59:05 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
import appeng.api.parts.IAlphaPassItem;
|
|
|
|
import appeng.api.parts.IFacadePart;
|
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.parts.IPartItem;
|
|
|
|
import appeng.client.ClientHelper;
|
|
|
|
import appeng.core.AEConfig;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.facade.IFacadeItem;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
@SideOnly( Side.CLIENT )
|
2014-09-24 02:26:27 +02:00
|
|
|
public class BusRenderer implements IItemRenderer
|
|
|
|
{
|
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
public static final BusRenderer INSTANCE = new BusRenderer();
|
2015-03-26 11:13:24 +01:00
|
|
|
private static final Map<Integer, IPart> RENDER_PART = new HashMap<Integer, IPart>();
|
2015-04-03 08:54:31 +02:00
|
|
|
public final RenderBlocksWorkaround renderer = new RenderBlocksWorkaround();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean handleRenderType( ItemStack item, ItemRenderType type )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean shouldUseRenderHelper( ItemRenderType type, ItemStack item, ItemRendererHelper helper )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void renderItem( ItemRenderType type, ItemStack item, Object... data )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( item == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
|
|
|
|
GL11.glEnable( GL11.GL_DEPTH_TEST );
|
|
|
|
GL11.glEnable( GL11.GL_TEXTURE_2D );
|
|
|
|
GL11.glEnable( GL11.GL_LIGHTING );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) && item.getItem() instanceof IAlphaPassItem && ( (IAlphaPassItem) item.getItem() ).useAlphaPass( item ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
|
|
|
GL11.glDisable( GL11.GL_ALPHA_TEST );
|
|
|
|
GL11.glEnable( GL11.GL_BLEND );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL11.glAlphaFunc( GL11.GL_GREATER, 0.4f );
|
|
|
|
GL11.glEnable( GL11.GL_ALPHA_TEST );
|
|
|
|
GL11.glDisable( GL11.GL_BLEND );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type == ItemRenderType.EQUIPPED_FIRST_PERSON )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
GL11.glTranslatef( -0.2f, -0.1f, -0.3f );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type == ItemRenderType.ENTITY )
|
2014-09-24 02:26:27 +02: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 );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type == ItemRenderType.INVENTORY )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
GL11.glTranslatef( 0.0f, -0.1f, 0.0f );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
GL11.glTranslated( 0.2, 0.3, 0.1 );
|
|
|
|
GL11.glScaled( 1.2, 1.2, 1. );
|
|
|
|
|
|
|
|
GL11.glColor4f( 1, 1, 1, 1 );
|
|
|
|
Tessellator.instance.setColorOpaque_F( 1, 1, 1 );
|
|
|
|
Tessellator.instance.setBrightness( 14 << 20 | 14 << 4 );
|
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
BusRenderHelper.INSTANCE.setBounds( 0, 0, 0, 1, 1, 1 );
|
|
|
|
BusRenderHelper.INSTANCE.setTexture( null );
|
|
|
|
BusRenderHelper.INSTANCE.setInvColor( 0xffffff );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderer.blockAccess = ClientHelper.proxy.getWorld();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
BusRenderHelper.INSTANCE.setOrientation( ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderer.uvRotateBottom = this.renderer.uvRotateEast = this.renderer.uvRotateNorth = this.renderer.uvRotateSouth = this.renderer.uvRotateTop = this.renderer.uvRotateWest = 0;
|
|
|
|
this.renderer.useInventoryTint = false;
|
|
|
|
this.renderer.overrideBlockTexture = null;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( item.getItem() instanceof IFacadeItem )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
IFacadeItem fi = (IFacadeItem) item.getItem();
|
|
|
|
IFacadePart fp = fi.createPartFromItemStack( item, ForgeDirection.SOUTH );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type == ItemRenderType.EQUIPPED_FIRST_PERSON )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
GL11.glRotatef( 160.0f, 0.0f, 1.0f, 0.0f );
|
|
|
|
GL11.glTranslated( -0.4, 0.1, -1.6 );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( fp != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
fp.renderInventory( BusRenderHelper.INSTANCE, this.renderer );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IPart ip = this.getRenderer( item, (IPartItem) item.getItem() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ip != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type == ItemRenderType.ENTITY )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
int depth = ip.cableConnectionRenderTo();
|
2015-04-03 08:54:31 +02:00
|
|
|
GL11.glTranslatef( 0.0f, 0.0f, -0.04f * ( 8 - depth ) - 0.06f );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
ip.renderInventory( BusRenderHelper.INSTANCE, this.renderer );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderer.uvRotateBottom = this.renderer.uvRotateEast = this.renderer.uvRotateNorth = this.renderer.uvRotateSouth = this.renderer.uvRotateTop = this.renderer.uvRotateWest = 0;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
GL11.glPopAttrib();
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-05-24 13:36:43 +02:00
|
|
|
@Nullable
|
2015-04-03 08:54:31 +02:00
|
|
|
public IPart getRenderer( ItemStack is, IPartItem c )
|
|
|
|
{
|
|
|
|
int id = ( Item.getIdFromItem( is.getItem() ) << Platform.DEF_OFFSET ) | is.getItemDamage();
|
|
|
|
|
|
|
|
IPart part = RENDER_PART.get( id );
|
|
|
|
if( part == null )
|
|
|
|
{
|
|
|
|
part = c.createPartFromItemStack( is );
|
|
|
|
if( part != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
RENDER_PART.put( id, part );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|