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
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
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.util.AEColor;
|
2015-05-09 12:18:43 +02:00
|
|
|
import appeng.block.networking.BlockWireless;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.client.render.BaseBlockRender;
|
|
|
|
import appeng.client.render.BlockRenderInfo;
|
|
|
|
import appeng.client.texture.CableBusTextures;
|
|
|
|
import appeng.client.texture.ExtraBlockTextures;
|
|
|
|
import appeng.client.texture.OffsetIcon;
|
|
|
|
import appeng.tile.networking.TileWireless;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-05-09 12:18:43 +02:00
|
|
|
public class RenderBlockWireless extends BaseBlockRender<BlockWireless, TileWireless>
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
2015-05-09 12:18:43 +02:00
|
|
|
private int centerX = 0;
|
|
|
|
private int centerY = 0;
|
|
|
|
private int centerZ = 0;
|
|
|
|
private BlockWireless blk;
|
|
|
|
private boolean hasChan = false;
|
|
|
|
private boolean hasPower = false;
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
public RenderBlockWireless()
|
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super( false, 20 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void renderInventory( final BlockWireless blk, final ItemStack is, final RenderBlocks renderer, final ItemRenderType type, final Object[] obj )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
this.blk = blk;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.centerX = 0;
|
|
|
|
this.centerY = 0;
|
|
|
|
this.centerZ = 0;
|
|
|
|
this.hasChan = false;
|
|
|
|
this.hasPower = false;
|
2015-09-25 23:10:56 +02:00
|
|
|
final BlockRenderInfo ri = blk.getRendererInstance();
|
|
|
|
final Tessellator tess = Tessellator.instance;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
renderer.renderAllFaces = true;
|
|
|
|
|
|
|
|
IIcon r = CableBusTextures.PartMonitorSidesStatus.getIcon();
|
|
|
|
ri.setTemporaryRenderIcons( r, r, CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), r, r );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderBlockBounds( renderer, 5, 5, 0, 11, 11, 1, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH );
|
|
|
|
this.renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
r = CableBusTextures.PartWirelessSides.getIcon();
|
|
|
|
ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderBlockBounds( renderer, 5, 5, 1, 11, 11, 2, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH );
|
|
|
|
this.renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
tess.startDrawingQuads();
|
|
|
|
ri.setTemporaryRenderIcon( null );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderTorchAtAngle( renderer, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH );
|
2014-09-24 02:26:27 +02:00
|
|
|
super.postRenderInWorld( renderer );
|
|
|
|
tess.draw();
|
|
|
|
|
|
|
|
ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r );
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final ForgeDirection[] sides = { ForgeDirection.EAST, ForgeDirection.WEST, ForgeDirection.UP, ForgeDirection.DOWN };
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
int s = 1;
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection side : sides )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.renderBlockBounds( renderer, 8 + ( side.offsetX != 0 ? side.offsetX * 2 : -2 ), 8 + ( side.offsetY != 0 ? side.offsetY * 2 : -2 ), 2 + ( side.offsetZ != 0 ? side.offsetZ * 2 : -1 ) + s, 8 + ( side.offsetX != 0 ? side.offsetX * 4 : 2 ), 8 + ( side.offsetY != 0 ? side.offsetY * 4 : 2 ), 2 + ( side.offsetZ != 0 ? side.offsetZ * 5 : 1 ) + s, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
s = 3;
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection side : sides )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.renderBlockBounds( renderer, 8 + ( side.offsetX != 0 ? side.offsetX * 4 : -1 ), 8 + ( side.offsetY != 0 ? side.offsetY * 4 : -1 ), 1 + ( side.offsetZ != 0 ? side.offsetZ * 4 : -1 ) + s, 8 + ( side.offsetX != 0 ? side.offsetX * 5 : 1 ), 8 + ( side.offsetY != 0 ? side.offsetY * 5 : 1 ), 2 + ( side.offsetZ != 0 ? side.offsetZ * 5 : 1 ) + s, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean renderInWorld( final BlockWireless blk, 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 TileWireless tw = blk.getTileEntity( world, x, y, z );
|
2014-09-24 02:26:27 +02:00
|
|
|
this.blk = blk;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tw != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.hasChan = ( tw.getClientFlags() & ( TileWireless.POWERED_FLAG | TileWireless.CHANNEL_FLAG ) ) == ( TileWireless.POWERED_FLAG | TileWireless.CHANNEL_FLAG );
|
|
|
|
this.hasPower = ( tw.getClientFlags() & TileWireless.POWERED_FLAG ) == TileWireless.POWERED_FLAG;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final BlockRenderInfo ri = blk.getRendererInstance();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final ForgeDirection fdy = tw.getUp();
|
|
|
|
final ForgeDirection fdz = tw.getForward();
|
|
|
|
final ForgeDirection fdx = Platform.crossProduct( fdz, fdy ).getOpposite();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
renderer.renderAllFaces = true;
|
|
|
|
|
|
|
|
IIcon r = CableBusTextures.PartMonitorSidesStatus.getIcon();
|
|
|
|
ri.setTemporaryRenderIcons( r, r, CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), r, r );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderBlockBounds( renderer, 5, 5, 0, 11, 11, 1, fdx, fdy, fdz );
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderInWorld( blk, world, x, y, z, renderer );
|
|
|
|
|
|
|
|
r = CableBusTextures.PartWirelessSides.getIcon();
|
|
|
|
ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderBlockBounds( renderer, 5, 5, 1, 11, 11, 2, fdx, fdy, fdz );
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderInWorld( blk, world, x, y, z, renderer );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.centerX = x;
|
|
|
|
this.centerY = y;
|
|
|
|
this.centerZ = z;
|
2014-09-24 02:26:27 +02:00
|
|
|
ri.setTemporaryRenderIcon( null );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderTorchAtAngle( renderer, fdx, fdy, fdz );
|
2014-09-24 02:26:27 +02:00
|
|
|
super.postRenderInWorld( renderer );
|
|
|
|
|
|
|
|
ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r );
|
|
|
|
|
2015-09-27 00:00:11 +02:00
|
|
|
final ForgeDirection[] sides = { ForgeDirection.EAST, ForgeDirection.WEST, ForgeDirection.UP, ForgeDirection.DOWN };
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
int s = 1;
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection side : sides )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.renderBlockBounds( renderer, 8 + ( side.offsetX != 0 ? side.offsetX * 2 : -2 ), 8 + ( side.offsetY != 0 ? side.offsetY * 2 : -2 ), 2 + ( side.offsetZ != 0 ? side.offsetZ * 2 : -1 ) + s, 8 + ( side.offsetX != 0 ? side.offsetX * 4 : 2 ), 8 + ( side.offsetY != 0 ? side.offsetY * 4 : 2 ), 2 + ( side.offsetZ != 0 ? side.offsetZ * 5 : 1 ) + s, fdx, fdy, fdz );
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderInWorld( blk, world, x, y, z, renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
s = 3;
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection side : sides )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.renderBlockBounds( renderer, 8 + ( side.offsetX != 0 ? side.offsetX * 4 : -1 ), 8 + ( side.offsetY != 0 ? side.offsetY * 4 : -1 ), 1 + ( side.offsetZ != 0 ? side.offsetZ * 4 : -1 ) + s, 8 + ( side.offsetX != 0 ? side.offsetX * 5 : 1 ), 8 + ( side.offsetY != 0 ? side.offsetY * 5 : 1 ), 2 + ( side.offsetZ != 0 ? side.offsetZ * 5 : 1 ) + s, fdx, fdy, fdz );
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderInWorld( blk, world, x, y, z, renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
r = CableBusTextures.PartMonitorSidesStatusLights.getIcon();
|
|
|
|
// ri.setTemporaryRenderIcons( r, r, ExtraTextures.BlockChargerInside.getIcon(),
|
|
|
|
// ExtraTextures.BlockChargerInside.getIcon(), r, r );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderBlockBounds( renderer, 5, 5, 0, 11, 11, 1, fdx, fdy, fdz );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.hasChan )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int l = 14;
|
2014-09-24 02:26:27 +02:00
|
|
|
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
|
|
|
Tessellator.instance.setColorOpaque_I( AEColor.Transparent.blackVariant );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( this.hasPower )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int l = 9;
|
2014-09-24 02:26:27 +02:00
|
|
|
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
|
|
|
Tessellator.instance.setColorOpaque_I( AEColor.Transparent.whiteVariant );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Tessellator.instance.setBrightness( 0 );
|
|
|
|
Tessellator.instance.setColorOpaque_I( 0x000000 );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ForgeDirection.UP != fdz.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.UP );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ForgeDirection.DOWN != fdz.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.DOWN );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ForgeDirection.EAST != fdz.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.EAST );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ForgeDirection.WEST != fdz.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.WEST );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ForgeDirection.SOUTH != fdz.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.SOUTH );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ForgeDirection.NORTH != fdz.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.NORTH );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
ri.setTemporaryRenderIcon( null );
|
|
|
|
renderer.renderAllFaces = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private void renderTorchAtAngle( final RenderBlocks renderer, final ForgeDirection x, final ForgeDirection y, final ForgeDirection z )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IIcon r = ( this.hasChan ? CableBusTextures.BlockWirelessOn.getIcon() : this.blk.getIcon( 0, 0 ) );
|
|
|
|
final IIcon sides = new OffsetIcon( r, 0.0f, -2.0f );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( z )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case DOWN:
|
|
|
|
renderer.uvRotateNorth = 3;
|
|
|
|
renderer.uvRotateSouth = 3;
|
|
|
|
renderer.uvRotateEast = 3;
|
|
|
|
renderer.uvRotateWest = 3;
|
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
renderer.uvRotateTop = 1;
|
|
|
|
renderer.uvRotateBottom = 2;
|
|
|
|
renderer.uvRotateEast = 2;
|
|
|
|
renderer.uvRotateWest = 1;
|
|
|
|
break;
|
|
|
|
case NORTH:
|
|
|
|
renderer.uvRotateTop = 0;
|
|
|
|
renderer.uvRotateBottom = 0;
|
|
|
|
renderer.uvRotateNorth = 2;
|
|
|
|
renderer.uvRotateSouth = 1;
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
renderer.uvRotateTop = 3;
|
|
|
|
renderer.uvRotateBottom = 3;
|
|
|
|
renderer.uvRotateNorth = 1;
|
|
|
|
renderer.uvRotateSouth = 2;
|
|
|
|
break;
|
|
|
|
case WEST:
|
|
|
|
renderer.uvRotateTop = 2;
|
|
|
|
renderer.uvRotateBottom = 1;
|
|
|
|
renderer.uvRotateEast = 1;
|
|
|
|
renderer.uvRotateWest = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Tessellator.instance.setColorOpaque_I( 0xffffff );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderBlockBounds( renderer, 0, 7, 1, 16, 9, 16, x, y, z );
|
|
|
|
this.renderFace( this.centerX, this.centerY, this.centerZ, this.blk, sides, renderer, y );
|
|
|
|
this.renderFace( this.centerX, this.centerY, this.centerZ, this.blk, sides, renderer, y.getOpposite() );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderBlockBounds( renderer, 7, 0, 1, 9, 16, 16, x, y, z );
|
|
|
|
this.renderFace( this.centerX, this.centerY, this.centerZ, this.blk, sides, renderer, x );
|
|
|
|
this.renderFace( this.centerX, this.centerY, this.centerZ, this.blk, sides, renderer, x.getOpposite() );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderBlockBounds( renderer, 7, 7, 1, 9, 9, 10.6, x, y, z );
|
|
|
|
this.renderFace( this.centerX, this.centerY, this.centerZ, this.blk, r, renderer, z );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|