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 );
}
}
}
+32 -38
View File
@@ -18,6 +18,7 @@
package appeng.util.item;
import java.util.List;
import net.minecraft.init.Items;
@@ -30,37 +31,30 @@ import cpw.mods.fml.relauncher.SideOnly;
import appeng.util.Platform;
public class AEItemDef
{
public int myHash;
public int def;
public final int itemID;
public final Item item;
public int damageValue;
public int displayDamage;
public int maxDamage;
public AESharedNBT tagCompound;
@SideOnly(Side.CLIENT)
public String displayName;
@SideOnly(Side.CLIENT)
public List tooltip;
@SideOnly(Side.CLIENT)
public UniqueIdentifier uniqueID;
public OreReference isOre;
static final AESharedNBT LOW_TAG = new AESharedNBT( Integer.MIN_VALUE );
static final AESharedNBT HIGH_TAG = new AESharedNBT( Integer.MAX_VALUE );
public final int itemID;
public final Item item;
public int myHash;
public int def;
public int damageValue;
public int displayDamage;
public int maxDamage;
public AESharedNBT tagCompound;
@SideOnly( Side.CLIENT )
public String displayName;
@SideOnly( Side.CLIENT )
public List tooltip;
@SideOnly( Side.CLIENT )
public UniqueIdentifier uniqueID;
public OreReference isOre;
public AEItemDef(Item it) {
public AEItemDef( Item it )
{
this.item = it;
this.itemID = Item.getIdFromItem( it );
}
@@ -78,32 +72,27 @@ public class AEItemDef
}
@Override
public boolean equals(Object obj)
public boolean equals( Object obj )
{
if ( obj == null )
if( obj == null )
return false;
if ( this.getClass() != obj.getClass() )
if( this.getClass() != obj.getClass() )
return false;
AEItemDef other = (AEItemDef) obj;
return other.damageValue == this.damageValue && other.item == this.item && this.tagCompound == other.tagCompound;
}
public int getDamageValueHack(ItemStack is)
{
return Items.blaze_rod.getDamage( is );
}
public boolean isItem(ItemStack otherStack)
public boolean isItem( ItemStack otherStack )
{
// hackery!
int dmg = this.getDamageValueHack( otherStack );
if ( this.item == otherStack.getItem() && dmg == this.damageValue )
if( this.item == otherStack.getItem() && dmg == this.damageValue )
{
if ( (this.tagCompound != null) == otherStack.hasTagCompound() )
if( ( this.tagCompound != null ) == otherStack.hasTagCompound() )
return true;
if ( this.tagCompound != null && otherStack.hasTagCompound() )
if( this.tagCompound != null && otherStack.hasTagCompound() )
return Platform.NBTEqualityTest( this.tagCompound, otherStack.getTagCompound() );
return true;
@@ -111,9 +100,14 @@ public class AEItemDef
return false;
}
public int getDamageValueHack( ItemStack is )
{
return Items.blaze_rod.getDamage( is );
}
public void reHash()
{
this.def = this.itemID << Platform.DEF_OFFSET | this.damageValue;
this.myHash = this.def ^ (this.tagCompound == null ? 0 : System.identityHashCode( this.tagCompound ));
this.myHash = this.def ^ ( this.tagCompound == null ? 0 : System.identityHashCode( this.tagCompound ) );
}
}
+76 -76
View File
@@ -396,51 +396,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return StorageChannel.ITEMS;
}
@Override
public int hashCode()
{
return this.def.myHash;
}
@Override
public boolean equals( Object ia )
{
if( ia instanceof AEItemStack )
{
return ( (AEItemStack) ia ).def.equals( this.def );// && def.tagCompound == ((AEItemStack) ia).def.tagCompound;
}
else if( ia instanceof ItemStack )
{
ItemStack is = (ItemStack) ia;
if( is.getItem() == this.def.item && is.getItemDamage() == this.def.damageValue )
{
NBTTagCompound ta = this.def.tagCompound;
NBTTagCompound tb = is.getTagCompound();
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.getItemStack().toString();
}
@Override
public ItemStack getItemStack()
{
@@ -487,6 +442,51 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return this.def.isItem( otherStack );
}
@Override
public int hashCode()
{
return this.def.myHash;
}
@Override
public boolean equals( Object ia )
{
if( ia instanceof AEItemStack )
{
return ( (AEItemStack) ia ).def.equals( this.def );// && def.tagCompound == ((AEItemStack) ia).def.tagCompound;
}
else if( ia instanceof ItemStack )
{
ItemStack is = (ItemStack) ia;
if( is.getItem() == this.def.item && is.getItemDamage() == this.def.damageValue )
{
NBTTagCompound ta = this.def.tagCompound;
NBTTagCompound tb = is.getTagCompound();
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.getItemStack().toString();
}
@Override
public int compareTo( AEItemStack b )
{
@@ -553,37 +553,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return uniqueIdentifier.modId == null ? "** Null" : uniqueIdentifier.modId;
}
@Override
void writeIdentity( ByteBuf i ) throws IOException
{
i.writeShort( Item.itemRegistry.getIDForObject( this.def.item ) );
i.writeShort( this.getItemDamage() );
}
@Override
void readNBT( ByteBuf i ) throws IOException
{
if( this.hasTagCompound() )
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
CompressedStreamTools.write( (NBTTagCompound) this.getTagCompound(), data );
byte[] tagBytes = bytes.toByteArray();
int size = tagBytes.length;
i.writeInt( size );
i.writeBytes( tagBytes );
}
}
@Override
public boolean hasTagCompound()
{
return this.def.tagCompound != null;
}
public IAEItemStack getLow( FuzzyMode fuzzy, boolean ignoreMeta )
{
AEItemStack bottom = new AEItemStack( this );
@@ -666,4 +635,35 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
{
return this.def.isOre != null;
}
@Override
void writeIdentity( ByteBuf i ) throws IOException
{
i.writeShort( Item.itemRegistry.getIDForObject( this.def.item ) );
i.writeShort( this.getItemDamage() );
}
@Override
void readNBT( ByteBuf i ) throws IOException
{
if( this.hasTagCompound() )
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
CompressedStreamTools.write( (NBTTagCompound) this.getTagCompound(), data );
byte[] tagBytes = bytes.toByteArray();
int size = tagBytes.length;
i.writeInt( size );
i.writeBytes( tagBytes );
}
}
@Override
public boolean hasTagCompound()
{
return this.def.tagCompound != null;
}
}
+94 -92
View File
@@ -18,6 +18,7 @@
package appeng.util.item;
import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
@@ -30,54 +31,100 @@ import appeng.api.features.IItemComparison;
import appeng.api.storage.data.IAETagCompound;
import appeng.util.Platform;
/*
* this is used for the shared NBT Cache.
*/
public class AESharedNBT extends NBTTagCompound implements IAETagCompound
{
/*
* Shared Tag Compound Cache.
*/
private static final WeakHashMap<SharedSearchObject, WeakReference<SharedSearchObject>> SHARED_TAG_COMPOUND = new WeakHashMap<SharedSearchObject, WeakReference<SharedSearchObject>>();
private final Item item;
private final int meta;
private int hash;
public SharedSearchObject sso;
private int hash;
private IItemComparison comp;
public int getHash()
private AESharedNBT( Item itemID, int damageValue )
{
return this.hash;
}
@Override
public IItemComparison getSpecialComparison()
{
return this.comp;
}
private AESharedNBT(Item itemID, int damageValue) {
super();
this.item = itemID;
this.meta = damageValue;
}
public AESharedNBT(int fakeValue) {
public AESharedNBT( int fakeValue )
{
super();
this.item = null;
this.meta = 0;
this.hash = fakeValue;
}
@Override
public NBTTagCompound getNBTTagCompoundCopy()
/*
* Debug purposes.
*/
public static int sharedTagLoad()
{
return (NBTTagCompound) this.copy();
return SHARED_TAG_COMPOUND.size();
}
public static AESharedNBT createFromCompound(Item itemID, int damageValue, NBTTagCompound c)
/*
* Returns an NBT Compound that is used for accelerating comparisons.
*/
synchronized public static NBTTagCompound getSharedTagCompound( NBTTagCompound tagCompound, ItemStack s )
{
if( tagCompound.hasNoTags() )
return null;
Item item = s.getItem();
int meta = -1;
if( s.getItem() != null && s.isItemStackDamageable() && s.getHasSubtypes() )
meta = s.getItemDamage();
if( isShared( tagCompound ) )
return tagCompound;
SharedSearchObject sso = new SharedSearchObject( item, meta, tagCompound );
WeakReference<SharedSearchObject> c = SHARED_TAG_COMPOUND.get( sso );
if( c != null )
{
SharedSearchObject cg = c.get();
if( cg != null )
return cg.shared; // I don't think I really need to check this
// as its already certain to exist..
}
AESharedNBT clone = AESharedNBT.createFromCompound( item, meta, tagCompound );
sso.compound = (NBTTagCompound) sso.compound.copy(); // prevent
// modification
// of data based
// on original
// item.
sso.shared = clone;
clone.sso = sso;
SHARED_TAG_COMPOUND.put( sso, new WeakReference<SharedSearchObject>( sso ) );
return clone;
}
/*
* returns true if the compound is part of the shared compound system ( and can thus be compared directly ).
*/
public static boolean isShared( NBTTagCompound ta )
{
return ta instanceof AESharedNBT;
}
public static AESharedNBT createFromCompound( Item itemID, int damageValue, NBTTagCompound c )
{
AESharedNBT x = new AESharedNBT( itemID, damageValue );
// c.getTags()
for (Object o : c.func_150296_c())
for( Object o : c.func_150296_c() )
{
String name = (String) o;
x.setTag( name, c.getTag( name ).copy() );
@@ -92,25 +139,42 @@ public class AESharedNBT extends NBTTagCompound implements IAETagCompound
return x;
}
@Override
public boolean equals(Object par1Obj)
public int getHash()
{
if ( par1Obj instanceof AESharedNBT )
return this.hash;
}
@Override
public NBTTagCompound getNBTTagCompoundCopy()
{
return (NBTTagCompound) this.copy();
}
@Override
public IItemComparison getSpecialComparison()
{
return this.comp;
}
@Override
public boolean equals( Object par1Obj )
{
if( par1Obj instanceof AESharedNBT )
return this == par1Obj;
return super.equals( par1Obj );
}
public boolean matches(Item item, int meta, int orderlessHash)
public boolean matches( Item item, int meta, int orderlessHash )
{
return item == this.item && this.meta == meta && this.hash == orderlessHash;
}
public boolean comparePreciseWithRegistry(AESharedNBT tagCompound)
public boolean comparePreciseWithRegistry( AESharedNBT tagCompound )
{
if ( this == tagCompound )
if( this == tagCompound )
return true;
if ( this.comp != null && tagCompound.comp != null )
if( this.comp != null && tagCompound.comp != null )
{
return this.comp.sameAsPrecise( tagCompound.comp );
}
@@ -118,83 +182,21 @@ public class AESharedNBT extends NBTTagCompound implements IAETagCompound
return false;
}
public boolean compareFuzzyWithRegistry(AESharedNBT tagCompound)
public boolean compareFuzzyWithRegistry( AESharedNBT tagCompound )
{
if ( this == tagCompound )
if( this == tagCompound )
return true;
if ( tagCompound == null )
if( tagCompound == null )
return false;
if ( this.comp == tagCompound.comp )
if( this.comp == tagCompound.comp )
return true;
if ( this.comp != null )
if( this.comp != null )
{
return this.comp.sameAsFuzzy( tagCompound.comp );
}
return false;
}
/*
* Shared Tag Compound Cache.
*/
private static final WeakHashMap<SharedSearchObject, WeakReference<SharedSearchObject>> SHARED_TAG_COMPOUND = new WeakHashMap<SharedSearchObject, WeakReference<SharedSearchObject>>();
/*
* Debug purposes.
*/
public static int sharedTagLoad()
{
return SHARED_TAG_COMPOUND.size();
}
/*
* returns true if the compound is part of the shared compound system ( and can thus be compared directly ).
*/
public static boolean isShared(NBTTagCompound ta)
{
return ta instanceof AESharedNBT;
}
/*
* Returns an NBT Compound that is used for accelerating comparisons.
*/
synchronized public static NBTTagCompound getSharedTagCompound(NBTTagCompound tagCompound, ItemStack s)
{
if ( tagCompound.hasNoTags() )
return null;
Item item = s.getItem();
int meta = -1;
if ( s.getItem() != null && s.isItemStackDamageable() && s.getHasSubtypes() )
meta = s.getItemDamage();
if ( isShared( tagCompound ) )
return tagCompound;
SharedSearchObject sso = new SharedSearchObject( item, meta, tagCompound );
WeakReference<SharedSearchObject> c = SHARED_TAG_COMPOUND.get( sso );
if ( c != null )
{
SharedSearchObject cg = c.get();
if ( cg != null )
return cg.shared; // I don't think I really need to check this
// as its already certain to exist..
}
AESharedNBT clone = AESharedNBT.createFromCompound( item, meta, tagCompound );
sso.compound = (NBTTagCompound) sso.compound.copy(); // prevent
// modification
// of data based
// on original
// item.
sso.shared = clone;
clone.sso = sso;
SHARED_TAG_COMPOUND.put( sso, new WeakReference<SharedSearchObject>( sso ) );
return clone;
}
}
+109 -109
View File
@@ -18,12 +18,14 @@
package appeng.util.item;
import java.io.IOException;
import io.netty.buffer.ByteBuf;
import appeng.api.storage.data.IAEStack;
public abstract class AEStack<StackType extends IAEStack> implements IAEStack<StackType>
{
@@ -31,10 +33,67 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
protected long stackSize;
protected long countRequestable;
@Override
public boolean isMeaningful()
static long getPacketValue( byte type, ByteBuf tag )
{
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
if( type == 0 )
{
long l = tag.readByte();
l -= Byte.MIN_VALUE;
return l;
}
else if( type == 1 )
{
long l = tag.readShort();
l -= Short.MIN_VALUE;
return l;
}
else if( type == 2 )
{
long l = tag.readInt();
l -= Integer.MIN_VALUE;
return l;
}
return tag.readLong();
}
@Override
public long getStackSize()
{
return this.stackSize;
}
@Override
public StackType setStackSize( long ss )
{
this.stackSize = ss;
return (StackType) this;
}
@Override
public long getCountRequestable()
{
return this.countRequestable;
}
@Override
public StackType setCountRequestable( long countRequestable )
{
this.countRequestable = countRequestable;
return (StackType) this;
}
@Override
public boolean isCraftable()
{
return this.isCraftable;
}
@Override
public StackType setCraftable( boolean isCraftable )
{
this.isCraftable = isCraftable;
return (StackType) this;
}
@Override
@@ -48,127 +107,39 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
}
@Override
public long getStackSize()
public boolean isMeaningful()
{
return this.stackSize;
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
}
@Override
public StackType setStackSize(long ss)
{
this.stackSize = ss;
return (StackType) this;
}
@Override
public long getCountRequestable()
{
return this.countRequestable;
}
@Override
public StackType setCountRequestable(long countRequestable)
{
this.countRequestable = countRequestable;
return (StackType) this;
}
@Override
public boolean isCraftable()
{
return this.isCraftable;
}
@Override
public StackType setCraftable(boolean isCraftable)
{
this.isCraftable = isCraftable;
return (StackType) this;
}
@Override
public void decStackSize(long i)
{
this.stackSize -= i;
}
@Override
public void incStackSize(long i)
public void incStackSize( long i )
{
this.stackSize += i;
}
@Override
public void decCountRequestable(long i)
public void decStackSize( long i )
{
this.stackSize -= i;
}
@Override
public void incCountRequestable( long i )
{
this.countRequestable += i;
}
@Override
public void decCountRequestable( long i )
{
this.countRequestable -= i;
}
@Override
public void incCountRequestable(long i)
public void writeToPacket( ByteBuf i ) throws IOException
{
this.countRequestable += i;
}
void putPacketValue(ByteBuf tag, long num)
{
if ( num <= 255 )
tag.writeByte( (byte) (num + Byte.MIN_VALUE) );
else if ( num <= 65535 )
tag.writeShort( (short) (num + Short.MIN_VALUE) );
else if ( num <= 4294967295L )
tag.writeInt( (int) (num + Integer.MIN_VALUE) );
else
tag.writeLong( num );
}
static long getPacketValue(byte type, ByteBuf tag)
{
if ( type == 0 )
{
long l = tag.readByte();
l -= Byte.MIN_VALUE;
return l;
}
else if ( type == 1 )
{
long l = tag.readShort();
l -= Short.MIN_VALUE;
return l;
}
else if ( type == 2 )
{
long l = tag.readInt();
l -= Integer.MIN_VALUE;
return l;
}
return tag.readLong();
}
byte getType(long num)
{
if ( num <= 255 )
return 0;
else if ( num <= 65535 )
return 1;
else if ( num <= 4294967295L )
return 2;
else
return 3;
}
abstract void writeIdentity(ByteBuf i) throws IOException;
abstract void readNBT(ByteBuf i) throws IOException;
abstract boolean hasTagCompound();
@Override
public void writeToPacket(ByteBuf i) throws IOException
{
byte mask = (byte) (this.getType( 0 ) | (this.getType( this.stackSize ) << 2) | (this.getType( this.countRequestable ) << 4) | ((byte) (this.isCraftable ? 1 : 0) << 6) | (this.hasTagCompound() ? 1
: 0) << 7);
byte mask = (byte) ( this.getType( 0 ) | ( this.getType( this.stackSize ) << 2 ) | ( this.getType( this.countRequestable ) << 4 ) | ( (byte) ( this.isCraftable ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
i.writeByte( mask );
this.writeIdentity( i );
@@ -180,4 +151,33 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
this.putPacketValue( i, this.countRequestable );
}
byte getType( long num )
{
if( num <= 255 )
return 0;
else if( num <= 65535 )
return 1;
else if( num <= 4294967295L )
return 2;
else
return 3;
}
abstract boolean hasTagCompound();
abstract void writeIdentity( ByteBuf i ) throws IOException;
abstract void readNBT( ByteBuf i ) throws IOException;
void putPacketValue( ByteBuf tag, long num )
{
if( num <= 255 )
tag.writeByte( (byte) ( num + Byte.MIN_VALUE ) );
else if( num <= 65535 )
tag.writeShort( (short) ( num + Short.MIN_VALUE ) );
else if( num <= 4294967295L )
tag.writeInt( (int) ( num + Integer.MIN_VALUE ) );
else
tag.writeLong( num );
}
}
+111 -113
View File
@@ -1,4 +1,3 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
@@ -28,10 +27,10 @@ import java.util.List;
import java.util.NavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import com.google.common.collect.Lists;
import net.minecraftforge.oredict.OreDictionary;
import com.google.common.collect.Lists;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
@@ -46,84 +45,157 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
private final Class<? extends IAEStack> clz;
// private int currentPriority = Integer.MIN_VALUE;
int iteration = Integer.MIN_VALUE;
public Throwable stacktrace;
int iteration = Integer.MIN_VALUE;
public ItemList( Class<? extends IAEStack> cla )
{
this.clz = cla;
}
private boolean checkStackType( StackType st )
{
if ( st == null )
return true;
if ( !this.clz.isInstance( st ) )
throw new RuntimeException( "WRONG TYPE - got " + st.getClass().getName() + " expected " + this.clz.getName() );
return false;
}
@Override
synchronized public void add( StackType option )
{
if ( this.checkStackType( option ) )
if( this.checkStackType( option ) )
return;
StackType st = this.records.get( option );
if ( st != null )
if( st != null )
{
// st.setPriority( currentPriority );
st.add( option );
return;
}
StackType opt = ( StackType ) option.copy();
StackType opt = (StackType) option.copy();
// opt.setPriority( currentPriority );
this.records.put( opt, opt );
}
private boolean checkStackType( StackType st )
{
if( st == null )
return true;
if( !this.clz.isInstance( st ) )
throw new RuntimeException( "WRONG TYPE - got " + st.getClass().getName() + " expected " + this.clz.getName() );
return false;
}
@Override
synchronized public StackType findPrecise( StackType i )
{
if( this.checkStackType( i ) )
return null;
StackType is = this.records.get( i );
if( is != null )
{
return is;
}
return null;
}
@Override
public Collection<StackType> findFuzzy( StackType filter, FuzzyMode fuzzy )
{
if( this.checkStackType( filter ) )
return new ArrayList<StackType>();
if( filter instanceof IAEFluidStack )
{
List<StackType> result = Lists.newArrayList();
if( filter.equals( this ) )
{
result.add( filter );
}
return result;
}
AEItemStack ais = (AEItemStack) filter;
if( ais.isOre() )
{
OreReference or = ais.def.isOre;
if( or.getAEEquivalents().size() == 1 )
{
IAEItemStack is = or.getAEEquivalents().get( 0 );
return this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
}
else
{
Collection<StackType> output = new LinkedList<StackType>();
for( IAEItemStack is : or.getAEEquivalents() )
output.addAll( this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
return output;
}
}
return this.findFuzzyDamage( ais, fuzzy, false );
}
@Override
public boolean isEmpty()
{
return !this.iterator().hasNext();
}
public Collection<StackType> findFuzzyDamage( AEItemStack filter, FuzzyMode fuzzy, boolean ignoreMeta )
{
StackType low = (StackType) filter.getLow( fuzzy, ignoreMeta );
StackType high = (StackType) filter.getHigh( fuzzy, ignoreMeta );
return this.records.subMap( low, true, high, true ).descendingMap().values();
}
@Override
synchronized public void addStorage( StackType option ) // adds a stack as
// stored.
// stored.
{
if ( this.checkStackType( option ) )
if( this.checkStackType( option ) )
return;
StackType st = this.records.get( option );
if ( st != null )
if( st != null )
{
// st.setPriority( currentPriority );
st.incStackSize( option.getStackSize() );
return;
}
StackType opt = ( StackType ) option.copy();
StackType opt = (StackType) option.copy();
// opt.setPriority( currentPriority );
this.records.put( opt, opt );
}
/*
* synchronized public void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
*/
@Override
synchronized public void addCrafting( StackType option ) // adds a stack as
// craftable.
// craftable.
{
if ( this.checkStackType( option ) )
if( this.checkStackType( option ) )
return;
StackType st = this.records.get( option );
if ( st != null )
if( st != null )
{
// st.setPriority( currentPriority );
st.setCraftable( true );
return;
}
StackType opt = ( StackType ) option.copy();
StackType opt = (StackType) option.copy();
// opt.setPriority( currentPriority );
opt.setStackSize( 0 );
opt.setCraftable( true );
@@ -133,22 +205,22 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
@Override
synchronized public void addRequestable( StackType option ) // adds a stack
// as
// requestable.
// as
// requestable.
{
if ( this.checkStackType( option ) )
if( this.checkStackType( option ) )
return;
StackType st = this.records.get( option );
if ( st != null )
if( st != null )
{
// st.setPriority( currentPriority );
( ( IAEItemStack ) st ).setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
( (IAEItemStack) st ).setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
return;
}
StackType opt = ( StackType ) option.copy();
StackType opt = (StackType) option.copy();
// opt.setPriority( currentPriority );
opt.setStackSize( 0 );
opt.setCraftable( false );
@@ -160,46 +232,13 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
@Override
synchronized public StackType getFirstItem()
{
for ( StackType stackType : this )
for( StackType stackType : this )
{
return stackType;
}
return null;
}
@Override
synchronized public void resetStatus()
{
for ( StackType i : this )
i.reset();
}
/*
* synchronized public void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
*/
@Override
synchronized public Iterator<StackType> iterator()
{
return new MeaningfulIterator<StackType>( this.records.values().iterator() );
}
@Override
synchronized public StackType findPrecise( StackType i )
{
if ( this.checkStackType( i ) )
return null;
StackType is = this.records.get( i );
if ( is != null )
{
return is;
}
return null;
}
@Override
synchronized public int size()
{
@@ -207,56 +246,15 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
}
@Override
public boolean isEmpty()
synchronized public Iterator<StackType> iterator()
{
return !this.iterator().hasNext();
}
public Collection<StackType> findFuzzyDamage( AEItemStack filter, FuzzyMode fuzzy, boolean ignoreMeta )
{
StackType low = ( StackType ) filter.getLow( fuzzy, ignoreMeta );
StackType high = ( StackType ) filter.getHigh( fuzzy, ignoreMeta );
return this.records.subMap( low, true, high, true ).descendingMap().values();
return new MeaningfulIterator<StackType>( this.records.values().iterator() );
}
@Override
public Collection<StackType> findFuzzy( StackType filter, FuzzyMode fuzzy )
synchronized public void resetStatus()
{
if ( this.checkStackType( filter ) )
return new ArrayList<StackType>();
if ( filter instanceof IAEFluidStack )
{
List<StackType> result = Lists.newArrayList();
if ( filter.equals( this ) )
{
result.add( filter );
}
return result;
}
AEItemStack ais = ( AEItemStack ) filter;
if ( ais.isOre() )
{
OreReference or = ais.def.isOre;
if ( or.getAEEquivalents().size() == 1 )
{
IAEItemStack is = or.getAEEquivalents().get( 0 );
return this.findFuzzyDamage( ( AEItemStack ) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
}
else
{
Collection<StackType> output = new LinkedList<StackType>();
for ( IAEItemStack is : or.getAEEquivalents() )
output.addAll( this.findFuzzyDamage( ( AEItemStack ) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
return output;
}
}
return this.findFuzzyDamage( ais, fuzzy, false );
for( StackType i : this )
i.reset();
}
}
@@ -18,6 +18,7 @@
package appeng.util.item;
import java.util.Collection;
import appeng.api.AEApi;
@@ -25,24 +26,26 @@ import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemContainer;
public class ItemModList implements IItemContainer<IAEItemStack>
{
final IItemContainer<IAEItemStack> backingStore;
final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().createItemList();
public ItemModList(IItemContainer<IAEItemStack> backend) {
public ItemModList( IItemContainer<IAEItemStack> backend )
{
this.backingStore = backend;
}
@Override
public void add(IAEItemStack option)
public void add( IAEItemStack option )
{
IAEItemStack over = this.overrides.findPrecise( option );
if ( over == null )
if( over == null )
{
over = this.backingStore.findPrecise( option );
if ( over == null )
if( over == null )
this.overrides.add( option );
else
{
@@ -55,16 +58,16 @@ public class ItemModList implements IItemContainer<IAEItemStack>
}
@Override
public IAEItemStack findPrecise(IAEItemStack i)
public IAEItemStack findPrecise( IAEItemStack i )
{
IAEItemStack over = this.overrides.findPrecise( i );
if ( over == null )
if( over == null )
return this.backingStore.findPrecise( i );
return over;
}
@Override
public Collection<IAEItemStack> findFuzzy(IAEItemStack input, FuzzyMode fuzzy)
public Collection<IAEItemStack> findFuzzy( IAEItemStack input, FuzzyMode fuzzy )
{
return this.overrides.findFuzzy( input, fuzzy );
}
@@ -74,5 +77,4 @@ public class ItemModList implements IItemContainer<IAEItemStack>
{
return this.overrides.isEmpty() && this.backingStore.isEmpty();
}
}
@@ -18,17 +18,19 @@
package appeng.util.item;
import java.util.Iterator;
import appeng.api.storage.data.IAEStack;
public class MeaningfulIterator<StackType extends IAEStack> implements Iterator<StackType>
{
private final Iterator<StackType> parent;
private StackType next;
public MeaningfulIterator(Iterator<StackType> iterator)
public MeaningfulIterator( Iterator<StackType> iterator )
{
this.parent = iterator;
}
@@ -36,10 +38,10 @@ public class MeaningfulIterator<StackType extends IAEStack> implements Iterator<
@Override
public boolean hasNext()
{
while (this.parent.hasNext())
while( this.parent.hasNext() )
{
this.next = this.parent.next();
if ( this.next.isMeaningful() )
if( this.next.isMeaningful() )
{
return true;
}
@@ -63,5 +65,4 @@ public class MeaningfulIterator<StackType extends IAEStack> implements Iterator<
{
this.parent.remove();
}
}
+40 -40
View File
@@ -45,14 +45,14 @@ public class OreHelper
/**
* A local cache to speed up OreDictionary lookups.
*/
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder
.newBuilder().build( new CacheLoader<String, List<ItemStack>>(){
@Override
public List<ItemStack> load( String oreName )
{
return OreDictionary.getOres( oreName );
}
} );
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder.newBuilder().build( new CacheLoader<String, List<ItemStack>>()
{
@Override
public List<ItemStack> load( String oreName )
{
return OreDictionary.getOres( oreName );
}
} );
private final Map<ItemRef, OreReference> references = new HashMap<ItemRef, OreReference>();
@@ -60,13 +60,14 @@ public class OreHelper
* Test if the passed {@link ItemStack} is an ore.
*
* @param ItemStack the itemstack to test
*
* @return true if an ore entry exists, false otherwise
*/
public OreReference isOre( ItemStack ItemStack )
{
ItemRef ir = new ItemRef( ItemStack );
if ( !this.references.containsKey( ir ) )
if( !this.references.containsKey( ir ) )
{
final OreReference ref = new OreReference();
final Collection<Integer> ores = ref.getOres();
@@ -74,17 +75,17 @@ public class OreHelper
Set<String> toAdd = new HashSet<String>();
for ( String ore : OreDictionary.getOreNames() )
for( String ore : OreDictionary.getOreNames() )
{
// skip ore if it is a match already or null.
if ( ore == null || toAdd.contains( ore ) )
if( ore == null || toAdd.contains( ore ) )
{
continue;
}
for ( ItemStack oreItem : this.oreDictCache.getUnchecked( ore ) )
for( ItemStack oreItem : this.oreDictCache.getUnchecked( ore ) )
{
if ( OreDictionary.itemMatches( oreItem, ItemStack, false ) )
if( OreDictionary.itemMatches( oreItem, ItemStack, false ) )
{
toAdd.add( ore );
break;
@@ -92,13 +93,13 @@ public class OreHelper
}
}
for ( String ore : toAdd )
for( String ore : toAdd )
{
set.add( ore );
ores.add( OreDictionary.getOreID( ore ) );
}
if ( !set.isEmpty() )
if( !set.isEmpty() )
this.references.put( ir, ref );
else
this.references.put( ir, null );
@@ -117,16 +118,16 @@ public class OreHelper
public boolean sameOre( OreReference a, OreReference b )
{
if ( a == null || b == null )
if( a == null || b == null )
return false;
if ( a == b )
if( a == b )
return true;
Collection<Integer> bOres = b.getOres();
for ( Integer ore : a.getOres() )
for( Integer ore : a.getOres() )
{
if ( bOres.contains( ore ) )
if( bOres.contains( ore ) )
return true;
}
@@ -136,14 +137,14 @@ public class OreHelper
public boolean sameOre( AEItemStack aeItemStack, ItemStack o )
{
OreReference a = aeItemStack.def.isOre;
if ( a == null )
if( a == null )
return false;
for ( String oreName : a.getEquivalents() )
for( String oreName : a.getEquivalents() )
{
for ( ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) )
for( ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) )
{
if ( OreDictionary.itemMatches( oreItem, o, false ) )
if( OreDictionary.itemMatches( oreItem, o, false ) )
return true;
}
}
@@ -159,11 +160,15 @@ public class OreHelper
private static class ItemRef
{
private final Item ref;
private final int damage;
private final int hash;
ItemRef( ItemStack stack )
{
this.ref = stack.getItem();
if ( stack.getItem().isDamageable() )
if( stack.getItem().isDamageable() )
this.damage = 0; // IGNORED
else
this.damage = stack.getItemDamage(); // might be important...
@@ -171,32 +176,27 @@ public class OreHelper
this.hash = this.ref.hashCode() ^ this.damage;
}
private final Item ref;
private final int damage;
private final int hash;
@Override
public boolean equals( Object obj )
{
if ( obj == null )
return false;
if ( this.getClass() != obj.getClass() )
return false;
ItemRef other = ( ItemRef ) obj;
return this.damage == other.damage && this.ref == other.ref;
}
@Override
public int hashCode()
{
return this.hash;
}
@Override
public boolean equals( Object obj )
{
if( obj == null )
return false;
if( this.getClass() != obj.getClass() )
return false;
ItemRef other = (ItemRef) obj;
return this.damage == other.damage && this.ref == other.ref;
}
@Override
public String toString()
{
return "ItemRef [ref=" + this.ref.getUnlocalizedName() + ", damage=" + this.damage + ", hash=" + this.hash + ']';
}
}
}
@@ -35,8 +35,8 @@ public class OreReference
{
private final List<String> otherOptions = new LinkedList<String>();
private List<IAEItemStack> aeOtherOptions = null;
private final Set<Integer> ores = new HashSet<Integer>();
private List<IAEItemStack> aeOtherOptions = null;
public Collection<String> getEquivalents()
{
@@ -45,20 +45,19 @@ public class OreReference
public List<IAEItemStack> getAEEquivalents()
{
if ( this.aeOtherOptions == null )
if( this.aeOtherOptions == null )
{
this.aeOtherOptions = new ArrayList<IAEItemStack>( this.otherOptions.size() );
// SUMMON AE STACKS!
for ( String oreName : this.otherOptions )
for( String oreName : this.otherOptions )
{
for ( ItemStack is : OreHelper.INSTANCE.getCachedOres( oreName ) )
for( ItemStack is : OreHelper.INSTANCE.getCachedOres( oreName ) )
{
if ( is.getItem() != null )
if( is.getItem() != null )
{
this.aeOtherOptions.add( AEItemStack.create( is ) );
}
}
}
}
@@ -70,5 +69,4 @@ public class OreReference
{
return this.ores;
}
}
@@ -18,44 +18,46 @@
package appeng.util.item;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import appeng.util.Platform;
public class SharedSearchObject
{
final int def;
final int hash;
NBTTagCompound compound;
public AESharedNBT shared;
NBTTagCompound compound;
public SharedSearchObject(Item itemID, int damageValue, NBTTagCompound tagCompound) {
this.def = (damageValue << Platform.DEF_OFFSET) | Item.itemRegistry.getIDForObject( itemID );
public SharedSearchObject( Item itemID, int damageValue, NBTTagCompound tagCompound )
{
this.def = ( damageValue << Platform.DEF_OFFSET ) | Item.itemRegistry.getIDForObject( itemID );
this.hash = Platform.NBTOrderlessHash( tagCompound );
this.compound = tagCompound;
}
@Override
public boolean equals(Object obj)
{
if ( obj == null )
return false;
if ( this.getClass() != obj.getClass() )
return false;
SharedSearchObject other = (SharedSearchObject) obj;
if ( this.def == other.def && this.hash == other.hash )
{
return Platform.NBTEqualityTest( this.compound, other.compound );
}
return false;
}
@Override
public int hashCode()
{
return this.def ^ this.hash;
}
@Override
public boolean equals( Object obj )
{
if( obj == null )
return false;
if( this.getClass() != obj.getClass() )
return false;
SharedSearchObject other = (SharedSearchObject) obj;
if( this.def == other.def && this.hash == other.hash )
{
return Platform.NBTEqualityTest( this.compound, other.compound );
}
return false;
}
}