Applied-Energistics-2-tiler.../src/main/java/appeng/client/render/blocks/RenderBlockCharger.java

174 lines
6.1 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* 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.blocks;
2014-09-24 02:26:27 +02:00
import java.util.EnumSet;
2015-12-24 02:07:03 +01:00
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
2014-09-24 02:26:27 +02:00
import net.minecraft.block.Block;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.VertexBuffer;
2014-09-24 02:26:27 +02:00
import net.minecraft.item.ItemStack;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
2014-09-24 02:26:27 +02:00
import net.minecraft.world.IBlockAccess;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEPartLocation;
2014-09-24 02:26:27 +02:00
import appeng.api.util.IOrientable;
import appeng.api.util.ModelGenerator;
2014-09-24 02:26:27 +02:00
import appeng.block.misc.BlockCharger;
2016-01-01 01:47:22 +01:00
import appeng.client.ItemRenderType;
2014-09-24 02:26:27 +02:00
import appeng.client.render.BaseBlockRender;
import appeng.client.texture.ExtraBlockTextures;
import appeng.core.AELog;
import appeng.tile.misc.TileCharger;
2014-09-24 02:26:27 +02:00
import appeng.util.Platform;
public class RenderBlockCharger extends BaseBlockRender<BlockCharger, TileCharger>
2014-09-24 02:26:27 +02:00
{
public RenderBlockCharger()
{
2014-09-24 02:26:27 +02:00
super( true, 30 );
}
@Override
2015-09-30 14:24:40 +02:00
public void renderInventory( final BlockCharger blk, final ItemStack is, final ModelGenerator renderer, final ItemRenderType type, final Object[] obj )
2014-09-24 02:26:27 +02:00
{
renderer.setRenderAllFaces( true );
2014-12-29 15:13:47 +01:00
this.setInvRenderBounds( renderer, 6, 1, 0, 10, 15, 2 );
2015-06-16 02:44:59 +02:00
this.renderInvBlock( EnumSet.allOf( AEPartLocation.class ), blk, is, 0xffffff, renderer );
2014-09-24 02:26:27 +02:00
blk.getRendererInstance().setTemporaryRenderIcons( ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null, null );
2014-12-29 15:13:47 +01:00
this.setInvRenderBounds( renderer, 2, 0, 2, 14, 3, 14 );
2015-12-24 02:03:16 +01:00
this.renderInvBlock( EnumSet.allOf( AEPartLocation.class ), blk, is, 0xffffff, renderer );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.setInvRenderBounds( renderer, 3, 3, 3, 13, 4, 13 );
2015-12-24 02:03:16 +01:00
this.renderInvBlock( EnumSet.allOf( AEPartLocation.class ), blk, is, 0xffffff, renderer );
2014-09-24 02:26:27 +02:00
blk.getRendererInstance().setTemporaryRenderIcon( null );
blk.getRendererInstance().setTemporaryRenderIcons( null, ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null );
2014-12-29 15:13:47 +01:00
this.setInvRenderBounds( renderer, 2, 13, 2, 14, 16, 14 );
2015-12-24 02:03:16 +01:00
this.renderInvBlock( EnumSet.allOf( AEPartLocation.class ), blk, is, 0xffffff, renderer );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.setInvRenderBounds( renderer, 3, 12, 3, 13, 13, 13 );
2015-12-24 02:03:16 +01:00
this.renderInvBlock( EnumSet.allOf( AEPartLocation.class ), blk, is, 0xffffff, renderer );
2014-09-24 02:26:27 +02:00
renderer.setRenderAllFaces( false );
2014-09-24 02:26:27 +02:00
blk.getRendererInstance().setTemporaryRenderIcon( null );
}
@Override
2015-09-30 14:24:40 +02:00
public boolean renderInWorld( final BlockCharger block, final IBlockAccess world, final BlockPos pos, final ModelGenerator renderer )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
this.preRenderInWorld( block, world, pos, renderer );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
final IOrientable te = this.getOrientable( block, world, pos );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
final EnumFacing fdy = te.getUp();
final EnumFacing fdz = te.getForward();
final EnumFacing fdx = Platform.crossProduct( fdz, fdy ).getOpposite();
2014-09-24 02:26:27 +02:00
renderer.setRenderAllFaces( true );
2014-12-29 15:13:47 +01:00
this.renderBlockBounds( renderer, 6, 1, 0, 10, 15, 2, fdx, fdy, fdz );
2015-09-25 22:30:38 +02:00
boolean out = renderer.renderStandardBlock( block, pos );
2014-09-24 02:26:27 +02:00
2015-09-25 22:30:38 +02:00
block.getRendererInstance().setTemporaryRenderIcons( ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null, null );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.renderBlockBounds( renderer, 2, 0, 2, 14, 3, 14, fdx, fdy, fdz );
2015-09-25 22:30:38 +02:00
out = renderer.renderStandardBlock( block, pos );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.renderBlockBounds( renderer, 3, 3, 3, 13, 4, 13, fdx, fdy, fdz );
2015-09-25 22:30:38 +02:00
out = renderer.renderStandardBlock( block, pos );
2014-09-24 02:26:27 +02:00
2015-09-25 22:30:38 +02:00
block.getRendererInstance().setTemporaryRenderIcon( null );
2014-09-24 02:26:27 +02:00
2015-09-25 22:30:38 +02:00
block.getRendererInstance().setTemporaryRenderIcons( null, ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.renderBlockBounds( renderer, 2, 13, 2, 14, 16, 14, fdx, fdy, fdz );
2015-09-25 22:30:38 +02:00
out = renderer.renderStandardBlock( block, pos );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.renderBlockBounds( renderer, 3, 12, 3, 13, 13, 13, fdx, fdy, fdz );
2015-09-25 22:30:38 +02:00
out = renderer.renderStandardBlock( block, pos );
2014-09-24 02:26:27 +02:00
renderer.setRenderAllFaces( false );
2015-09-25 22:30:38 +02:00
block.getRendererInstance().setTemporaryRenderIcon( null );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.postRenderInWorld( renderer );
2014-09-24 02:26:27 +02:00
return out;
}
@Override
public void renderTile( final BlockCharger block, final TileCharger tile, final VertexBuffer tess, final double x, final double y, final double z, final float f, final ModelGenerator renderer )
2014-09-24 02:26:27 +02:00
{
2015-09-25 22:30:38 +02:00
final ItemStack sis = tile.getStackInSlot( 0 );
2014-09-24 02:26:27 +02:00
if( sis != null )
2014-09-24 02:26:27 +02:00
{
GL11.glPushMatrix();
2014-12-29 15:13:47 +01:00
this.applyTESRRotation( x, y, z, tile.getForward(), tile.getUp() );
2014-09-24 02:26:27 +02:00
try
{
2015-06-16 02:44:59 +02:00
GL11.glTranslatef( 0.5f, 0.35f, 0.5f );
2014-09-24 02:26:27 +02:00
GL11.glScalef( 1.0f / 1.1f, 1.0f / 1.1f, 1.0f / 1.1f );
GL11.glScalef( 1.0f, 1.0f, 1.0f );
final Block blk = Block.getBlockFromItem( sis.getItem() );
2015-06-16 02:44:59 +02:00
/*
2015-12-24 02:03:16 +01:00
* if( sis.getItemSpriteNumber() == 0 && block != null && IRenderHelper.renderItemIn3d(
* blk.getRenderType() ) )
* {
* GL11.glRotatef( 25.0f, 1.0f, 0.0f, 0.0f );
* GL11.glRotatef( 15.0f, 0.0f, 1.0f, 0.0f );
* GL11.glRotatef( 30.0f, 0.0f, 1.0f, 0.0f );
* }
*/
// << 20 | light << 4;
2015-06-16 02:44:59 +02:00
final int br = tile.getWorld().getCombinedLight( tile.getPos(), 0 );
final int var11 = br % 65536;
final int var12 = br / 65536;
2014-09-24 02:26:27 +02:00
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, var11, var12 );
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
GL11.glDisable( GL11.GL_LIGHTING );
GL11.glDisable( GL12.GL_RESCALE_NORMAL );
2014-12-29 15:13:47 +01:00
this.doRenderItem( sis, tile );
2014-09-24 02:26:27 +02:00
}
2015-09-30 14:24:40 +02:00
catch( final Exception err )
2014-09-24 02:26:27 +02:00
{
AELog.debug( err );
2014-09-24 02:26:27 +02:00
}
GL11.glPopMatrix();
}
}
}