Applied-Energistics-2-tiler.../src/main/java/appeng/parts/networking/PartCableSmart.java

377 lines
13 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.parts.networking;
2014-09-24 02:26:27 +02:00
import java.util.EnumSet;
2015-12-24 02:07:03 +01:00
import org.lwjgl.opengl.GL11;
2014-09-24 02:26:27 +02:00
import net.minecraft.item.ItemStack;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2014-09-24 02:26:27 +02:00
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartRenderHelper;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEPartLocation;
import appeng.api.util.IAESprite;
import appeng.api.util.ModelGenerator;
2014-09-24 02:26:27 +02:00
import appeng.block.AEBaseBlock;
2014-12-29 21:59:05 +01:00
import appeng.client.texture.FlippableIcon;
2014-09-24 02:26:27 +02:00
import appeng.client.texture.OffsetIcon;
import appeng.client.texture.TaughtIcon;
import appeng.helpers.Reflected;
2014-09-24 02:26:27 +02:00
import appeng.util.Platform;
2014-09-24 02:26:27 +02:00
public class PartCableSmart extends PartCable
{
@Reflected
2015-09-30 14:24:40 +02:00
public PartCableSmart( final ItemStack is )
{
super( is );
}
2014-09-24 02:26:27 +02:00
@MENetworkEventSubscribe
2015-09-30 14:24:40 +02:00
public void channelUpdated( final MENetworkChannelsChanged c )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.getHost().markForUpdate();
2014-09-24 02:26:27 +02:00
}
@MENetworkEventSubscribe
2015-09-30 14:24:40 +02:00
public void powerRender( final MENetworkPowerStatusChange c )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.getHost().markForUpdate();
2014-09-24 02:26:27 +02:00
}
@Override
public AECableType getCableConnectionType()
{
return AECableType.SMART;
}
@Override
2015-09-30 14:24:40 +02:00
public void getBoxes( final IPartCollisionHelper bch )
2014-09-24 02:26:27 +02:00
{
bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 );
if( Platform.isServer() )
{
2015-09-30 14:24:40 +02:00
final IGridNode n = this.getGridNode();
if( n != null )
2015-04-29 02:30:53 +02:00
{
this.setConnections( n.getConnectedSides() );
2015-04-29 02:30:53 +02:00
}
else
2015-04-29 02:30:53 +02:00
{
this.getConnections().clear();
2015-04-29 02:30:53 +02:00
}
}
for( final AEPartLocation of : this.getConnections() )
{
switch( of )
{
case DOWN:
bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 );
break;
case EAST:
bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 );
break;
case NORTH:
bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 );
break;
case SOUTH:
bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 );
break;
case UP:
bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 );
break;
case WEST:
bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 );
break;
default:
}
}
2014-09-24 02:26:27 +02:00
}
@Override
@SideOnly( Side.CLIENT )
2015-09-30 14:24:40 +02:00
public void renderInventory( final IPartRenderHelper rh, final ModelGenerator renderer )
2014-09-24 02:26:27 +02:00
{
GL11.glTranslated( -0.0, -0.0, 0.3 );
float offU = 0;
float offV = 9;
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
OffsetIcon main = new OffsetIcon( this.getTexture( this.getCableColor(), renderer ), offU, offV );
2014-12-29 15:13:47 +01:00
OffsetIcon ch1 = new OffsetIcon( this.getChannelTex( 4, false ).getIcon(), offU, offV );
OffsetIcon ch2 = new OffsetIcon( this.getChannelTex( 4, true ).getIcon(), offU, offV );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
for( final EnumFacing side : EnumSet.of( EnumFacing.UP, EnumFacing.DOWN ) )
2014-09-24 02:26:27 +02:00
{
rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f );
rh.renderInventoryFace( main, side, renderer );
rh.renderInventoryFace( ch1, side, renderer );
rh.renderInventoryFace( ch2, side, renderer );
}
offU = 9;
offV = 0;
2015-06-16 02:44:59 +02:00
main = new OffsetIcon( this.getTexture( this.getCableColor(), renderer ), offU, offV );
2014-12-29 15:13:47 +01:00
ch1 = new OffsetIcon( this.getChannelTex( 4, false ).getIcon(), offU, offV );
ch2 = new OffsetIcon( this.getChannelTex( 4, true ).getIcon(), offU, offV );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
for( final EnumFacing side : EnumSet.of( EnumFacing.EAST, EnumFacing.WEST ) )
2014-09-24 02:26:27 +02:00
{
rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f );
rh.renderInventoryFace( main, side, renderer );
rh.renderInventoryFace( ch1, side, renderer );
rh.renderInventoryFace( ch2, side, renderer );
}
2015-06-16 02:44:59 +02:00
main = new OffsetIcon( this.getTexture( this.getCableColor(), renderer ), 0, 0 );
2014-12-29 15:13:47 +01:00
ch1 = new OffsetIcon( this.getChannelTex( 4, false ).getIcon(), 0, 0 );
ch2 = new OffsetIcon( this.getChannelTex( 4, true ).getIcon(), 0, 0 );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
for( final EnumFacing side : EnumSet.of( EnumFacing.SOUTH, EnumFacing.NORTH ) )
2014-09-24 02:26:27 +02:00
{
rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f );
rh.renderInventoryFace( main, side, renderer );
rh.renderInventoryFace( ch1, side, renderer );
rh.renderInventoryFace( ch2, side, renderer );
}
rh.setTexture( null );
}
@Override
2015-09-30 14:24:40 +02:00
public IAESprite getTexture( final AEColor c, final ModelGenerator renderer )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
return this.getSmartTexture( c, renderer );
2014-09-24 02:26:27 +02:00
}
@Override
@SideOnly( Side.CLIENT )
2015-09-30 14:24:40 +02:00
public void renderStatic( final BlockPos pos, final IPartRenderHelper rh, final ModelGenerator renderer )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
rh.setTexture( this.getTexture( this.getCableColor(), renderer ) );
2014-09-24 02:26:27 +02:00
final EnumSet<AEPartLocation> sides = this.getConnections().clone();
2014-09-24 02:26:27 +02:00
boolean hasBuses = false;
2015-09-30 14:24:40 +02:00
final IPartHost ph = this.getHost();
for( final AEPartLocation of : EnumSet.complementOf( this.getConnections() ) )
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:24:40 +02:00
final IPart bp = ph.getPart( of );
if( bp instanceof IGridHost )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
if( of != AEPartLocation.INTERNAL )
2014-09-24 02:26:27 +02:00
{
sides.add( of );
hasBuses = true;
}
2015-09-30 14:24:40 +02:00
final int len = bp.cableConnectionRenderTo();
if( len < 8 )
2014-09-24 02:26:27 +02:00
{
switch( of )
2014-09-24 02:26:27 +02:00
{
case DOWN:
rh.setBounds( 6, len, 6, 10, 5, 10 );
break;
case EAST:
rh.setBounds( 11, 6, 6, 16 - len, 10, 10 );
break;
case NORTH:
rh.setBounds( 6, 6, len, 10, 10, 5 );
break;
case SOUTH:
rh.setBounds( 6, 6, 11, 10, 10, 16 - len );
break;
case UP:
rh.setBounds( 6, 11, 6, 10, 16 - len, 10 );
break;
case WEST:
rh.setBounds( len, 6, 6, 5, 10, 10 );
break;
default:
continue;
2014-09-24 02:26:27 +02:00
}
2015-06-16 02:44:59 +02:00
rh.renderBlock( pos, renderer );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.setSmartConnectionRotations( of, renderer );
final IAESprite firstIcon = new TaughtIcon( this.getChannelTex( this.getChannelsOnSide( of.ordinal() ), false ).getIcon(), -0.2f );
final IAESprite secondIcon = new TaughtIcon( this.getChannelTex( this.getChannelsOnSide( of.ordinal() ), true ).getIcon(), -0.2f );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
if( of == AEPartLocation.EAST || of == AEPartLocation.WEST )
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:24:40 +02:00
final AEBaseBlock blk = (AEBaseBlock) rh.getBlock();
final FlippableIcon ico = blk.getRendererInstance().getTexture( AEPartLocation.EAST );
2014-09-24 02:26:27 +02:00
ico.setFlip( false, true );
}
2015-06-16 02:44:59 +02:00
renderer.setBrightness( 15 << 20 | 15 << 4 );
renderer.setColorOpaque_I( this.getCableColor().blackVariant );
rh.setTexture( firstIcon, firstIcon, firstIcon, firstIcon, firstIcon, firstIcon );
2015-06-16 02:44:59 +02:00
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), pos, rh, renderer );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( this.getCableColor().whiteVariant );
rh.setTexture( secondIcon, secondIcon, secondIcon, secondIcon, secondIcon, secondIcon );
2015-06-16 02:44:59 +02:00
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), pos, rh, renderer );
2014-09-24 02:26:27 +02:00
renderer.setUvRotateBottom( renderer.setUvRotateEast( renderer.setUvRotateNorth( renderer.setUvRotateSouth( renderer.setUvRotateTop( renderer.setUvRotateWest( 0 ) ) ) ) ) );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
rh.setTexture( this.getTexture( this.getCableColor(), renderer ) );
2014-09-24 02:26:27 +02:00
}
}
}
if( sides.size() != 2 || !this.nonLinear( sides ) || hasBuses )
2014-09-24 02:26:27 +02:00
{
for( final AEPartLocation of : this.getConnections() )
2014-09-24 02:26:27 +02:00
{
this.renderSmartConnection( pos, rh, renderer, this.getChannelsOnSide( of.ordinal() ), of );
2014-09-24 02:26:27 +02:00
}
2015-06-16 02:44:59 +02:00
rh.setTexture( this.getCoveredTexture( this.getCableColor(), renderer ) );
2014-09-24 02:26:27 +02:00
rh.setBounds( 5, 5, 5, 11, 11, 11 );
2015-06-16 02:44:59 +02:00
rh.renderBlock( pos, renderer );
2014-09-24 02:26:27 +02:00
}
else
{
2015-06-16 02:44:59 +02:00
AEPartLocation selectedSide = AEPartLocation.INTERNAL;
2014-09-24 02:26:27 +02:00
for( final AEPartLocation of : this.getConnections() )
2014-09-24 02:26:27 +02:00
{
selectedSide = of;
break;
}
final int channels = this.getChannelsOnSide( selectedSide.ordinal() );
2015-09-30 14:24:40 +02:00
final IAESprite def = this.getTexture( this.getCableColor(), renderer );
final IAESprite off = new OffsetIcon( def, 0, -12 );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
final IAESprite firstTaughtIcon = new TaughtIcon( this.getChannelTex( channels, false ).getIcon(), -0.2f );
final IAESprite firstOffsetIcon = new OffsetIcon( firstTaughtIcon, 0, -12 );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
final IAESprite secondTaughtIcon = new TaughtIcon( this.getChannelTex( channels, true ).getIcon(), -0.2f );
final IAESprite secondOffsetIcon = new OffsetIcon( secondTaughtIcon, 0, -12 );
2014-09-24 02:26:27 +02:00
switch( selectedSide )
2014-09-24 02:26:27 +02:00
{
case DOWN:
case UP:
renderer.setRenderBounds( 5 / 16.0, 0, 5 / 16.0, 11 / 16.0, 16 / 16.0, 11 / 16.0 );
rh.setTexture( def, def, off, off, off, off );
2015-06-16 02:44:59 +02:00
rh.renderBlockCurrentBounds( pos, renderer );
renderer.setUvRotateTop( 0 );
renderer.setUvRotateBottom( 0 );
renderer.setUvRotateSouth( 3 );
renderer.setUvRotateEast( 3 );
2015-06-16 02:44:59 +02:00
renderer.setBrightness( 15 << 20 | 15 << 4 );
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( this.getCableColor().blackVariant );
rh.setTexture( firstTaughtIcon, firstTaughtIcon, firstOffsetIcon, firstOffsetIcon, firstOffsetIcon, firstOffsetIcon );
2015-06-16 02:44:59 +02:00
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), pos, rh, renderer );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( this.getCableColor().whiteVariant );
rh.setTexture( secondTaughtIcon, secondTaughtIcon, secondOffsetIcon, secondOffsetIcon, secondOffsetIcon, secondOffsetIcon );
2015-06-16 02:44:59 +02:00
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), pos, rh, renderer );
break;
case EAST:
case WEST:
rh.setTexture( off, off, off, off, def, def );
renderer.setUvRotateEast( 2 );
renderer.setUvRotateWest( 1 );
renderer.setUvRotateBottom( 2 );
renderer.setUvRotateTop( 1 );
renderer.setUvRotateSouth( 0 );
renderer.setUvRotateNorth( 0 );
2015-09-30 14:24:40 +02:00
final AEBaseBlock blk = (AEBaseBlock) rh.getBlock();
final FlippableIcon ico = blk.getRendererInstance().getTexture( AEPartLocation.EAST );
ico.setFlip( false, true );
renderer.setRenderBounds( 0, 5 / 16.0, 5 / 16.0, 16 / 16.0, 11 / 16.0, 11 / 16.0 );
2015-06-16 02:44:59 +02:00
rh.renderBlockCurrentBounds( pos, renderer );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
renderer.setBrightness( 15 << 20 | 15 << 4 );
2014-09-24 02:26:27 +02:00
FlippableIcon fpA = new FlippableIcon( firstTaughtIcon );
FlippableIcon fpB = new FlippableIcon( secondTaughtIcon );
2014-09-24 02:26:27 +02:00
fpA = new FlippableIcon( firstTaughtIcon );
fpB = new FlippableIcon( secondTaughtIcon );
2014-09-24 02:26:27 +02:00
fpA.setFlip( true, false );
fpB.setFlip( true, false );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( this.getCableColor().blackVariant );
rh.setTexture( firstOffsetIcon, firstOffsetIcon, firstOffsetIcon, firstOffsetIcon, firstTaughtIcon, fpA );
2015-06-16 02:44:59 +02:00
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), pos, rh, renderer );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( this.getCableColor().whiteVariant );
rh.setTexture( secondOffsetIcon, secondOffsetIcon, secondOffsetIcon, secondOffsetIcon, secondTaughtIcon, fpB );
2015-06-16 02:44:59 +02:00
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), pos, rh, renderer );
break;
case NORTH:
case SOUTH:
rh.setTexture( off, off, def, def, off, off );
renderer.setUvRotateTop( 3 );
renderer.setUvRotateBottom( 3 );
renderer.setUvRotateNorth( 1 );
renderer.setUvRotateSouth( 2 );
renderer.setUvRotateWest( 1 );
renderer.setRenderBounds( 5 / 16.0, 5 / 16.0, 0, 11 / 16.0, 11 / 16.0, 16 / 16.0 );
2015-06-16 02:44:59 +02:00
rh.renderBlockCurrentBounds( pos, renderer );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
renderer.setBrightness( 15 << 20 | 15 << 4 );
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( this.getCableColor().blackVariant );
rh.setTexture( firstOffsetIcon, firstOffsetIcon, firstTaughtIcon, firstTaughtIcon, firstOffsetIcon, firstOffsetIcon );
2015-06-16 02:44:59 +02:00
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), pos, rh, renderer );
2015-06-16 02:44:59 +02:00
renderer.setColorOpaque_I( this.getCableColor().whiteVariant );
rh.setTexture( secondOffsetIcon, secondOffsetIcon, secondTaughtIcon, secondTaughtIcon, secondOffsetIcon, secondOffsetIcon );
2015-06-16 02:44:59 +02:00
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), pos, rh, renderer );
break;
default:
break;
2014-09-24 02:26:27 +02:00
}
}
renderer.setUvRotateBottom( renderer.setUvRotateEast( renderer.setUvRotateNorth( renderer.setUvRotateSouth( renderer.setUvRotateTop( renderer.setUvRotateWest( 0 ) ) ) ) ) );
2014-09-24 02:26:27 +02:00
rh.setTexture( null );
}
}