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

368 lines
12 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-05-14 04:42:14 +02:00
package appeng.client.render.blocks;
import java.util.EnumSet;
import net.minecraft.block.Block;
2014-05-14 04:42:14 +02:00
import net.minecraft.client.renderer.RenderBlocks;
2014-05-18 05:19:23 +02:00
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
2014-05-14 04:42:14 +02:00
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
2014-12-29 21:59:05 +01:00
import appeng.api.AEApi;
import appeng.api.util.AEColor;
2014-05-18 05:19:23 +02:00
import appeng.block.crafting.BlockCraftingMonitor;
import appeng.block.crafting.BlockCraftingUnit;
2014-05-14 04:42:14 +02:00
import appeng.client.render.BaseBlockRender;
import appeng.client.render.BusRenderHelper;
import appeng.client.render.BusRenderer;
import appeng.client.texture.ExtraBlockTextures;
import appeng.tile.crafting.TileCraftingMonitorTile;
2014-05-14 04:42:14 +02:00
import appeng.tile.crafting.TileCraftingTile;
public class RenderBlockCraftingCPU<B extends BlockCraftingUnit, T extends TileCraftingTile> extends BaseBlockRender<B, T>
2014-05-14 04:42:14 +02:00
{
protected RenderBlockCraftingCPU( final boolean useTESR, final int range )
{
super( useTESR, range );
2014-05-18 05:19:23 +02:00
}
public RenderBlockCraftingCPU()
{
2014-05-14 04:42:14 +02:00
super( false, 20 );
}
@Override
public boolean renderInWorld( final B blk, final IBlockAccess w, final int x, final int y, final int z, RenderBlocks renderer )
2014-05-14 04:42:14 +02:00
{
boolean formed = false;
2014-05-18 05:19:23 +02:00
boolean emitsLight = false;
final TileCraftingTile ct = blk.getTileEntity( w, x, y, z );
if( ct != null && ct.isFormed() )
2014-05-14 04:42:14 +02:00
{
2014-05-18 05:19:23 +02:00
formed = true;
emitsLight = ct.isPowered();
}
final int meta = w.getBlockMetadata( x, y, z ) & 3;
2014-05-18 05:19:23 +02:00
final boolean isMonitor = blk.getClass() == BlockCraftingMonitor.class;
final IIcon theIcon = blk.getIcon( ForgeDirection.SOUTH.ordinal(), meta | ( formed ? 8 : 0 ) );
IIcon nonForward = theIcon;
if( isMonitor )
{
for( final Block craftingBlock : AEApi.instance().definitions().blocks().craftingUnit().maybeBlock().asSet() )
{
nonForward = craftingBlock.getIcon( 0, meta | ( formed ? 8 : 0 ) );
}
}
if( formed && renderer.overrideBlockTexture == null )
{
renderer = BusRenderer.INSTANCE.getRenderer();
final BusRenderHelper i = BusRenderHelper.INSTANCE;
BusRenderer.INSTANCE.getRenderer().setFacade( true );
renderer.blockAccess = w;
i.setPass( 0 );
i.setOrientation( ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH );
try
{
ct.setLightCache( i.useSimplifiedRendering( x, y, z, null, ct.getLightCache() ) );
}
catch( final Throwable ignored )
{
}
final float highX = this.isConnected( w, x, y, z, ForgeDirection.EAST ) ? 16 : 13.01f;
final float lowX = this.isConnected( w, x, y, z, ForgeDirection.WEST ) ? 0 : 2.99f;
final float highY = this.isConnected( w, x, y, z, ForgeDirection.UP ) ? 16 : 13.01f;
final float lowY = this.isConnected( w, x, y, z, ForgeDirection.DOWN ) ? 0 : 2.99f;
final float highZ = this.isConnected( w, x, y, z, ForgeDirection.SOUTH ) ? 16 : 13.01f;
final float lowZ = this.isConnected( w, x, y, z, ForgeDirection.NORTH ) ? 0 : 2.99f;
2014-12-29 15:13:47 +01:00
this.renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.EAST, ForgeDirection.NORTH );
this.renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.EAST, ForgeDirection.SOUTH );
this.renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.WEST, ForgeDirection.NORTH );
this.renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.WEST, ForgeDirection.SOUTH );
this.renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.EAST, ForgeDirection.NORTH );
this.renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.EAST, ForgeDirection.SOUTH );
this.renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.WEST, ForgeDirection.NORTH );
this.renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.WEST, ForgeDirection.SOUTH );
for( final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS )
{
i.setBounds( this.fso( side, lowX, ForgeDirection.WEST ), this.fso( side, lowY, ForgeDirection.DOWN ), this.fso( side, lowZ, ForgeDirection.NORTH ), this.fso( side, highX, ForgeDirection.EAST ), this.fso( side, highY, ForgeDirection.UP ), this.fso( side, highZ, ForgeDirection.SOUTH ) );
i.prepareBounds( renderer );
boolean LocalEmit = emitsLight;
if( blk instanceof BlockCraftingMonitor && ct.getForward() != side )
2015-04-29 02:30:53 +02:00
{
LocalEmit = false;
2015-04-29 02:30:53 +02:00
}
this.handleSide( blk, meta, x, y, z, i, renderer, ct.getForward() == side ? theIcon : nonForward, LocalEmit, isMonitor, side, w );
}
BusRenderer.INSTANCE.getRenderer().setFacade( false );
i.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) );
i.normalRendering();
return true;
2014-05-14 04:42:14 +02:00
}
else
{
final double a = 0.0 / 16.0;
final double o = 16.0 / 16.0;
renderer.setRenderBounds( a, a, a, o, o, o );
2014-05-14 04:42:14 +02:00
2014-10-01 11:34:27 +02:00
return renderer.renderStandardBlock( blk, x, y, z );
2014-05-14 04:42:14 +02:00
}
}
private boolean isConnected( final IBlockAccess w, final int x, final int y, final int z, final ForgeDirection side )
{
final int tileYPos = y + side.offsetY;
if( 0 <= tileYPos && tileYPos <= 255 )
{
final TileEntity tile = w.getTileEntity( x + side.offsetX, tileYPos, z + side.offsetZ );
return tile instanceof TileCraftingTile;
}
else
{
return false;
}
}
private void renderCorner( final BusRenderHelper i, final RenderBlocks renderer, final IBlockAccess w, final int x, final int y, final int z, final ForgeDirection up, final ForgeDirection east, final ForgeDirection south )
{
if( this.isConnected( w, x, y, z, up ) )
2015-04-29 02:30:53 +02:00
{
return;
2015-04-29 02:30:53 +02:00
}
if( this.isConnected( w, x, y, z, east ) )
2015-04-29 02:30:53 +02:00
{
return;
2015-04-29 02:30:53 +02:00
}
if( this.isConnected( w, x, y, z, south ) )
2015-04-29 02:30:53 +02:00
{
return;
2015-04-29 02:30:53 +02:00
}
i.setBounds( this.gso( east, 3, ForgeDirection.WEST ), this.gso( up, 3, ForgeDirection.DOWN ), this.gso( south, 3, ForgeDirection.NORTH ), this.gso( east, 13, ForgeDirection.EAST ), this.gso( up, 13, ForgeDirection.UP ), this.gso( south, 13, ForgeDirection.SOUTH ) );
i.prepareBounds( renderer );
i.setTexture( ExtraBlockTextures.BlockCraftingUnitRing.getIcon() );
i.renderBlockCurrentBounds( x, y, z, renderer );
}
private float fso( final ForgeDirection side, final float def, final ForgeDirection target )
{
if( side == target )
{
if( side.offsetX > 0 || side.offsetY > 0 || side.offsetZ > 0 )
2015-04-29 02:30:53 +02:00
{
return 16;
2015-04-29 02:30:53 +02:00
}
return 0;
}
return def;
}
private void handleSide( final B blk, final int meta, final int x, final int y, final int z, final BusRenderHelper i, final RenderBlocks renderer, final IIcon color, final boolean emitsLight, final boolean isMonitor, final ForgeDirection side, final IBlockAccess w )
{
if( this.isConnected( w, x, y, z, side ) )
2015-04-29 02:30:53 +02:00
{
return;
2015-04-29 02:30:53 +02:00
}
i.setFacesToRender( EnumSet.of( side ) );
2014-05-18 05:19:23 +02:00
if( meta == 0 && blk.getClass() == BlockCraftingUnit.class )
2014-05-18 05:19:23 +02:00
{
i.setTexture( ExtraBlockTextures.BlockCraftingUnitFit.getIcon() );
2014-05-18 05:19:23 +02:00
i.renderBlockCurrentBounds( x, y, z, renderer );
}
else
{
if( color == ExtraBlockTextures.BlockCraftingMonitorFit_Light.getIcon() )
2015-04-29 02:30:53 +02:00
{
i.setTexture( ExtraBlockTextures.BlockCraftingMonitorOuter.getIcon() );
2015-04-29 02:30:53 +02:00
}
2014-05-18 05:19:23 +02:00
else
2015-04-29 02:30:53 +02:00
{
i.setTexture( ExtraBlockTextures.BlockCraftingFitSolid.getIcon() );
2015-04-29 02:30:53 +02:00
}
2014-05-18 05:19:23 +02:00
i.renderBlockCurrentBounds( x, y, z, renderer );
if( color != null )
2014-05-18 05:19:23 +02:00
{
i.setTexture( color );
if( !emitsLight )
2014-05-18 05:19:23 +02:00
{
if( color == ExtraBlockTextures.BlockCraftingMonitorFit_Light.getIcon() )
{
final int b = w.getLightBrightnessForSkyBlocks( x + side.offsetX, y + side.offsetY, z + side.offsetZ, 0 );
final TileCraftingMonitorTile sr = blk.getTileEntity( w, x, y, z );
final AEColor col = sr.getColor();
Tessellator.instance.setBrightness( b );
Tessellator.instance.setColorOpaque_I( col.whiteVariant );
i.renderFace( x, y, z, color, side, renderer );
Tessellator.instance.setColorOpaque_I( col.mediumVariant );
i.renderFace( x, y, z, ExtraBlockTextures.BlockCraftingMonitorFit_Medium.getIcon(), side, renderer );
Tessellator.instance.setColorOpaque_I( col.blackVariant );
i.renderFace( x, y, z, ExtraBlockTextures.BlockCraftingMonitorFit_Dark.getIcon(), side, renderer );
}
else
2015-04-29 02:30:53 +02:00
{
i.renderBlockCurrentBounds( x, y, z, renderer );
2015-04-29 02:30:53 +02:00
}
2014-05-18 05:19:23 +02:00
}
else
{
if( isMonitor )
{
final TileCraftingMonitorTile sr = blk.getTileEntity( w, x, y, z );
final AEColor col = sr.getColor();
Tessellator.instance.setColorOpaque_I( col.whiteVariant );
Tessellator.instance.setBrightness( 13 << 20 | 13 << 4 );
i.renderFace( x, y, z, color, side, renderer );
Tessellator.instance.setColorOpaque_I( col.mediumVariant );
Tessellator.instance.setBrightness( 13 << 20 | 13 << 4 );
i.renderFace( x, y, z, ExtraBlockTextures.BlockCraftingMonitorFit_Medium.getIcon(), side, renderer );
Tessellator.instance.setColorOpaque_I( col.blackVariant );
Tessellator.instance.setBrightness( 13 << 20 | 13 << 4 );
i.renderFace( x, y, z, ExtraBlockTextures.BlockCraftingMonitorFit_Dark.getIcon(), side, renderer );
}
else
{
Tessellator.instance.setColorOpaque_F( 1.0f, 1.0f, 1.0f );
Tessellator.instance.setBrightness( 13 << 20 | 13 << 4 );
i.renderFace( x, y, z, color, side, renderer );
}
2014-05-18 05:19:23 +02:00
}
}
}
for( final ForgeDirection a : ForgeDirection.VALID_DIRECTIONS )
{
if( a == side || a == side.getOpposite() )
2015-04-29 02:30:53 +02:00
{
continue;
2015-04-29 02:30:53 +02:00
}
if( ( side.offsetX != 0 || side.offsetZ != 0 ) && ( a == ForgeDirection.NORTH || a == ForgeDirection.EAST || a == ForgeDirection.WEST || a == ForgeDirection.SOUTH ) )
2015-04-29 02:30:53 +02:00
{
i.setTexture( ExtraBlockTextures.BlockCraftingUnitRingLongRotated.getIcon() );
2015-04-29 02:30:53 +02:00
}
else if( ( side.offsetY != 0 ) && ( a == ForgeDirection.EAST || a == ForgeDirection.WEST ) )
2015-04-29 02:30:53 +02:00
{
i.setTexture( ExtraBlockTextures.BlockCraftingUnitRingLongRotated.getIcon() );
2015-04-29 02:30:53 +02:00
}
else
2015-04-29 02:30:53 +02:00
{
i.setTexture( ExtraBlockTextures.BlockCraftingUnitRingLong.getIcon() );
2015-04-29 02:30:53 +02:00
}
if( !( i.getBound( a ) < 0.001 || i.getBound( a ) > 15.999 ) )
{
final double width = 3.0 / 16.0;
switch( a )
{
case DOWN:
renderer.renderMinY = 0;
renderer.renderMaxY = width;
break;
case EAST:
renderer.renderMaxX = 1;
renderer.renderMinX = 1.0 - width;
renderer.uvRotateTop = 1;
renderer.uvRotateBottom = 1;
renderer.uvRotateWest = 1;
renderer.uvRotateEast = 1;
break;
case NORTH:
renderer.renderMinZ = 0;
renderer.renderMaxZ = width;
renderer.uvRotateWest = 1;
renderer.uvRotateNorth = 1;
renderer.uvRotateSouth = 1;
break;
case SOUTH:
renderer.renderMaxZ = 1;
renderer.renderMinZ = 1.0 - width;
renderer.uvRotateNorth = 1;
renderer.uvRotateSouth = 1;
break;
case UP:
renderer.renderMaxY = 1;
renderer.renderMinY = 1.0 - width;
break;
case WEST:
renderer.renderMinX = 0;
renderer.renderMaxX = width;
renderer.uvRotateTop = 1;
renderer.uvRotateBottom = 1;
renderer.uvRotateWest = 1;
renderer.uvRotateEast = 1;
break;
case UNKNOWN:
default:
}
i.renderBlockCurrentBounds( x, y, z, renderer );
i.prepareBounds( renderer );
}
}
}
private float gso( final ForgeDirection side, final float def, final ForgeDirection target )
{
if( side != target )
{
if( side.offsetX > 0 || side.offsetY > 0 || side.offsetZ > 0 )
2015-04-29 02:30:53 +02:00
{
return 16;
2015-04-29 02:30:53 +02:00
}
return 0;
}
return def;
}
2014-05-14 04:42:14 +02:00
}