2013-12-27 23:59:59 +01:00
|
|
|
package appeng.util.item;
|
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import net.minecraft.item.Item;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-13 06:24:07 +01:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
|
|
|
|
public class OreHelper
|
|
|
|
{
|
|
|
|
|
2014-01-05 09:45:29 +01:00
|
|
|
public static OreHelper instance = new OreHelper();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
class ItemRef
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-13 06:24:07 +01:00
|
|
|
|
|
|
|
ItemRef(ItemStack stack) {
|
|
|
|
ref = stack.getItem();
|
|
|
|
|
|
|
|
if ( stack.getItem().isDamageable() )
|
|
|
|
damage = 0; // IGNORED
|
|
|
|
else
|
|
|
|
damage = stack.getItemDamage(); // might be important...
|
|
|
|
|
|
|
|
hash = ref.hashCode() ^ damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
Item ref;
|
|
|
|
int damage;
|
|
|
|
int hash;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o)
|
|
|
|
{
|
|
|
|
ItemRef obj = (ItemRef) o;
|
|
|
|
return damage == obj.damage && ref == obj.ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class OreResult
|
|
|
|
{
|
|
|
|
|
|
|
|
public OreRefrence oreValue = null;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
HashMap<ItemRef, OreResult> refrences = new HashMap();
|
|
|
|
|
|
|
|
public OreRefrence isOre(ItemStack ItemStack)
|
|
|
|
{
|
|
|
|
ItemRef ir = new ItemRef( ItemStack );
|
|
|
|
OreResult or = refrences.get( ir );
|
|
|
|
|
|
|
|
if ( or == null )
|
|
|
|
{
|
|
|
|
or = new OreResult();
|
|
|
|
refrences.put( ir, or );
|
|
|
|
|
|
|
|
OreRefrence ref = new OreRefrence();
|
|
|
|
Collection<Integer> ores = ref.getOres();
|
|
|
|
Collection<ItemStack> set = ref.getEquivilients();
|
|
|
|
Collection<IAEItemStack> aeset = ref.getAEEquivilients();
|
|
|
|
|
|
|
|
for (String ore : OreDictionary.getOreNames())
|
|
|
|
{
|
|
|
|
boolean add = false;
|
|
|
|
|
|
|
|
for (ItemStack oreItem : OreDictionary.getOres( ore ))
|
|
|
|
{
|
|
|
|
if ( OreDictionary.itemMatches( oreItem, ItemStack, false ) )
|
|
|
|
{
|
|
|
|
add = true;
|
2014-05-22 04:08:38 +02:00
|
|
|
break;
|
2014-02-13 06:24:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( add )
|
2014-05-22 04:08:38 +02:00
|
|
|
{
|
|
|
|
for (ItemStack oreItem : OreDictionary.getOres( ore ))
|
|
|
|
set.add( oreItem.copy() );
|
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
ores.add( OreDictionary.getOreID( ore ) );
|
2014-05-22 04:08:38 +02:00
|
|
|
}
|
2014-02-13 06:24:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !set.isEmpty() )
|
|
|
|
{
|
|
|
|
or.oreValue = ref;
|
|
|
|
|
|
|
|
// SUMMON AE STACKS!
|
|
|
|
for (ItemStack is : set)
|
2014-05-29 18:41:47 +02:00
|
|
|
if ( is.getItem() != null )
|
|
|
|
aeset.add( AEItemStack.create( is ) );
|
2014-02-13 06:24:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return or.oreValue;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean sameOre(AEItemStack aeItemStack, IAEItemStack is)
|
|
|
|
{
|
2014-02-13 06:24:07 +01:00
|
|
|
OreRefrence a = aeItemStack.def.isOre;
|
|
|
|
OreRefrence b = ((AEItemStack) aeItemStack).def.isOre;
|
|
|
|
|
|
|
|
if ( a == b )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ( a == null || b == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Collection<Integer> bOres = b.getOres();
|
|
|
|
for (Integer ore : a.ores)
|
|
|
|
{
|
|
|
|
if ( bOres.contains( ore ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
public boolean sameOre(OreRefrence a, OreRefrence b)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-13 06:24:07 +01:00
|
|
|
if ( a == b )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ( a == null || b == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Collection<Integer> bOres = b.getOres();
|
|
|
|
for (Integer ore : a.ores)
|
|
|
|
{
|
|
|
|
if ( bOres.contains( ore ) )
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
return false;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-13 06:24:07 +01:00
|
|
|
public boolean sameOre(AEItemStack aeItemStack, ItemStack o)
|
|
|
|
{
|
|
|
|
OreRefrence a = aeItemStack.def.isOre;
|
|
|
|
if ( a == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (ItemStack oreItem : a.getEquivilients())
|
|
|
|
{
|
|
|
|
if ( OreDictionary.itemMatches( oreItem, o, false ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|