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;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
import java.util.Collection;
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
import net.minecraft.block.Block;
|
2014-09-24 02:26:27 +02:00
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IBlocks;
|
|
|
|
import appeng.api.definitions.IDefinitions;
|
|
|
|
import appeng.api.definitions.IParts;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.util.AEColor;
|
2015-05-09 12:18:43 +02:00
|
|
|
import appeng.block.qnb.BlockQuantumBase;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.client.render.BaseBlockRender;
|
|
|
|
import appeng.client.texture.ExtraBlockTextures;
|
|
|
|
import appeng.tile.qnb.TileQuantumBridge;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-05-09 12:18:43 +02:00
|
|
|
public class RenderQNB extends BaseBlockRender<BlockQuantumBase, TileQuantumBridge>
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-16 18:03:07 +02:00
|
|
|
private static final float DEFAULT_RENDER_MIN = 2.0f / 16.0f;
|
|
|
|
private static final float DEFAULT_RENDER_MAX = 14.0f / 16.0f;
|
|
|
|
|
|
|
|
private static final float CORNER_POWERED_RENDER_MIN = 3.9f / 16.0f;
|
|
|
|
private static final float CORNER_POWERED_RENDER_MAX = 12.1f / 16.0f;
|
|
|
|
|
|
|
|
private static final float CENTER_POWERED_RENDER_MIN = -0.01f / 16.0f;
|
|
|
|
private static final float CENTER_POWERED_RENDER_MAX = 16.01f / 16.0f;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void renderInventory( final BlockQuantumBase block, final ItemStack item, final RenderBlocks renderer, final ItemRenderType type, final Object[] obj )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-16 18:03:07 +02:00
|
|
|
renderer.setRenderBounds( DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX );
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderInventory( block, item, renderer, type, obj );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean renderInWorld( final BlockQuantumBase block, final IBlockAccess world, final int x, final int y, final int z, final RenderBlocks renderer )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TileQuantumBridge tqb = block.getTileEntity( world, x, y, z );
|
2015-09-16 18:03:07 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tqb == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
renderer.renderAllFaces = true;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
final IDefinitions definitions = AEApi.instance().definitions();
|
|
|
|
final IBlocks blocks = definitions.blocks();
|
|
|
|
final IParts parts = definitions.parts();
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final Block linkBlock : blocks.quantumLink().maybeBlock().asSet() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tqb.getBlockType() == linkBlock )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tqb.isFormed() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final EnumSet<ForgeDirection> sides = tqb.getConnections();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final Item transGlassCable = parts.cableGlass().item( AEColor.Transparent );
|
2015-01-03 02:53:14 +01:00
|
|
|
this.renderCableAt( 0.11D, world, x, y, z, block, renderer, transGlassCable.getIconIndex( parts.cableGlass().stack( AEColor.Transparent, 1 ) ), 0.141D, sides );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final Item transCoveredCable = parts.cableCovered().item( AEColor.Transparent );
|
2015-01-03 02:53:14 +01:00
|
|
|
this.renderCableAt( 0.188D, world, x, y, z, block, renderer, transCoveredCable.getIconIndex( parts.cableCovered().stack( AEColor.Transparent, 1 ) ), 0.1875D, sides );
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-16 18:03:07 +02:00
|
|
|
renderer.setRenderBounds( DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX );
|
2014-09-24 02:26:27 +02:00
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
else
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !tqb.isFormed() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-16 18:03:07 +02:00
|
|
|
renderer.setRenderBounds( DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX );
|
2015-01-03 02:53:14 +01:00
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( tqb.isCorner() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final Item transCoveredCable = parts.cableCovered().item( AEColor.Transparent );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-16 18:03:07 +02:00
|
|
|
this.renderCableAt( 0.188D, world, x, y, z, block, renderer, transCoveredCable.getIconIndex( parts.cableCovered().stack( AEColor.Transparent, 1 ) ), 0.05D, tqb.getConnections() );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-16 18:03:07 +02:00
|
|
|
renderer.setRenderBounds( DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX );
|
2015-01-03 02:53:14 +01:00
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tqb.isPowered() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-09-16 18:03:07 +02:00
|
|
|
renderer.setRenderBounds( CORNER_POWERED_RENDER_MIN, CORNER_POWERED_RENDER_MIN, CORNER_POWERED_RENDER_MIN, CORNER_POWERED_RENDER_MAX, CORNER_POWERED_RENDER_MAX, CORNER_POWERED_RENDER_MAX );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
Tessellator.instance.setColorOpaque_F( 1.0F, 1.0F, 1.0F );
|
2015-09-25 23:10:56 +02:00
|
|
|
final int bn = 15;
|
2015-01-03 02:53:14 +01:00
|
|
|
Tessellator.instance.setBrightness( bn << 20 | bn << 4 );
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.renderFace( x, y, z, block, ExtraBlockTextures.BlockQRingCornerLight.getIcon(), renderer, side );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-16 18:03:07 +02:00
|
|
|
renderer.setRenderBounds( 0, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, 1, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX );
|
2015-01-03 02:53:14 +01:00
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
|
2015-09-16 18:03:07 +02:00
|
|
|
renderer.setRenderBounds( DEFAULT_RENDER_MIN, 0, DEFAULT_RENDER_MIN, DEFAULT_RENDER_MAX, 1, DEFAULT_RENDER_MAX );
|
2015-01-03 02:53:14 +01:00
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
|
2015-09-16 18:03:07 +02:00
|
|
|
renderer.setRenderBounds( DEFAULT_RENDER_MIN, DEFAULT_RENDER_MIN, 0, DEFAULT_RENDER_MAX, DEFAULT_RENDER_MAX, 1 );
|
2015-01-03 02:53:14 +01:00
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tqb.isPowered() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-09-16 18:03:07 +02:00
|
|
|
renderer.setRenderBounds( CENTER_POWERED_RENDER_MIN, CENTER_POWERED_RENDER_MIN, CENTER_POWERED_RENDER_MIN, CENTER_POWERED_RENDER_MAX, CENTER_POWERED_RENDER_MAX, CENTER_POWERED_RENDER_MAX );
|
2015-01-03 02:53:14 +01:00
|
|
|
|
|
|
|
Tessellator.instance.setColorOpaque_F( 1.0F, 1.0F, 1.0F );
|
2015-09-25 23:10:56 +02:00
|
|
|
final int bn = 15;
|
2015-01-03 02:53:14 +01:00
|
|
|
Tessellator.instance.setBrightness( bn << 20 | bn << 4 );
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.renderFace( x, y, z, block, ExtraBlockTextures.BlockQRingEdgeLight.getIcon(), renderer, side );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer.renderAllFaces = false;
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private void renderCableAt( final double thickness, final IBlockAccess world, final int x, final int y, final int z, final BlockQuantumBase block, final RenderBlocks renderer, final IIcon texture, final double pull, final Collection<ForgeDirection> connections )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
block.getRendererInstance().setTemporaryRenderIcon( texture );
|
|
|
|
|
|
|
|
if( connections.contains( ForgeDirection.UNKNOWN ) )
|
|
|
|
{
|
|
|
|
renderer.setRenderBounds( 0.5D - thickness, 0.5D - thickness, 0.5D - thickness, 0.5D + thickness, 0.5D + thickness, 0.5D + thickness );
|
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( connections.contains( ForgeDirection.WEST ) )
|
|
|
|
{
|
|
|
|
renderer.setRenderBounds( 0.0D, 0.5D - thickness, 0.5D - thickness, 0.5D - thickness - pull, 0.5D + thickness, 0.5D + thickness );
|
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( connections.contains( ForgeDirection.EAST ) )
|
|
|
|
{
|
|
|
|
renderer.setRenderBounds( 0.5D + thickness + pull, 0.5D - thickness, 0.5D - thickness, 1.0D, 0.5D + thickness, 0.5D + thickness );
|
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( connections.contains( ForgeDirection.NORTH ) )
|
|
|
|
{
|
|
|
|
renderer.setRenderBounds( 0.5D - thickness, 0.5D - thickness, 0.0D, 0.5D + thickness, 0.5D + thickness, 0.5D - thickness - pull );
|
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( connections.contains( ForgeDirection.SOUTH ) )
|
|
|
|
{
|
|
|
|
renderer.setRenderBounds( 0.5D - thickness, 0.5D - thickness, 0.5D + thickness + pull, 0.5D + thickness, 0.5D + thickness, 1.0D );
|
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( connections.contains( ForgeDirection.DOWN ) )
|
|
|
|
{
|
|
|
|
renderer.setRenderBounds( 0.5D - thickness, 0.0D, 0.5D - thickness, 0.5D + thickness, 0.5D - thickness - pull, 0.5D + thickness );
|
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( connections.contains( ForgeDirection.UP ) )
|
|
|
|
{
|
|
|
|
renderer.setRenderBounds( 0.5D - thickness, 0.5D + thickness + pull, 0.5D - thickness, 0.5D + thickness, 1.0D, 0.5D + thickness );
|
|
|
|
renderer.renderStandardBlock( block, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
block.getRendererInstance().setTemporaryRenderIcon( null );
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|