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 net.minecraft.tileentity.TileEntity;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-06-19 14:43:27 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2014-09-24 02:26:27 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-08-06 18:31:46 +02:00
|
|
|
|
2016-02-16 21:06:59 +01:00
|
|
|
import appeng.api.util.ModelGenerator;
|
2015-05-09 12:18:43 +02:00
|
|
|
import appeng.block.networking.BlockController;
|
2015-06-16 02:44:59 +02:00
|
|
|
import appeng.block.networking.BlockController.ControllerBlockState;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.client.render.BaseBlockRender;
|
|
|
|
import appeng.client.texture.ExtraBlockTextures;
|
|
|
|
import appeng.tile.networking.TileController;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-05-09 12:18:43 +02:00
|
|
|
public class RenderBlockController extends BaseBlockRender<BlockController, TileController>
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public RenderBlockController()
|
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super( false, 20 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-30 14:24:40 +02:00
|
|
|
public boolean renderInWorld( final BlockController blk, final IBlockAccess world, final BlockPos pos, final ModelGenerator renderer )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
2015-12-24 02:03:16 +01:00
|
|
|
final boolean xx = this.getTileEntity( world, pos.offset( EnumFacing.WEST ) ) instanceof TileController && this.getTileEntity( world, pos.offset( EnumFacing.EAST ) ) instanceof TileController;
|
2015-09-30 14:24:40 +02:00
|
|
|
final boolean yy = this.getTileEntity( world, pos.offset( EnumFacing.DOWN ) ) instanceof TileController && this.getTileEntity( world, pos.offset( EnumFacing.UP ) ) instanceof TileController;
|
2015-12-24 02:03:16 +01:00
|
|
|
final boolean zz = this.getTileEntity( world, pos.offset( EnumFacing.SOUTH ) ) instanceof TileController && this.getTileEntity( world, pos.offset( EnumFacing.NORTH ) ) instanceof TileController;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-12-24 02:03:16 +01:00
|
|
|
final BlockController.ControllerBlockState meta = (ControllerBlockState) world.getBlockState( pos ).getValue( BlockController.CONTROLLER_STATE );
|
2015-09-30 14:24:40 +02:00
|
|
|
final boolean hasPower = meta != BlockController.ControllerBlockState.OFFLINE;
|
|
|
|
final boolean isConflict = meta == BlockController.ControllerBlockState.CONFLICTED;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
ExtraBlockTextures lights = null;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( xx && !yy && !zz )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasPower )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumnPowered.getIcon() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( isConflict )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
lights = ExtraBlockTextures.BlockControllerColumnConflict;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
lights = ExtraBlockTextures.BlockControllerColumnLights;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumn.getIcon() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
renderer.setUvRotateEast( 1 );
|
|
|
|
renderer.setUvRotateWest( 1 );
|
|
|
|
renderer.setUvRotateTop( 1 );
|
|
|
|
renderer.setUvRotateBottom( 1 );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( !xx && yy && !zz )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasPower )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumnPowered.getIcon() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( isConflict )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
lights = ExtraBlockTextures.BlockControllerColumnConflict;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
lights = ExtraBlockTextures.BlockControllerColumnLights;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumn.getIcon() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
renderer.setUvRotateEast( 0 );
|
|
|
|
renderer.setUvRotateNorth( 0 );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( !xx && !yy && zz )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasPower )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumnPowered.getIcon() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( isConflict )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
lights = ExtraBlockTextures.BlockControllerColumnConflict;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
lights = ExtraBlockTextures.BlockControllerColumnLights;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumn.getIcon() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
renderer.setUvRotateNorth( 1 );
|
|
|
|
renderer.setUvRotateSouth( 1 );
|
|
|
|
renderer.setUvRotateTop( 0 );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( ( xx ? 1 : 0 ) + ( yy ? 1 : 0 ) + ( zz ? 1 : 0 ) >= 2 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final int v = ( Math.abs( pos.getX() ) + Math.abs( pos.getY() ) + Math.abs( pos.getZ() ) ) % 2;
|
2015-10-08 15:42:42 +02:00
|
|
|
renderer.setUvRotateEast( renderer.setUvRotateBottom( renderer.setUvRotateNorth( renderer.setUvRotateSouth( renderer.setUvRotateTop( renderer.setUvRotateWest( 0 ) ) ) ) ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( v == 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerInsideA.getIcon() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerInsideB.getIcon() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasPower )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerPowered.getIcon() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( isConflict )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
lights = ExtraBlockTextures.BlockControllerConflict;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
lights = ExtraBlockTextures.BlockControllerLights;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( null );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final boolean out = renderer.renderStandardBlock( blk, pos );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( lights != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
renderer.setColorOpaque_F( 1.0f, 1.0f, 1.0f );
|
|
|
|
renderer.setBrightness( 14 << 20 | 14 << 4 );
|
|
|
|
renderer.renderFaceXNeg( blk, pos, lights.getIcon() );
|
|
|
|
renderer.renderFaceXPos( blk, pos, lights.getIcon() );
|
|
|
|
renderer.renderFaceYNeg( blk, pos, lights.getIcon() );
|
|
|
|
renderer.renderFaceYPos( blk, pos, lights.getIcon() );
|
|
|
|
renderer.renderFaceZNeg( blk, pos, lights.getIcon() );
|
|
|
|
renderer.renderFaceZPos( blk, pos, lights.getIcon() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( null );
|
2015-10-08 15:42:42 +02:00
|
|
|
renderer.setUvRotateEast( renderer.setUvRotateBottom( renderer.setUvRotateNorth( renderer.setUvRotateSouth( renderer.setUvRotateTop( renderer.setUvRotateWest( 0 ) ) ) ) ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
private TileEntity getTileEntity( final IBlockAccess world, final BlockPos pos )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
if( pos.getY() >= 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
return world.getTileEntity( pos );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|