Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,12 +18,14 @@
|
||||
|
||||
package appeng.parts;
|
||||
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import appeng.api.implementations.parts.IPartCable;
|
||||
import appeng.api.parts.IFacadePart;
|
||||
import appeng.api.parts.IPart;
|
||||
|
||||
|
||||
/**
|
||||
* Thin data storage to optimize memory usage for cables.
|
||||
*/
|
||||
@@ -39,47 +41,81 @@ public class CableBusStorage
|
||||
return this.center;
|
||||
}
|
||||
|
||||
protected void setCenter(IPartCable center)
|
||||
protected void setCenter( IPartCable center )
|
||||
{
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
protected IPart getSide(ForgeDirection side)
|
||||
protected IPart getSide( ForgeDirection side )
|
||||
{
|
||||
int x = side.ordinal();
|
||||
if ( this.sides != null && this.sides.length > x )
|
||||
if( this.sides != null && this.sides.length > x )
|
||||
return this.sides[x];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setSide(ForgeDirection side, IPart part)
|
||||
protected void setSide( ForgeDirection side, IPart part )
|
||||
{
|
||||
int x = side.ordinal();
|
||||
|
||||
if ( this.sides != null && this.sides.length > x && part == null )
|
||||
if( this.sides != null && this.sides.length > x && part == null )
|
||||
{
|
||||
this.sides[x] = null;
|
||||
this.sides = this.shrink( this.sides, true );
|
||||
}
|
||||
else if ( part != null )
|
||||
else if( part != null )
|
||||
{
|
||||
this.sides = this.grow( this.sides, x, true );
|
||||
this.sides[x] = part;
|
||||
}
|
||||
}
|
||||
|
||||
public IFacadePart getFacade(int x)
|
||||
private <T> T[] shrink( T[] in, boolean parts )
|
||||
{
|
||||
if ( this.facades != null && this.facades.length > x )
|
||||
int newSize = -1;
|
||||
for( int x = 0; x < in.length; x++ )
|
||||
if( in[x] != null )
|
||||
newSize = x;
|
||||
|
||||
if( newSize == -1 )
|
||||
return null;
|
||||
|
||||
newSize++;
|
||||
if( newSize == in.length )
|
||||
return in;
|
||||
|
||||
T[] newArray = (T[]) ( parts ? new IPart[newSize] : new IFacadePart[newSize] );
|
||||
System.arraycopy( in, 0, newArray, 0, newSize );
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
private <T> T[] grow( T[] in, int new_value, boolean parts )
|
||||
{
|
||||
if( in != null && in.length > new_value )
|
||||
return in;
|
||||
|
||||
int newSize = new_value + 1;
|
||||
|
||||
T[] newArray = (T[]) ( parts ? new IPart[newSize] : new IFacadePart[newSize] );
|
||||
if( in != null )
|
||||
System.arraycopy( in, 0, newArray, 0, in.length );
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
public IFacadePart getFacade( int x )
|
||||
{
|
||||
if( this.facades != null && this.facades.length > x )
|
||||
return this.facades[x];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFacade(int x, IFacadePart facade)
|
||||
public void setFacade( int x, IFacadePart facade )
|
||||
{
|
||||
if ( this.facades != null && this.facades.length > x && facade == null )
|
||||
if( this.facades != null && this.facades.length > x && facade == null )
|
||||
{
|
||||
this.facades[x] = null;
|
||||
this.facades = this.shrink( this.facades, false );
|
||||
@@ -90,38 +126,4 @@ public class CableBusStorage
|
||||
this.facades[x] = facade;
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T[] grow(T[] in, int new_value, boolean parts)
|
||||
{
|
||||
if ( in != null && in.length > new_value )
|
||||
return in;
|
||||
|
||||
int newSize = new_value + 1;
|
||||
|
||||
T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]);
|
||||
if ( in != null )
|
||||
System.arraycopy( in, 0, newArray, 0, in.length );
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
private <T> T[] shrink(T[] in, boolean parts)
|
||||
{
|
||||
int newSize = -1;
|
||||
for (int x = 0; x < in.length; x++)
|
||||
if ( in[x] != null )
|
||||
newSize = x;
|
||||
|
||||
if ( newSize == -1 )
|
||||
return null;
|
||||
|
||||
newSize++;
|
||||
if ( newSize == in.length )
|
||||
return in;
|
||||
|
||||
T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]);
|
||||
System.arraycopy( in, 0, newArray, 0, newSize );
|
||||
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user