Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
+188 -186
View File
@@ -18,6 +18,7 @@
package appeng.util.item;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
@@ -38,6 +39,7 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAETagCompound;
import appeng.util.Platform;
public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFluidStack, Comparable<AEFluidStack>
{
@@ -45,33 +47,8 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
Fluid fluid;
private IAETagCompound tagCompound;
@Override
public String toString()
private AEFluidStack( AEFluidStack is )
{
return this.getFluidStack().toString();
}
@Override
public IAETagCompound getTagCompound()
{
return this.tagCompound;
}
@Override
public void add(IAEFluidStack option)
{
if ( option == null )
return;
// if ( priority < ((AEFluidStack) option).priority )
// priority = ((AEFluidStack) option).priority;
this.incStackSize( option.getStackSize() );
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
this.setCraftable( this.isCraftable() || option.isCraftable() );
}
private AEFluidStack(AEFluidStack is) {
this.fluid = is.fluid;
this.stackSize = is.stackSize;
@@ -83,85 +60,109 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
this.myHash = is.myHash;
}
private AEFluidStack( FluidStack is ) {
if ( is == null )
private AEFluidStack( FluidStack is )
{
if( is == null )
throw new RuntimeException( "Invalid Itemstack." );
this.fluid = is.getFluid();
if ( this.fluid == null )
if( this.fluid == null )
throw new RuntimeException( "Fluid is null." );
this.stackSize = is.amount;
this.setCraftable( false );
this.setCountRequestable( 0 );
this.myHash = this.fluid.hashCode() ^ (this.tagCompound == null ? 0 : System.identityHashCode( this.tagCompound ));
this.myHash = this.fluid.hashCode() ^ ( this.tagCompound == null ? 0 : System.identityHashCode( this.tagCompound ) );
}
public static AEFluidStack create(Object a)
public static IAEFluidStack loadFluidStackFromNBT( NBTTagCompound i )
{
if ( a == null )
ItemStack itemstack = ItemStack.loadItemStackFromNBT( i );
if( itemstack == null )
return null;
if ( a instanceof AEFluidStack )
((AEFluidStack) a).copy();
if ( a instanceof FluidStack )
AEFluidStack fluid = AEFluidStack.create( itemstack );
// fluid.priority = i.getInteger( "Priority" );
fluid.stackSize = i.getLong( "Cnt" );
fluid.setCountRequestable( i.getLong( "Req" ) );
fluid.setCraftable( i.getBoolean( "Craft" ) );
return fluid;
}
public static AEFluidStack create( Object a )
{
if( a == null )
return null;
if( a instanceof AEFluidStack )
( (AEFluidStack) a ).copy();
if( a instanceof FluidStack )
return new AEFluidStack( (FluidStack) a );
return null;
}
@Override
public boolean equals(Object ia)
public static IAEFluidStack loadFluidStackFromPacket( ByteBuf data ) throws IOException
{
if ( ia instanceof AEFluidStack )
byte mask = data.readByte();
// byte PriorityType = (byte) (mask & 0x03);
byte StackType = (byte) ( ( mask & 0x0C ) >> 2 );
byte CountReqType = (byte) ( ( mask & 0x30 ) >> 4 );
boolean isCraftable = ( mask & 0x40 ) > 0;
boolean hasTagCompound = ( mask & 0x80 ) > 0;
// don't send this...
NBTTagCompound d = new NBTTagCompound();
byte len2 = data.readByte();
byte[] name = new byte[len2];
data.readBytes( name, 0, len2 );
d.setString( "FluidName", new String( name, "UTF-8" ) );
d.setByte( "Count", (byte) 0 );
if( hasTagCompound )
{
return ((AEFluidStack) ia).fluid == this.fluid && this.tagCompound == ((AEFluidStack) ia).tagCompound;
int len = data.readInt();
byte[] bd = new byte[len];
data.readBytes( bd );
DataInputStream di = new DataInputStream( new ByteArrayInputStream( bd ) );
d.setTag( "tag", CompressedStreamTools.read( di ) );
}
else if ( ia instanceof FluidStack )
{
FluidStack is = (FluidStack) ia;
if ( is.fluidID == this.fluid.getID() )
{
NBTTagCompound ta = (NBTTagCompound) this.tagCompound;
NBTTagCompound tb = is.tag;
if ( ta == tb )
return true;
// long priority = getPacketValue( PriorityType, data );
long stackSize = getPacketValue( StackType, data );
long countRequestable = getPacketValue( CountReqType, data );
if ( (ta == null && tb == null) || (ta != null && ta.hasNoTags() && tb == null) || (tb != null && tb.hasNoTags() && ta == null)
|| (ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags()) )
return true;
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( d );
if( fluidStack == null )
return null;
if ( (ta == null && tb != null) || (ta != null && tb == null) )
return false;
if ( AESharedNBT.isShared( tb ) )
return ta == tb;
return Platform.NBTEqualityTest( ta, tb );
}
}
return false;
AEFluidStack fluid = AEFluidStack.create( fluidStack );
// fluid.priority = (int) priority;
fluid.stackSize = stackSize;
fluid.setCountRequestable( countRequestable );
fluid.setCraftable( isCraftable );
return fluid;
}
@Override
public FluidStack getFluidStack()
public void add( IAEFluidStack option )
{
FluidStack is = new FluidStack( this.fluid, (int) Math.min( Integer.MAX_VALUE, this.stackSize ) );
if ( this.tagCompound != null )
is.tag = this.tagCompound.getNBTTagCompoundCopy();
if( option == null )
return;
return is;
// if ( priority < ((AEFluidStack) option).priority )
// priority = ((AEFluidStack) option).priority;
this.incStackSize( option.getStackSize() );
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
this.setCraftable( this.isCraftable() || option.isCraftable() );
}
@Override
public IAEFluidStack copy()
{
return new AEFluidStack( this );
}
@Override
public void writeToNBT(NBTTagCompound i)
public void writeToNBT( NBTTagCompound i )
{
/*
* Mojang Fucked this over ; GC Optimization - Ugly Yes, but it saves a lot in the memory department.
@@ -196,123 +197,35 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
/*
* if ( Craft != null && Craft instanceof NBTTagByte ) ((NBTTagByte) Craft).data = (byte) (this.isCraftable() ?
* 1 : 0); else
*/i.setBoolean( "Craft", this.isCraftable() );
*/
i.setBoolean( "Craft", this.isCraftable() );
if ( this.tagCompound != null )
if( this.tagCompound != null )
i.setTag( "tag", (NBTTagCompound) this.tagCompound );
else
i.removeTag( "tag" );
}
public static IAEFluidStack loadFluidStackFromNBT(NBTTagCompound i)
{
ItemStack itemstack = ItemStack.loadItemStackFromNBT( i );
if ( itemstack == null )
return null;
AEFluidStack fluid = AEFluidStack.create( itemstack );
// fluid.priority = i.getInteger( "Priority" );
fluid.stackSize = i.getLong( "Cnt" );
fluid.setCountRequestable( i.getLong( "Req" ) );
fluid.setCraftable( i.getBoolean( "Craft" ) );
return fluid;
}
@Override
public boolean hasTagCompound()
public boolean fuzzyComparison( Object st, FuzzyMode mode )
{
return this.tagCompound != null;
}
@Override
public int hashCode()
{
return this.myHash;
}
@Override
public int compareTo(AEFluidStack b)
{
int diff = this.hashCode() - b.hashCode();
return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
}
@Override
void writeIdentity(ByteBuf i) throws IOException
{
byte[] name = this.fluid.getName().getBytes( "UTF-8" );
i.writeByte( (byte) name.length );
i.writeBytes( name );
}
@Override
void readNBT(ByteBuf i) throws IOException
{
if ( this.hasTagCompound() )
if( st instanceof FluidStack )
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
CompressedStreamTools.write( (NBTTagCompound) this.tagCompound, data );
byte[] tagBytes = bytes.toByteArray();
int size = tagBytes.length;
i.writeInt( size );
i.writeBytes( tagBytes );
}
}
public static IAEFluidStack loadFluidStackFromPacket(ByteBuf data) throws IOException
{
byte mask = data.readByte();
// byte PriorityType = (byte) (mask & 0x03);
byte StackType = (byte) ((mask & 0x0C) >> 2);
byte CountReqType = (byte) ((mask & 0x30) >> 4);
boolean isCraftable = (mask & 0x40) > 0;
boolean hasTagCompound = (mask & 0x80) > 0;
// don't send this...
NBTTagCompound d = new NBTTagCompound();
byte len2 = data.readByte();
byte[] name = new byte[len2];
data.readBytes( name, 0, len2 );
d.setString( "FluidName", new String( name, "UTF-8" ) );
d.setByte( "Count", (byte) 0 );
if ( hasTagCompound )
{
int len = data.readInt();
byte[] bd = new byte[len];
data.readBytes( bd );
DataInputStream di = new DataInputStream( new ByteArrayInputStream( bd ) );
d.setTag( "tag", CompressedStreamTools.read( di ) );
return ( (FluidStack) st ).getFluid() == this.fluid;
}
// long priority = getPacketValue( PriorityType, data );
long stackSize = getPacketValue( StackType, data );
long countRequestable = getPacketValue( CountReqType, data );
if( st instanceof IAEFluidStack )
{
return ( (IAEFluidStack) st ).getFluid() == this.fluid;
}
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( d );
if ( fluidStack == null )
return null;
AEFluidStack fluid = AEFluidStack.create( fluidStack );
// fluid.priority = (int) priority;
fluid.stackSize = stackSize;
fluid.setCountRequestable( countRequestable );
fluid.setCraftable( isCraftable );
return fluid;
return false;
}
@Override
public Fluid getFluid()
public IAEFluidStack copy()
{
return this.fluid;
return new AEFluidStack( this );
}
@Override
@@ -324,19 +237,9 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
}
@Override
public boolean fuzzyComparison(Object st, FuzzyMode mode)
public IAETagCompound getTagCompound()
{
if ( st instanceof FluidStack )
{
return ((FluidStack) st).getFluid() == this.fluid;
}
if ( st instanceof IAEFluidStack )
{
return ((IAEFluidStack) st).getFluid() == this.fluid;
}
return false;
return this.tagCompound;
}
@Override
@@ -357,4 +260,103 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
return StorageChannel.FLUIDS;
}
@Override
public int compareTo( AEFluidStack b )
{
int diff = this.hashCode() - b.hashCode();
return diff > 0 ? 1 : ( diff < 0 ? -1 : 0 );
}
@Override
public int hashCode()
{
return this.myHash;
}
@Override
public boolean equals( Object ia )
{
if( ia instanceof AEFluidStack )
{
return ( (AEFluidStack) ia ).fluid == this.fluid && this.tagCompound == ( (AEFluidStack) ia ).tagCompound;
}
else if( ia instanceof FluidStack )
{
FluidStack is = (FluidStack) ia;
if( is.fluidID == this.fluid.getID() )
{
NBTTagCompound ta = (NBTTagCompound) this.tagCompound;
NBTTagCompound tb = is.tag;
if( ta == tb )
return true;
if( ( ta == null && tb == null ) || ( ta != null && ta.hasNoTags() && tb == null ) || ( tb != null && tb.hasNoTags() && ta == null ) || ( ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags() ) )
return true;
if( ( ta == null && tb != null ) || ( ta != null && tb == null ) )
return false;
if( AESharedNBT.isShared( tb ) )
return ta == tb;
return Platform.NBTEqualityTest( ta, tb );
}
}
return false;
}
@Override
public String toString()
{
return this.getFluidStack().toString();
} @Override
public boolean hasTagCompound()
{
return this.tagCompound != null;
}
@Override
public FluidStack getFluidStack()
{
FluidStack is = new FluidStack( this.fluid, (int) Math.min( Integer.MAX_VALUE, this.stackSize ) );
if( this.tagCompound != null )
is.tag = this.tagCompound.getNBTTagCompoundCopy();
return is;
}
@Override
public Fluid getFluid()
{
return this.fluid;
}
@Override
void writeIdentity( ByteBuf i ) throws IOException
{
byte[] name = this.fluid.getName().getBytes( "UTF-8" );
i.writeByte( (byte) name.length );
i.writeBytes( name );
}
@Override
void readNBT( ByteBuf i ) throws IOException
{
if( this.hasTagCompound() )
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
CompressedStreamTools.write( (NBTTagCompound) this.tagCompound, data );
byte[] tagBytes = bytes.toByteArray();
int size = tagBytes.length;
i.writeInt( size );
i.writeBytes( tagBytes );
}
}
}