Fuzzy now supports the ore dictionary again.
This commit is contained in:
parent
0a3474291c
commit
7f773f0d2b
6 changed files with 217 additions and 16 deletions
|
@ -79,6 +79,8 @@ import appeng.server.AccessType;
|
|||
import appeng.util.item.AEItemStack;
|
||||
import appeng.util.item.AESharedNBT;
|
||||
import appeng.util.item.ItemList;
|
||||
import appeng.util.item.OreHelper;
|
||||
import appeng.util.item.OreRefrence;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
@ -1078,6 +1080,12 @@ public class Platform
|
|||
}
|
||||
}
|
||||
|
||||
OreRefrence aOR = OreHelper.instance.isOre( a );
|
||||
OreRefrence bOR = OreHelper.instance.isOre( b );
|
||||
|
||||
if ( OreHelper.instance.sameOre( aOR, bOR ) )
|
||||
return true;
|
||||
|
||||
/*
|
||||
* // test ore dictionary.. int OreID = getOreID( a ); if ( OreID != -1 ) return OreID == getOreID( b );
|
||||
*
|
||||
|
|
|
@ -32,7 +32,7 @@ public class AEItemDef
|
|||
@SideOnly(Side.CLIENT)
|
||||
public List tooltip;
|
||||
|
||||
public boolean isOre;
|
||||
public OreRefrence isOre;
|
||||
|
||||
public AEItemDef copy()
|
||||
{
|
||||
|
|
|
@ -82,7 +82,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
|||
setCountRequestable( 0 );
|
||||
|
||||
def.reHash();
|
||||
def.isOre = OreHelper.instance.isOre( this );
|
||||
def.isOre = OreHelper.instance.isOre( is );
|
||||
}
|
||||
|
||||
public static AEItemStack create(Object a)
|
||||
|
@ -460,11 +460,18 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
|||
return false;
|
||||
}
|
||||
|
||||
public IAEItemStack getLow(FuzzyMode fuzzy)
|
||||
public IAEItemStack getLow(FuzzyMode fuzzy, boolean ignoreMeta)
|
||||
{
|
||||
AEItemStack bottom = new AEItemStack( this );
|
||||
AEItemDef newDef = bottom.def = bottom.def.copy();
|
||||
|
||||
if ( ignoreMeta )
|
||||
{
|
||||
newDef.dspDamage = newDef.damageValue = 0;
|
||||
newDef.reHash();
|
||||
return bottom;
|
||||
}
|
||||
|
||||
if ( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
newDef.dspDamage = 0;
|
||||
|
@ -482,11 +489,18 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
|||
return bottom;
|
||||
}
|
||||
|
||||
public IAEItemStack getHigh(FuzzyMode fuzzy)
|
||||
public IAEItemStack getHigh(FuzzyMode fuzzy, boolean ignoreMeta)
|
||||
{
|
||||
AEItemStack top = new AEItemStack( this );
|
||||
AEItemDef newDef = top.def = top.def.copy();
|
||||
|
||||
if ( ignoreMeta )
|
||||
{
|
||||
newDef.dspDamage = newDef.damageValue = Integer.MAX_VALUE;
|
||||
newDef.reHash();
|
||||
return top;
|
||||
}
|
||||
|
||||
if ( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
newDef.dspDamage = def.maxDamage + 1;
|
||||
|
@ -548,6 +562,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
|||
|
||||
public boolean isOre()
|
||||
{
|
||||
return def.isOre;
|
||||
return def.isOre != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ package appeng.util.item;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
@ -166,6 +168,13 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
return records.isEmpty();
|
||||
}
|
||||
|
||||
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 records.subMap( low, high ).values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StackType> findFuzzy(StackType filter, FuzzyMode fuzzy)
|
||||
{
|
||||
|
@ -174,14 +183,25 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
.asList( new IAEFluidStack[] {} );
|
||||
|
||||
AEItemStack ais = (AEItemStack) filter;
|
||||
|
||||
if ( OreHelper.instance.isOre( ais ) )
|
||||
if ( ais.isOre() )
|
||||
{
|
||||
OreRefrence or = ais.def.isOre;
|
||||
if ( or.aeotherOptions.size() == 1 )
|
||||
{
|
||||
IAEItemStack is = or.aeotherOptions.get( 0 );
|
||||
return findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<StackType> output = new LinkedList();
|
||||
|
||||
for (IAEItemStack is : or.aeotherOptions)
|
||||
output.addAll( findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
StackType low = (StackType) ais.getLow( fuzzy );
|
||||
StackType high = (StackType) ais.getHigh( fuzzy );
|
||||
return records.subMap( low, high ).values();
|
||||
return findFuzzyDamage( ais, fuzzy, false );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public class OreHelper
|
||||
|
@ -8,22 +13,144 @@ public class OreHelper
|
|||
|
||||
public static OreHelper instance = new OreHelper();
|
||||
|
||||
public boolean isOre(IAEItemStack is)
|
||||
class ItemRef
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
|
||||
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;
|
||||
set.add( oreItem.copy() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( add )
|
||||
ores.add( OreDictionary.getOreID( ore ) );
|
||||
}
|
||||
|
||||
if ( !set.isEmpty() )
|
||||
{
|
||||
or.oreValue = ref;
|
||||
|
||||
// SUMMON AE STACKS!
|
||||
for (ItemStack is : set)
|
||||
aeset.add( AEItemStack.create( is ) );
|
||||
}
|
||||
}
|
||||
|
||||
return or.oreValue;
|
||||
}
|
||||
|
||||
public boolean sameOre(AEItemStack aeItemStack, IAEItemStack is)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
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;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void sameOre(AEItemStack aeItemStack, ItemStack o)
|
||||
public boolean sameOre(OreRefrence a, OreRefrence b)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
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;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
32
util/item/OreRefrence.java
Normal file
32
util/item/OreRefrence.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public class OreRefrence
|
||||
{
|
||||
|
||||
LinkedList<ItemStack> otherOptions = new LinkedList();
|
||||
LinkedList<IAEItemStack> aeotherOptions = new LinkedList();
|
||||
HashSet<Integer> ores = new HashSet<Integer>();
|
||||
|
||||
public Collection<ItemStack> getEquivilients()
|
||||
{
|
||||
return otherOptions;
|
||||
}
|
||||
|
||||
public Collection<IAEItemStack> getAEEquivilients()
|
||||
{
|
||||
return aeotherOptions;
|
||||
}
|
||||
|
||||
public Collection<Integer> getOres()
|
||||
{
|
||||
return ores;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue