2013-12-27 23:59:59 +01:00
|
|
|
package appeng.util.item;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2014-05-14 17:55:45 +02:00
|
|
|
import java.io.ByteArrayInputStream;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.io.ByteArrayOutputStream;
|
2014-05-14 17:55:45 +02:00
|
|
|
import java.io.DataInputStream;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.io.DataOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.CompressedStreamTools;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import appeng.api.config.FuzzyMode;
|
2014-01-05 09:45:29 +01:00
|
|
|
import appeng.api.storage.StorageChannel;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IAETagCompound;
|
|
|
|
import appeng.util.Platform;
|
2014-07-03 04:09:17 +02:00
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
|
|
|
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
2013-12-27 23:59:59 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack, Comparable<AEItemStack>
|
|
|
|
{
|
|
|
|
|
|
|
|
AEItemDef def;
|
|
|
|
|
2014-06-16 07:48:43 +02:00
|
|
|
@Override
|
|
|
|
public String toString()
|
|
|
|
{
|
|
|
|
return getItemStack().toString();
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void add(IAEItemStack option)
|
|
|
|
{
|
|
|
|
if ( option == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if ( priority < ((AEItemStack) option).priority )
|
|
|
|
// priority = ((AEItemStack) option).priority;
|
|
|
|
|
|
|
|
incStackSize( option.getStackSize() );
|
|
|
|
setCountRequestable( getCountRequestable() + option.getCountRequestable() );
|
|
|
|
setCraftable( isCraftable() || option.isCraftable() );
|
|
|
|
}
|
|
|
|
|
|
|
|
private AEItemStack(AEItemStack is) {
|
|
|
|
def = is.def;
|
|
|
|
stackSize = is.stackSize;
|
|
|
|
setCraftable( is.isCraftable() );
|
|
|
|
setCountRequestable( is.getCountRequestable() );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected AEItemStack(ItemStack is) {
|
|
|
|
if ( is == null )
|
|
|
|
throw new RuntimeException( "Invalid Itemstack." );
|
|
|
|
|
2014-07-02 07:06:44 +02:00
|
|
|
def = new AEItemDef( is.getItem() );
|
2014-06-16 07:48:43 +02:00
|
|
|
|
2014-05-29 18:41:47 +02:00
|
|
|
if ( def.item == null )
|
|
|
|
throw new RuntimeException( "This ItemStack is bad, it has a null item." );
|
2014-06-16 07:48:43 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
/*
|
|
|
|
* Prevent an Item from changing the damage value on me... Either, this or a core mod.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2014-09-28 11:47:17 +02:00
|
|
|
* Super hackery.
|
2013-12-27 23:59:59 +01:00
|
|
|
*
|
|
|
|
* is.itemID = appeng.api.Materials.matQuartz.itemID; damageValue = is.getItemDamage(); is.itemID = itemID;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2014-09-28 11:47:17 +02:00
|
|
|
* Kinda hackery
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
2013-12-28 21:55:31 +01:00
|
|
|
def.damageValue = def.getDamageValueHack( is );
|
2014-09-28 11:47:17 +02:00
|
|
|
def.displayDamage = is.getItemDamageForDisplay();
|
2013-12-27 23:59:59 +01:00
|
|
|
def.maxDamage = is.getMaxDamage();
|
|
|
|
|
2014-01-01 10:03:00 +01:00
|
|
|
NBTTagCompound tagCompound = is.getTagCompound();
|
|
|
|
if ( tagCompound != null )
|
2014-01-20 17:41:37 +01:00
|
|
|
def.tagCompound = (AESharedNBT) AESharedNBT.getSharedTagCompound( tagCompound, is );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
stackSize = is.stackSize;
|
|
|
|
setCraftable( false );
|
|
|
|
setCountRequestable( 0 );
|
|
|
|
|
2014-01-06 07:55:16 +01:00
|
|
|
def.reHash();
|
2014-02-13 06:24:07 +01:00
|
|
|
def.isOre = OreHelper.instance.isOre( is );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static AEItemStack create(Object a)
|
|
|
|
{
|
|
|
|
if ( a instanceof ItemStack )
|
|
|
|
return new AEItemStack( (ItemStack) a );
|
2014-01-01 10:03:00 +01:00
|
|
|
if ( a instanceof IAEItemStack )
|
|
|
|
((IAEItemStack) a).copy();
|
2013-12-27 23:59:59 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Item getItem()
|
|
|
|
{
|
|
|
|
return def.item;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object ia)
|
|
|
|
{
|
|
|
|
if ( ia instanceof AEItemStack )
|
|
|
|
{
|
2014-07-13 00:14:28 +02:00
|
|
|
return ((AEItemStack) ia).def.equals( def );// && def.tagCompound == ((AEItemStack) ia).def.tagCompound;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else if ( ia instanceof ItemStack )
|
|
|
|
{
|
|
|
|
ItemStack is = (ItemStack) ia;
|
|
|
|
|
|
|
|
if ( is.getItem() == def.item && is.getItemDamage() == this.def.damageValue )
|
|
|
|
{
|
2014-09-28 20:56:16 +02:00
|
|
|
NBTTagCompound ta = def.tagCompound;
|
2013-12-27 23:59:59 +01:00
|
|
|
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 ItemStack getItemStack()
|
|
|
|
{
|
|
|
|
ItemStack is = new ItemStack( def.item, (int) Math.min( Integer.MAX_VALUE, stackSize ), def.damageValue );
|
|
|
|
if ( def.tagCompound != null )
|
|
|
|
is.setTagCompound( def.tagCompound.getNBTTagCompoundCopy() );
|
|
|
|
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAEItemStack copy()
|
|
|
|
{
|
|
|
|
return new AEItemStack( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound i)
|
|
|
|
{
|
|
|
|
/*
|
2014-02-09 02:34:52 +01:00
|
|
|
* Mojang Fucked this over ; GC Optimization - Ugly Yes, but it saves a lot in the memory department.
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
/*
|
|
|
|
* NBTBase id = i.getTag( "id" ); NBTBase Count = i.getTag( "Count" ); NBTBase Cnt = i.getTag( "Cnt" ); NBTBase
|
|
|
|
* Req = i.getTag( "Req" ); NBTBase Craft = i.getTag( "Craft" ); NBTBase Damage = i.getTag( "Damage" );
|
|
|
|
*/
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
/*
|
|
|
|
* if ( id != null && id instanceof NBTTagShort ) ((NBTTagShort) id).data = (short) this.def.item.itemID; else
|
|
|
|
*/
|
|
|
|
i.setShort( "id", (short) Item.itemRegistry.getIDForObject( this.def.item ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
/*
|
|
|
|
* if ( Count != null && Count instanceof NBTTagByte ) ((NBTTagByte) Count).data = (byte) 0; else
|
|
|
|
*/
|
|
|
|
i.setByte( "Count", (byte) 0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
/*
|
|
|
|
* if ( Cnt != null && Cnt instanceof NBTTagLong ) ((NBTTagLong) Cnt).data = this.stackSize; else
|
|
|
|
*/
|
|
|
|
i.setLong( "Cnt", this.stackSize );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
/*
|
|
|
|
* if ( Req != null && Req instanceof NBTTagLong ) ((NBTTagLong) Req).data = this.stackSize; else
|
|
|
|
*/
|
|
|
|
i.setLong( "Req", this.getCountRequestable() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
/*
|
|
|
|
* if ( Craft != null && Craft instanceof NBTTagByte ) ((NBTTagByte) Craft).data = (byte) (this.isCraftable() ?
|
|
|
|
* 1 : 0); else
|
|
|
|
*/
|
|
|
|
i.setBoolean( "Craft", this.isCraftable() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
/*
|
|
|
|
* if ( Damage != null && Damage instanceof NBTTagShort ) ((NBTTagShort) Damage).data = (short)
|
|
|
|
* this.def.damageValue; else
|
|
|
|
*/
|
|
|
|
i.setShort( "Damage", (short) this.def.damageValue );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( def.tagCompound != null )
|
2014-09-28 20:56:16 +02:00
|
|
|
i.setTag( "tag", def.tagCompound );
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
|
|
|
i.removeTag( "tag" );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static IAEItemStack loadItemStackFromNBT(NBTTagCompound i)
|
|
|
|
{
|
2014-07-04 08:19:45 +02:00
|
|
|
if ( i == null )
|
|
|
|
return null;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
ItemStack itemstack = ItemStack.loadItemStackFromNBT( i );
|
|
|
|
if ( itemstack == null )
|
|
|
|
return null;
|
2014-07-04 08:19:45 +02:00
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
AEItemStack item = AEItemStack.create( itemstack );
|
|
|
|
// item.priority = i.getInteger( "Priority" );
|
|
|
|
item.stackSize = i.getLong( "Cnt" );
|
|
|
|
item.setCountRequestable( i.getLong( "Req" ) );
|
|
|
|
item.setCraftable( i.getBoolean( "Craft" ) );
|
|
|
|
return item;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasTagCompound()
|
|
|
|
{
|
|
|
|
return def.tagCompound != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
return def.myHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(AEItemStack b)
|
|
|
|
{
|
2014-03-22 04:58:03 +01:00
|
|
|
int id = compare( def.item.hashCode(), b.def.item.hashCode() );
|
2014-09-28 11:47:17 +02:00
|
|
|
int damageValue = compare( def.damageValue, b.def.damageValue );
|
|
|
|
int displayDamage = compare( def.displayDamage, b.def.displayDamage );
|
2014-03-22 04:58:03 +01:00
|
|
|
// AELog.info( "NBT: " + nbt );
|
2014-09-28 11:47:17 +02:00
|
|
|
return id == 0 ? (damageValue == 0 ? (displayDamage == 0 ? compareNBT( b.def ) : displayDamage) : damageValue) : id;
|
2014-03-22 04:58:03 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-22 04:58:03 +01:00
|
|
|
private int compareNBT(AEItemDef b)
|
|
|
|
{
|
|
|
|
int nbt = compare( (def.tagCompound == null ? 0 : def.tagCompound.getHash()), (b.tagCompound == null ? 0 : b.tagCompound.getHash()) );
|
|
|
|
if ( nbt == 0 )
|
|
|
|
return compare( System.identityHashCode( def.tagCompound ), System.identityHashCode( b.tagCompound ) );
|
|
|
|
return nbt;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int compare(int l, long m)
|
|
|
|
{
|
|
|
|
return l < m ? -1 : (l > m ? 1 : 0);
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public List getToolTip()
|
|
|
|
{
|
|
|
|
if ( def.tooltip != null )
|
|
|
|
return def.tooltip;
|
|
|
|
|
|
|
|
return def.tooltip = Platform.getTooltip( getItemStack() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public String getDisplayName()
|
|
|
|
{
|
|
|
|
if ( def.displayName != null )
|
|
|
|
return def.displayName;
|
|
|
|
|
|
|
|
return def.displayName = Platform.getItemDisplayName( getItemStack() );
|
|
|
|
}
|
|
|
|
|
2014-07-03 04:09:17 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public String getModID()
|
|
|
|
{
|
|
|
|
if ( def.uniqueID != null )
|
|
|
|
return getModName( def.uniqueID );
|
|
|
|
|
|
|
|
return getModName( def.uniqueID = GameRegistry.findUniqueIdentifierFor( def.item ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getModName(UniqueIdentifier uniqueIdentifier)
|
|
|
|
{
|
|
|
|
if ( uniqueIdentifier == null )
|
|
|
|
return "** Null";
|
|
|
|
|
|
|
|
return uniqueIdentifier.modId == null ? "** Null" : uniqueIdentifier.modId;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public IAEItemStack empty()
|
|
|
|
{
|
|
|
|
IAEItemStack dup = copy();
|
|
|
|
dup.reset();
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemDamage()
|
|
|
|
{
|
|
|
|
return def.damageValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
void writeIdentity(ByteBuf i) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
i.writeShort( Item.itemRegistry.getIDForObject( def.item ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
i.writeShort( getItemDamage() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
void readNBT(ByteBuf i) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( hasTagCompound() )
|
|
|
|
{
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
DataOutputStream data = new DataOutputStream( bytes );
|
|
|
|
|
|
|
|
CompressedStreamTools.write( (NBTTagCompound) getTagCompound(), data );
|
|
|
|
|
|
|
|
byte[] tagBytes = bytes.toByteArray();
|
|
|
|
int size = tagBytes.length;
|
|
|
|
|
|
|
|
i.writeInt( size );
|
2014-02-09 02:34:52 +01:00
|
|
|
i.writeBytes( tagBytes );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
public static IAEItemStack loadItemStackFromPacket(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
|
|
|
d.setShort( "id", data.readShort() );
|
|
|
|
d.setShort( "Damage", data.readShort() );
|
|
|
|
d.setByte( "Count", (byte) 0 );
|
|
|
|
|
|
|
|
if ( hasTagCompound )
|
|
|
|
{
|
|
|
|
int len = data.readInt();
|
|
|
|
|
|
|
|
byte[] bd = new byte[len];
|
2014-02-09 02:34:52 +01:00
|
|
|
data.readBytes( bd );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-05-14 17:55:45 +02:00
|
|
|
ByteArrayInputStream di = new ByteArrayInputStream( bd );
|
2014-05-22 04:08:13 +02:00
|
|
|
d.setTag( "tag", CompressedStreamTools.read( new DataInputStream( di ) ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// long priority = getPacketValue( PriorityType, data );
|
|
|
|
long stackSize = getPacketValue( StackType, data );
|
|
|
|
long countRequestable = getPacketValue( CountReqType, data );
|
|
|
|
|
|
|
|
ItemStack itemstack = ItemStack.loadItemStackFromNBT( d );
|
|
|
|
if ( itemstack == null )
|
|
|
|
return null;
|
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
AEItemStack item = AEItemStack.create( itemstack );
|
|
|
|
// item.priority = (int) priority;
|
|
|
|
item.stackSize = stackSize;
|
|
|
|
item.setCountRequestable( countRequestable );
|
|
|
|
item.setCraftable( isCraftable );
|
|
|
|
return item;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean sameOre(IAEItemStack is)
|
|
|
|
{
|
|
|
|
return OreHelper.instance.sameOre( this, is );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean fuzzyComparison(Object st, FuzzyMode Mode)
|
|
|
|
{
|
|
|
|
if ( st instanceof IAEItemStack )
|
|
|
|
{
|
|
|
|
IAEItemStack o = (IAEItemStack) st;
|
|
|
|
|
|
|
|
if ( sameOre( o ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ( o.getItem() == getItem() )
|
|
|
|
{
|
|
|
|
if ( def.item.isDamageable() )
|
|
|
|
{
|
|
|
|
ItemStack a = getItemStack();
|
|
|
|
ItemStack b = o.getItemStack();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( Mode == FuzzyMode.IGNORE_ALL )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if ( Mode == FuzzyMode.PERCENT_99 )
|
|
|
|
{
|
|
|
|
return (a.getItemDamageForDisplay() > 1) == (b.getItemDamageForDisplay() > 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float APercentDamaged = 1.0f - (float) a.getItemDamageForDisplay() / (float) a.getMaxDamage();
|
|
|
|
float BPercentDamaged = 1.0f - (float) b.getItemDamageForDisplay() / (float) b.getMaxDamage();
|
|
|
|
|
|
|
|
return (APercentDamaged > Mode.breakPoint) == (BPercentDamaged > Mode.breakPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable e)
|
|
|
|
{
|
|
|
|
if ( Mode == FuzzyMode.IGNORE_ALL )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if ( Mode == FuzzyMode.PERCENT_99 )
|
|
|
|
{
|
|
|
|
return (a.getItemDamage() > 1) == (b.getItemDamage() > 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float APercentDamaged = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
|
|
|
float BPercentDamaged = (float) b.getItemDamage() / (float) b.getMaxDamage();
|
|
|
|
|
|
|
|
return (APercentDamaged > Mode.breakPoint) == (BPercentDamaged > Mode.breakPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.getItemDamage() == o.getItemDamage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( st instanceof ItemStack )
|
|
|
|
{
|
|
|
|
ItemStack o = (ItemStack) st;
|
|
|
|
|
|
|
|
OreHelper.instance.sameOre( this, o );
|
|
|
|
|
|
|
|
if ( o.getItem() == getItem() )
|
|
|
|
{
|
|
|
|
if ( def.item.isDamageable() )
|
|
|
|
{
|
|
|
|
ItemStack a = getItemStack();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( Mode == FuzzyMode.IGNORE_ALL )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if ( Mode == FuzzyMode.PERCENT_99 )
|
|
|
|
{
|
2014-10-01 11:34:27 +02:00
|
|
|
return (a.getItemDamageForDisplay() > 1) == (o.getItemDamageForDisplay() > 1);
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float APercentDamaged = 1.0f - (float) a.getItemDamageForDisplay() / (float) a.getMaxDamage();
|
2014-10-01 11:34:27 +02:00
|
|
|
float BPercentDamaged = 1.0f - (float) o.getItemDamageForDisplay() / (float) o.getMaxDamage();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
return (APercentDamaged > Mode.breakPoint) == (BPercentDamaged > Mode.breakPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable e)
|
|
|
|
{
|
|
|
|
if ( Mode == FuzzyMode.IGNORE_ALL )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if ( Mode == FuzzyMode.PERCENT_99 )
|
|
|
|
{
|
2014-10-01 11:34:27 +02:00
|
|
|
return (a.getItemDamage() > 1) == (o.getItemDamage() > 1);
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float APercentDamaged = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
2014-10-01 11:34:27 +02:00
|
|
|
float BPercentDamaged = (float) o.getItemDamage() / (float) o.getMaxDamage();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
return (APercentDamaged > Mode.breakPoint) == (BPercentDamaged > Mode.breakPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.getItemDamage() == o.getItemDamage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
public IAEItemStack getLow(FuzzyMode fuzzy, boolean ignoreMeta)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
AEItemStack bottom = new AEItemStack( this );
|
2014-01-06 07:55:16 +01:00
|
|
|
AEItemDef newDef = bottom.def = bottom.def.copy();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
if ( ignoreMeta )
|
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = newDef.damageValue = 0;
|
2014-02-13 06:24:07 +01:00
|
|
|
newDef.reHash();
|
|
|
|
return bottom;
|
|
|
|
}
|
|
|
|
|
2014-05-22 04:08:13 +02:00
|
|
|
if ( newDef.item.isDamageable() )
|
2014-01-05 09:45:29 +01:00
|
|
|
{
|
2014-05-22 04:08:13 +02:00
|
|
|
if ( fuzzy == FuzzyMode.IGNORE_ALL )
|
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = 0;
|
2014-05-22 04:08:13 +02:00
|
|
|
}
|
2014-08-17 11:21:07 +02:00
|
|
|
else if ( fuzzy == FuzzyMode.PERCENT_99 )
|
|
|
|
{
|
|
|
|
if ( def.damageValue == 0 )
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = 0;
|
2014-08-17 11:21:07 +02:00
|
|
|
else
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = 1;
|
2014-08-17 11:21:07 +02:00
|
|
|
|
|
|
|
}
|
2014-05-22 04:08:13 +02:00
|
|
|
else
|
|
|
|
{
|
2014-07-31 04:55:00 +02:00
|
|
|
int breakpoint = fuzzy.calculateBreakPoint( def.maxDamage );
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = breakpoint <= def.displayDamage ? breakpoint : 0;
|
2014-05-22 04:08:13 +02:00
|
|
|
}
|
2014-01-05 09:45:29 +01:00
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.damageValue = newDef.displayDamage;
|
2014-05-22 04:08:13 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-22 19:27:44 +01:00
|
|
|
newDef.tagCompound = AEItemDef.lowTag;
|
2014-01-06 07:55:16 +01:00
|
|
|
newDef.reHash();
|
2013-12-27 23:59:59 +01:00
|
|
|
return bottom;
|
|
|
|
}
|
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
public IAEItemStack getHigh(FuzzyMode fuzzy, boolean ignoreMeta)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
AEItemStack top = new AEItemStack( this );
|
2014-01-06 07:55:16 +01:00
|
|
|
AEItemDef newDef = top.def = top.def.copy();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
if ( ignoreMeta )
|
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = newDef.damageValue = Integer.MAX_VALUE;
|
2014-02-13 06:24:07 +01:00
|
|
|
newDef.reHash();
|
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
2014-05-22 04:08:13 +02:00
|
|
|
if ( newDef.item.isDamageable() )
|
2014-01-05 09:45:29 +01:00
|
|
|
{
|
2014-05-22 04:08:13 +02:00
|
|
|
if ( fuzzy == FuzzyMode.IGNORE_ALL )
|
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = def.maxDamage + 1;
|
2014-05-22 04:08:13 +02:00
|
|
|
}
|
2014-08-17 11:21:07 +02:00
|
|
|
else if ( fuzzy == FuzzyMode.PERCENT_99 )
|
|
|
|
{
|
|
|
|
if ( def.damageValue == 0 )
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = 0;
|
2014-08-17 11:21:07 +02:00
|
|
|
else
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = def.maxDamage + 1;
|
2014-08-17 11:21:07 +02:00
|
|
|
}
|
2014-05-22 04:08:13 +02:00
|
|
|
else
|
|
|
|
{
|
2014-07-31 04:55:00 +02:00
|
|
|
int breakpoint = fuzzy.calculateBreakPoint( def.maxDamage );
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.displayDamage = def.displayDamage < breakpoint ? breakpoint - 1 : def.maxDamage + 1;
|
2014-05-22 04:08:13 +02:00
|
|
|
}
|
2014-01-05 09:45:29 +01:00
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
newDef.damageValue = newDef.displayDamage;
|
2014-05-22 04:08:13 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-22 19:27:44 +01:00
|
|
|
newDef.tagCompound = AEItemDef.highTag;
|
2014-01-06 07:55:16 +01:00
|
|
|
newDef.reHash();
|
2013-12-27 23:59:59 +01:00
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAETagCompound getTagCompound()
|
|
|
|
{
|
|
|
|
return def.tagCompound;
|
|
|
|
}
|
2013-12-28 21:55:31 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSameType(IAEItemStack otherStack)
|
|
|
|
{
|
|
|
|
if ( otherStack == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return def.equals( ((AEItemStack) otherStack).def );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSameType(ItemStack otherStack)
|
|
|
|
{
|
|
|
|
if ( otherStack == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return def.isItem( otherStack );
|
|
|
|
}
|
2014-01-05 09:45:29 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItem()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isFluid()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StorageChannel getChannel()
|
|
|
|
{
|
|
|
|
return StorageChannel.ITEMS;
|
|
|
|
}
|
2014-02-05 08:25:44 +01:00
|
|
|
|
|
|
|
public boolean isOre()
|
|
|
|
{
|
2014-02-13 06:24:07 +01:00
|
|
|
return def.isOre != null;
|
2014-02-05 08:25:44 +01:00
|
|
|
}
|
2014-07-03 04:09:17 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|