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

189 lines
5.8 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;
import net.minecraft.item.ItemStack;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
2014-09-24 02:26:27 +02:00
import net.minecraft.world.IBlockAccess;
import appeng.client.ItemRenderType;
2015-12-24 02:07:03 +01:00
2014-09-24 02:26:27 +02:00
import appeng.api.AEApi;
import appeng.api.storage.ICellHandler;
import appeng.api.util.AEColor;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEPartLocation;
import appeng.block.storage.BlockChest;
2014-09-24 02:26:27 +02:00
import appeng.client.render.BaseBlockRender;
2015-06-22 18:16:25 +02:00
import appeng.client.render.ModelGenerator;
2014-09-24 02:26:27 +02:00
import appeng.client.texture.ExtraBlockTextures;
2014-12-29 21:59:05 +01:00
import appeng.client.texture.FlippableIcon;
2015-06-16 02:44:59 +02:00
import appeng.client.texture.IAESprite;
2014-09-24 02:26:27 +02:00
import appeng.client.texture.OffsetIcon;
import appeng.tile.storage.TileChest;
import appeng.util.Platform;
public class RenderMEChest extends BaseBlockRender<BlockChest, TileChest>
2014-09-24 02:26:27 +02:00
{
public RenderMEChest()
{
2014-09-24 02:26:27 +02:00
super( false, 0 );
}
@Override
2015-09-30 14:24:40 +02:00
public void renderInventory( final BlockChest block, final ItemStack is, final ModelGenerator renderer, final ItemRenderType type, final Object[] obj )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
renderer.setBrightness( 0 );
renderer.setOverrideBlockTexture( ExtraBlockTextures.White.getIcon() );
2015-06-16 02:44:59 +02:00
this.renderInvBlock( EnumSet.of( AEPartLocation.SOUTH ), block, is, 0x000000, renderer );
2014-09-24 02:26:27 +02:00
renderer.setOverrideBlockTexture( ExtraBlockTextures.MEChest.getIcon() );
2015-06-16 02:44:59 +02:00
this.renderInvBlock( EnumSet.of( AEPartLocation.UP ), block, is, this.adjustBrightness( AEColor.Transparent.whiteVariant, 0.7 ), renderer );
2014-09-24 02:26:27 +02:00
renderer.setOverrideBlockTexture( null );
2014-09-24 02:26:27 +02:00
super.renderInventory( block, is, renderer, type, obj );
}
@Override
2015-09-30 14:24:40 +02:00
public boolean renderInWorld( final BlockChest imb, final IBlockAccess world, final BlockPos pos, final ModelGenerator renderer )
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:24:40 +02:00
final TileChest sp = imb.getTileEntity( world, pos );
2014-09-24 02:26:27 +02:00
renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 );
if( sp == null )
2015-04-29 02:30:53 +02:00
{
return false;
2015-04-29 02:30:53 +02:00
}
2015-09-30 14:24:40 +02:00
final EnumFacing up = sp.getUp();
final EnumFacing forward = sp.getForward();
final EnumFacing west = Platform.crossProduct( forward, up );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
this.preRenderInWorld( imb, world, pos, renderer );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
final int stat = sp.getCellStatus( 0 );
final boolean result = renderer.renderStandardBlock( imb, pos );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.selectFace( renderer, west, up, forward, 5, 16 - 5, 9, 12 );
2014-09-24 02:26:27 +02:00
int offsetV = 8;
if( stat == 0 )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
offsetV = 3;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
int b = world.getCombinedLight( pos.offset( forward ), 0 );
renderer.setBrightness( b );
renderer.setColorOpaque_I( 0xffffff );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
final int offsetU = -4;
final FlippableIcon flippableIcon = new FlippableIcon( new OffsetIcon( ExtraBlockTextures.MEStorageCellTextures.getIcon(), offsetU, offsetV ) );
2015-06-16 02:44:59 +02:00
if( forward == EnumFacing.EAST && ( up == EnumFacing.NORTH || up == EnumFacing.SOUTH ) )
2015-04-29 02:30:53 +02:00
{
flippableIcon.setFlip( true, false );
2015-04-29 02:30:53 +02:00
}
2015-06-16 02:44:59 +02:00
else if( forward == EnumFacing.NORTH && up == EnumFacing.EAST )
2015-04-29 02:30:53 +02:00
{
flippableIcon.setFlip( false, true );
2015-04-29 02:30:53 +02:00
}
2015-06-16 02:44:59 +02:00
else if( forward == EnumFacing.NORTH && up == EnumFacing.WEST )
2015-04-29 02:30:53 +02:00
{
flippableIcon.setFlip( true, false );
2015-04-29 02:30:53 +02:00
}
2015-06-16 02:44:59 +02:00
else if( forward == EnumFacing.DOWN && up == EnumFacing.EAST )
2015-04-29 02:30:53 +02:00
{
flippableIcon.setFlip( false, true );
2015-04-29 02:30:53 +02:00
}
2015-06-16 02:44:59 +02:00
else if( forward == EnumFacing.DOWN )
2015-04-29 02:30:53 +02:00
{
flippableIcon.setFlip( true, false );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
/*
* 1.7.2
2015-06-16 02:44:59 +02:00
* else if ( forward == AEPartLocation.EAST && up == AEPartLocation.UP ) flippableIcon.setFlip( true, false );
* else if (
2015-06-16 02:44:59 +02:00
* forward == AEPartLocation.NORTH && up == AEPartLocation.UP ) flippableIcon.setFlip( true, false );
2014-09-24 02:26:27 +02:00
*/
2015-06-16 02:44:59 +02:00
this.renderFace( pos, imb, flippableIcon, renderer, forward );
2014-09-24 02:26:27 +02:00
if( stat != 0 )
2014-09-24 02:26:27 +02:00
{
b = 0;
if( sp.isPowered() )
2014-09-24 02:26:27 +02:00
{
b = 15 << 20 | 15 << 4;
}
2015-06-16 02:44:59 +02:00
renderer.setBrightness( b );
if( stat == 1 )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( 0x00ff00 );
2015-04-29 02:30:53 +02:00
}
if( stat == 2 )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( 0xffaa00 );
2015-04-29 02:30:53 +02:00
}
if( stat == 3 )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( 0xff0000 );
2015-04-29 02:30:53 +02:00
}
2014-12-29 15:13:47 +01:00
this.selectFace( renderer, west, up, forward, 9, 10, 11, 12 );
2015-06-16 02:44:59 +02:00
this.renderFace( pos, imb, ExtraBlockTextures.White.getIcon(), renderer, forward );
2014-09-24 02:26:27 +02:00
}
2015-06-16 02:44:59 +02:00
b = world.getCombinedLight( pos.offset( up ), 0 );
if( sp.isPowered() )
2014-09-24 02:26:27 +02:00
{
b = 15 << 20 | 15 << 4;
}
2015-06-16 02:44:59 +02:00
renderer.setBrightness( b );
renderer.setColorOpaque_I( 0xffffff );
2014-09-24 02:26:27 +02:00
renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 );
2015-09-30 14:24:40 +02:00
final ICellHandler ch = AEApi.instance().registries().cell().getHandler( sp.getStorageType() );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( sp.getColor().whiteVariant );
IAESprite ico = ch == null ? null : ch.getTopTexture_Light();
this.renderFace( pos, imb, ico == null ? ExtraBlockTextures.MEChest.getIcon() : ico, renderer, up );
2014-09-24 02:26:27 +02:00
if( ico != null )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( sp.getColor().mediumVariant );
2014-09-24 02:26:27 +02:00
ico = ch == null ? null : ch.getTopTexture_Medium();
2015-06-16 02:44:59 +02:00
this.renderFace( pos, imb, ico == null ? ExtraBlockTextures.MEChest.getIcon() : ico, renderer, up );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( sp.getColor().blackVariant );
2014-09-24 02:26:27 +02:00
ico = ch == null ? null : ch.getTopTexture_Dark();
2015-06-16 02:44:59 +02:00
this.renderFace( pos, imb, ico == null ? ExtraBlockTextures.MEChest.getIcon() : ico, renderer, up );
2014-09-24 02:26:27 +02:00
}
renderer.setOverrideBlockTexture( null );
2014-12-29 15:13:47 +01:00
this.postRenderInWorld( renderer );
2014-09-24 02:26:27 +02:00
return result;
}
}