Merge pull request #855 from yueh/fix-cable-renderer
Fixes cable render crash and covered cables render as smart.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package appeng.parts.networking;
|
package appeng.parts.networking;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ import appeng.me.helpers.AENetworkProxy;
|
|||||||
import appeng.parts.AEBasePart;
|
import appeng.parts.AEBasePart;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
|
||||||
|
|
||||||
public class PartCable extends AEBasePart implements IPartCable
|
public class PartCable extends AEBasePart implements IPartCable
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -70,7 +72,8 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
EnumSet<ForgeDirection> connections = EnumSet.noneOf( ForgeDirection.class );
|
EnumSet<ForgeDirection> connections = EnumSet.noneOf( ForgeDirection.class );
|
||||||
boolean powered = false;
|
boolean powered = false;
|
||||||
|
|
||||||
public PartCable(Class c, ItemStack is) {
|
public PartCable( Class c, ItemStack is )
|
||||||
|
{
|
||||||
super( c, is );
|
super( c, is );
|
||||||
this.proxy.setFlags( GridFlags.PREFERRED );
|
this.proxy.setFlags( GridFlags.PREFERRED );
|
||||||
this.proxy.setIdlePowerUsage( 0.0 );
|
this.proxy.setIdlePowerUsage( 0.0 );
|
||||||
@@ -256,7 +259,9 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
if ( node != null )
|
if ( node != null )
|
||||||
{
|
{
|
||||||
for ( IGridConnection gc : node.getConnections() )
|
for ( IGridConnection gc : node.getConnections() )
|
||||||
|
{
|
||||||
howMany = Math.max( gc.getUsedChannels(), howMany );
|
howMany = Math.max( gc.getUsedChannels(), howMany );
|
||||||
|
}
|
||||||
|
|
||||||
data.setByte( "usedChannels", ( byte ) howMany );
|
data.setByte( "usedChannels", ( byte ) howMany );
|
||||||
}
|
}
|
||||||
@@ -284,13 +289,17 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
for ( IGridConnection gc : set )
|
for ( IGridConnection gc : set )
|
||||||
{
|
{
|
||||||
if ( this.proxy.getNode().hasFlag( GridFlags.DENSE_CAPACITY ) && gc.getOtherSide( this.proxy.getNode() ).hasFlag( GridFlags.DENSE_CAPACITY ) )
|
if ( this.proxy.getNode().hasFlag( GridFlags.DENSE_CAPACITY ) && gc.getOtherSide( this.proxy.getNode() ).hasFlag( GridFlags.DENSE_CAPACITY ) )
|
||||||
|
{
|
||||||
sideOut |= ( gc.getUsedChannels() / 4 ) << ( 4 * thisSide.ordinal() );
|
sideOut |= ( gc.getUsedChannels() / 4 ) << ( 4 * thisSide.ordinal() );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
sideOut |= ( gc.getUsedChannels() ) << ( 4 * thisSide.ordinal() );
|
sideOut |= ( gc.getUsedChannels() ) << ( 4 * thisSide.ordinal() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for ( IGridConnection gc : n.getConnections() )
|
for ( IGridConnection gc : n.getConnections() )
|
||||||
{
|
{
|
||||||
@@ -301,9 +310,13 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
boolean isTier2b = gc.getOtherSide( this.proxy.getNode() ).hasFlag( GridFlags.DENSE_CAPACITY );
|
boolean isTier2b = gc.getOtherSide( this.proxy.getNode() ).hasFlag( GridFlags.DENSE_CAPACITY );
|
||||||
|
|
||||||
if ( isTier2a && isTier2b )
|
if ( isTier2a && isTier2b )
|
||||||
|
{
|
||||||
sideOut |= ( gc.getUsedChannels() / 4 ) << ( 4 * side.ordinal() );
|
sideOut |= ( gc.getUsedChannels() / 4 ) << ( 4 * side.ordinal() );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
sideOut |= gc.getUsedChannels() << ( 4 * side.ordinal() );
|
sideOut |= gc.getUsedChannels() << ( 4 * side.ordinal() );
|
||||||
|
}
|
||||||
cs |= ( 1 << side.ordinal() );
|
cs |= ( 1 << side.ordinal() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,8 +325,10 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if ( this.proxy.getEnergy().isNetworkPowered() )
|
if ( this.proxy.getEnergy().isNetworkPowered() )
|
||||||
|
{
|
||||||
cs |= ( 1 << ForgeDirection.UNKNOWN.ordinal() );
|
cs |= ( 1 << ForgeDirection.UNKNOWN.ordinal() );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch ( GridAccessException e )
|
catch ( GridAccessException e )
|
||||||
{
|
{
|
||||||
// aww...
|
// aww...
|
||||||
@@ -350,17 +365,23 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
{
|
{
|
||||||
int id = 1 << d.ordinal();
|
int id = 1 << d.ordinal();
|
||||||
if ( id == ( cs & id ) )
|
if ( id == ( cs & id ) )
|
||||||
|
{
|
||||||
this.powered = true;
|
this.powered = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int id = 1 << d.ordinal();
|
int id = 1 << d.ordinal();
|
||||||
if ( id == ( cs & id ) )
|
if ( id == ( cs & id ) )
|
||||||
|
{
|
||||||
this.connections.add( d );
|
this.connections.add( d );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
this.connections.remove( d );
|
this.connections.remove( d );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return !myC.equals( this.connections ) || wasPowered != this.powered || channelsChanged;
|
return !myC.equals( this.connections ) || wasPowered != this.powered || channelsChanged;
|
||||||
}
|
}
|
||||||
@@ -374,10 +395,14 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
{
|
{
|
||||||
IGridNode n = this.getGridNode();
|
IGridNode n = this.getGridNode();
|
||||||
if ( n != null )
|
if ( n != null )
|
||||||
|
{
|
||||||
this.connections = n.getConnectedSides();
|
this.connections = n.getConnectedSides();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
this.connections.clear();
|
this.connections.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IPartHost ph = this.getHost();
|
IPartHost ph = this.getHost();
|
||||||
if ( ph != null )
|
if ( ph != null )
|
||||||
@@ -390,7 +415,9 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
double dist = p.cableConnectionRenderTo();
|
double dist = p.cableConnectionRenderTo();
|
||||||
|
|
||||||
if ( dist > 8 )
|
if ( dist > 8 )
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch ( dir )
|
switch ( dir )
|
||||||
{
|
{
|
||||||
@@ -473,10 +500,12 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
|
|
||||||
rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) );
|
rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) );
|
||||||
|
|
||||||
if ( gh != null && partHost != null && gh.getCableConnectionType( of ) == AECableType.GLASS && partHost.getColor() != AEColor.Transparent
|
if ( gh != null && partHost != null && gh.getCableConnectionType( of.getOpposite() ) == AECableType.GLASS && partHost.getColor() != AEColor.Transparent
|
||||||
&& partHost.getPart( of.getOpposite() ) == null )
|
&& partHost.getPart( of.getOpposite() ) == null )
|
||||||
|
{
|
||||||
rh.setTexture( this.getTexture( partHost.getColor() ) );
|
rh.setTexture( this.getTexture( partHost.getColor() ) );
|
||||||
else if ( partHost == null && gh != null && gh.getCableConnectionType( of ) != AECableType.GLASS )
|
}
|
||||||
|
else if ( partHost == null && gh != null && gh.getCableConnectionType( of.getOpposite() ) != AECableType.GLASS )
|
||||||
{
|
{
|
||||||
rh.setTexture( this.getCoveredTexture( this.getCableColor() ) );
|
rh.setTexture( this.getCoveredTexture( this.getCableColor() ) );
|
||||||
switch ( of )
|
switch ( of )
|
||||||
@@ -507,7 +536,9 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
rh.setTexture( this.getTexture( this.getCableColor() ) );
|
rh.setTexture( this.getTexture( this.getCableColor() ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
rh.setTexture( this.getTexture( this.getCableColor() ) );
|
rh.setTexture( this.getTexture( this.getCableColor() ) );
|
||||||
|
}
|
||||||
|
|
||||||
switch ( of )
|
switch ( of )
|
||||||
{
|
{
|
||||||
@@ -540,7 +571,9 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
protected CableBusTextures getChannelTex( int i, boolean b )
|
protected CableBusTextures getChannelTex( int i, boolean b )
|
||||||
{
|
{
|
||||||
if ( !this.powered )
|
if ( !this.powered )
|
||||||
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ( b )
|
if ( b )
|
||||||
{
|
{
|
||||||
@@ -582,13 +615,14 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ );
|
TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ );
|
||||||
IPartHost partHost = te instanceof IPartHost ? ( IPartHost ) te : null;
|
IPartHost partHost = te instanceof IPartHost ? ( IPartHost ) te : null;
|
||||||
IGridHost ghh = te instanceof IGridHost ? ( IGridHost ) te : null;
|
IGridHost ghh = te instanceof IGridHost ? ( IGridHost ) te : null;
|
||||||
boolean isSmart = false;
|
|
||||||
|
|
||||||
rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) );
|
rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) );
|
||||||
if ( ghh != null && partHost != null && ghh.getCableConnectionType( of.getOpposite() ) == AECableType.GLASS && partHost.getPart( of.getOpposite() ) == null
|
if ( ghh != null && partHost != null && ghh.getCableConnectionType( of.getOpposite() ) == AECableType.GLASS && partHost.getPart( of.getOpposite() ) == null
|
||||||
&& partHost.getColor() != AEColor.Transparent )
|
&& partHost.getColor() != AEColor.Transparent )
|
||||||
|
{
|
||||||
rh.setTexture( this.getGlassTexture( partHost.getColor() ) );
|
rh.setTexture( this.getGlassTexture( partHost.getColor() ) );
|
||||||
else if ( partHost == null && ghh != null && ghh.getCableConnectionType( of ) != AECableType.GLASS )
|
}
|
||||||
|
else if ( partHost == null && ghh != null && ghh.getCableConnectionType( of.getOpposite() ) != AECableType.GLASS )
|
||||||
{
|
{
|
||||||
rh.setTexture( this.getCoveredTexture( this.getCableColor() ) );
|
rh.setTexture( this.getCoveredTexture( this.getCableColor() ) );
|
||||||
switch ( of )
|
switch ( of )
|
||||||
@@ -619,16 +653,15 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
|
|
||||||
rh.setTexture( this.getTexture( this.getCableColor() ) );
|
rh.setTexture( this.getTexture( this.getCableColor() ) );
|
||||||
}
|
}
|
||||||
else if ( ghh != null && partHost != null && ghh.getCableConnectionType( of ) == AECableType.COVERED && partHost.getColor() != AEColor.Transparent
|
else if ( ghh != null && partHost != null && ghh.getCableConnectionType( of.getOpposite() ) == AECableType.COVERED && partHost.getColor() != AEColor.Transparent
|
||||||
&& partHost.getPart( of.getOpposite() ) == null )
|
&& partHost.getPart( of.getOpposite() ) == null )
|
||||||
rh.setTexture( this.getCoveredTexture( partHost.getColor() ) );
|
|
||||||
else if ( ghh != null && partHost != null && ghh.getCableConnectionType( of ) == AECableType.SMART && partHost.getPart( of.getOpposite() ) == null )
|
|
||||||
{
|
{
|
||||||
isSmart = true;
|
rh.setTexture( this.getCoveredTexture( partHost.getColor() ) );
|
||||||
rh.setTexture( this.getSmartTexture( this.getCableColor() ) );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
rh.setTexture( this.getCoveredTexture( this.getCableColor() ) );
|
rh.setTexture( this.getCoveredTexture( this.getCableColor() ) );
|
||||||
|
}
|
||||||
|
|
||||||
switch ( of )
|
switch ( of )
|
||||||
{
|
{
|
||||||
@@ -656,32 +689,6 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
|
|
||||||
rh.renderBlock( x, y, z, renderer );
|
rh.renderBlock( x, y, z, renderer );
|
||||||
rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) );
|
rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) );
|
||||||
|
|
||||||
if ( isSmart )
|
|
||||||
{
|
|
||||||
this.setSmartConnectionRotations( of, renderer );
|
|
||||||
IIcon firstIcon = new TaughtIcon( this.getChannelTex( channels, false ).getIcon(), -0.2f );
|
|
||||||
IIcon secondIcon = new TaughtIcon( this.getChannelTex( channels, true ).getIcon(), -0.2f );
|
|
||||||
|
|
||||||
if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST )
|
|
||||||
{
|
|
||||||
AEBaseBlock blk = (AEBaseBlock) rh.getBlock();
|
|
||||||
FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST );
|
|
||||||
ico.setFlip( false, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 );
|
|
||||||
Tessellator.instance.setColorOpaque_I( this.getCableColor().blackVariant );
|
|
||||||
rh.setTexture( firstIcon, firstIcon, firstIcon, firstIcon, firstIcon, firstIcon );
|
|
||||||
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
|
||||||
|
|
||||||
Tessellator.instance.setColorOpaque_I( this.getCableColor().whiteVariant );
|
|
||||||
rh.setTexture( secondIcon, secondIcon, secondIcon, secondIcon, secondIcon, secondIcon );
|
|
||||||
this.renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
|
||||||
|
|
||||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) );
|
rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -755,11 +762,15 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
rh.setTexture( this.getTexture( this.getCableColor() ) );
|
rh.setTexture( this.getTexture( this.getCableColor() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ( ghh != null && partHost != null && ghh.getCableConnectionType( of ) != AECableType.GLASS && partHost.getColor() != AEColor.Transparent
|
else if ( ghh != null && partHost != null && ghh.getCableConnectionType( of.getOpposite() ) != AECableType.GLASS && partHost.getColor() != AEColor.Transparent
|
||||||
&& partHost.getPart( of.getOpposite() ) == null )
|
&& partHost.getPart( of.getOpposite() ) == null )
|
||||||
|
{
|
||||||
rh.setTexture( this.getSmartTexture( myColor = partHost.getColor() ) );
|
rh.setTexture( this.getSmartTexture( myColor = partHost.getColor() ) );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
rh.setTexture( this.getSmartTexture( this.getCableColor() ) );
|
rh.setTexture( this.getSmartTexture( this.getCableColor() ) );
|
||||||
|
}
|
||||||
|
|
||||||
switch ( of )
|
switch ( of )
|
||||||
{
|
{
|
||||||
@@ -885,9 +896,11 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
IPartHost partHost = te instanceof IPartHost ? ( IPartHost ) te : null;
|
IPartHost partHost = te instanceof IPartHost ? ( IPartHost ) te : null;
|
||||||
IGridHost gh = te instanceof IGridHost ? ( IGridHost ) te : null;
|
IGridHost gh = te instanceof IGridHost ? ( IGridHost ) te : null;
|
||||||
if ( partHost == null && gh != null && gh.getCableConnectionType( dir ) != AECableType.GLASS )
|
if ( partHost == null && gh != null && gh.getCableConnectionType( dir ) != AECableType.GLASS )
|
||||||
|
{
|
||||||
requireDetailed = true;
|
requireDetailed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( useCovered )
|
if ( useCovered )
|
||||||
{
|
{
|
||||||
@@ -997,13 +1010,21 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
ItemStack newPart = null;
|
ItemStack newPart = null;
|
||||||
|
|
||||||
if ( this.getCableConnectionType() == AECableType.GLASS )
|
if ( this.getCableConnectionType() == AECableType.GLASS )
|
||||||
|
{
|
||||||
newPart = AEApi.instance().parts().partCableGlass.stack( newColor, 1 );
|
newPart = AEApi.instance().parts().partCableGlass.stack( newColor, 1 );
|
||||||
|
}
|
||||||
else if ( this.getCableConnectionType() == AECableType.COVERED )
|
else if ( this.getCableConnectionType() == AECableType.COVERED )
|
||||||
|
{
|
||||||
newPart = AEApi.instance().parts().partCableCovered.stack( newColor, 1 );
|
newPart = AEApi.instance().parts().partCableCovered.stack( newColor, 1 );
|
||||||
|
}
|
||||||
else if ( this.getCableConnectionType() == AECableType.SMART )
|
else if ( this.getCableConnectionType() == AECableType.SMART )
|
||||||
|
{
|
||||||
newPart = AEApi.instance().parts().partCableSmart.stack( newColor, 1 );
|
newPart = AEApi.instance().parts().partCableSmart.stack( newColor, 1 );
|
||||||
|
}
|
||||||
else if ( this.getCableConnectionType() == AECableType.DENSE )
|
else if ( this.getCableConnectionType() == AECableType.DENSE )
|
||||||
|
{
|
||||||
newPart = AEApi.instance().parts().partCableDense.stack( newColor, 1 );
|
newPart = AEApi.instance().parts().partCableDense.stack( newColor, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasPermission = true;
|
boolean hasPermission = true;
|
||||||
|
|
||||||
@@ -1019,7 +1040,9 @@ public class PartCable extends AEBasePart implements IPartCable
|
|||||||
if ( newPart != null && hasPermission )
|
if ( newPart != null && hasPermission )
|
||||||
{
|
{
|
||||||
if ( Platform.isClient() )
|
if ( Platform.isClient() )
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
this.getHost().removePart( ForgeDirection.UNKNOWN, true );
|
this.getHost().removePart( ForgeDirection.UNKNOWN, true );
|
||||||
this.getHost().addPart( newPart, ForgeDirection.UNKNOWN, who );
|
this.getHost().addPart( newPart, ForgeDirection.UNKNOWN, who );
|
||||||
|
|||||||
Reference in New Issue
Block a user