reformatted all src files (#141)
This commit is contained in:
@@ -30,22 +30,19 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class OreHelper
|
||||
{
|
||||
public class OreHelper {
|
||||
|
||||
public static final OreHelper INSTANCE = new OreHelper();
|
||||
|
||||
/**
|
||||
* A local cache to speed up OreDictionary lookups.
|
||||
*/
|
||||
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder.newBuilder().build( new CacheLoader<String, List<ItemStack>>()
|
||||
{
|
||||
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder.newBuilder().build(new CacheLoader<String, List<ItemStack>>() {
|
||||
@Override
|
||||
public List<ItemStack> load( final String oreName )
|
||||
{
|
||||
return OreDictionary.getOres( oreName );
|
||||
public List<ItemStack> load(final String oreName) {
|
||||
return OreDictionary.getOres(oreName);
|
||||
}
|
||||
} );
|
||||
});
|
||||
|
||||
private final Map<ItemRef, OreReference> references = new HashMap<>();
|
||||
|
||||
@@ -55,80 +52,64 @@ public class OreHelper
|
||||
* @param itemStack the itemstack to test
|
||||
* @return true if an ore entry exists, false otherwise
|
||||
*/
|
||||
public Optional<OreReference> getOre( final ItemStack itemStack )
|
||||
{
|
||||
final ItemRef ir = new ItemRef( itemStack );
|
||||
public Optional<OreReference> getOre(final ItemStack itemStack) {
|
||||
final 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();
|
||||
final Collection<String> set = ref.getEquivalents();
|
||||
|
||||
final Set<String> toAdd = new HashSet<>();
|
||||
|
||||
for( final String ore : OreDictionary.getOreNames() )
|
||||
{
|
||||
for (final 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( final ItemStack oreItem : this.oreDictCache.getUnchecked( ore ) )
|
||||
{
|
||||
if( OreDictionary.itemMatches( oreItem, itemStack, false ) )
|
||||
{
|
||||
toAdd.add( ore );
|
||||
for (final ItemStack oreItem : this.oreDictCache.getUnchecked(ore)) {
|
||||
if (OreDictionary.itemMatches(oreItem, itemStack, false)) {
|
||||
toAdd.add(ore);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final String ore : toAdd )
|
||||
{
|
||||
set.add( ore );
|
||||
ores.add( OreDictionary.getOreID( ore ) );
|
||||
for (final String ore : toAdd) {
|
||||
set.add(ore);
|
||||
ores.add(OreDictionary.getOreID(ore));
|
||||
}
|
||||
|
||||
if( !set.isEmpty() )
|
||||
{
|
||||
this.references.put( ir, ref );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.references.put( ir, null );
|
||||
if (!set.isEmpty()) {
|
||||
this.references.put(ir, ref);
|
||||
} else {
|
||||
this.references.put(ir, null);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.ofNullable( this.references.get( ir ) );
|
||||
return Optional.ofNullable(this.references.get(ir));
|
||||
}
|
||||
|
||||
boolean sameOre( final AEItemStack aeItemStack, final IAEItemStack is )
|
||||
{
|
||||
final OreReference a = aeItemStack.getOre().orElse( null );
|
||||
final OreReference b = ( (AEItemStack) is ).getOre().orElse( null );
|
||||
boolean sameOre(final AEItemStack aeItemStack, final IAEItemStack is) {
|
||||
final OreReference a = aeItemStack.getOre().orElse(null);
|
||||
final OreReference b = ((AEItemStack) is).getOre().orElse(null);
|
||||
|
||||
return this.sameOre( a, b );
|
||||
return this.sameOre(a, b);
|
||||
}
|
||||
|
||||
public boolean sameOre( final OreReference a, final OreReference b )
|
||||
{
|
||||
if( a == null || b == null )
|
||||
{
|
||||
public boolean sameOre(final OreReference a, final OreReference b) {
|
||||
if (a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( a == b )
|
||||
{
|
||||
if (a == b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Collection<Integer> bOres = b.getOres();
|
||||
for( final Integer ore : a.getOres() )
|
||||
{
|
||||
if( bOres.contains( ore ) )
|
||||
{
|
||||
for (final Integer ore : a.getOres()) {
|
||||
if (bOres.contains(ore)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -136,60 +117,47 @@ public class OreHelper
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean sameOre( final AEItemStack aeItemStack, final ItemStack o )
|
||||
{
|
||||
return aeItemStack.getOre().map( a -> {
|
||||
for( final String oreName : a.getEquivalents() )
|
||||
{
|
||||
for( final ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) )
|
||||
{
|
||||
if( OreDictionary.itemMatches( oreItem, o, false ) )
|
||||
{
|
||||
boolean sameOre(final AEItemStack aeItemStack, final ItemStack o) {
|
||||
return aeItemStack.getOre().map(a -> {
|
||||
for (final String oreName : a.getEquivalents()) {
|
||||
for (final ItemStack oreItem : this.oreDictCache.getUnchecked(oreName)) {
|
||||
if (OreDictionary.itemMatches(oreItem, o, false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} ).orElse( false );
|
||||
}).orElse(false);
|
||||
}
|
||||
|
||||
public Set<Integer> getMatchingOre( String oreExp )
|
||||
{
|
||||
public Set<Integer> getMatchingOre(String oreExp) {
|
||||
Set<Integer> matchingIds = new HashSet<>();
|
||||
|
||||
List<OreDictFilterMatcher.MatchRule> rulesList = OreDictFilterMatcher.parseExpression( oreExp );
|
||||
for( String ore : OreDictionary.getOreNames() )
|
||||
{
|
||||
if( OreDictFilterMatcher.matches( rulesList, ore ) )
|
||||
{
|
||||
matchingIds.add( OreDictionary.getOreID( ore ) );
|
||||
List<OreDictFilterMatcher.MatchRule> rulesList = OreDictFilterMatcher.parseExpression(oreExp);
|
||||
for (String ore : OreDictionary.getOreNames()) {
|
||||
if (OreDictFilterMatcher.matches(rulesList, ore)) {
|
||||
matchingIds.add(OreDictionary.getOreID(ore));
|
||||
}
|
||||
}
|
||||
return matchingIds;
|
||||
}
|
||||
|
||||
public List<ItemStack> getCachedOres( final String oreName )
|
||||
{
|
||||
return this.oreDictCache.getUnchecked( oreName );
|
||||
public List<ItemStack> getCachedOres(final String oreName) {
|
||||
return this.oreDictCache.getUnchecked(oreName);
|
||||
}
|
||||
|
||||
private static class ItemRef
|
||||
{
|
||||
private static class ItemRef {
|
||||
|
||||
private final Item ref;
|
||||
private final int damage;
|
||||
private final int hash;
|
||||
|
||||
ItemRef( final ItemStack stack )
|
||||
{
|
||||
ItemRef(final ItemStack stack) {
|
||||
this.ref = stack.getItem();
|
||||
|
||||
if( stack.getItem().isDamageable() )
|
||||
{
|
||||
if (stack.getItem().isDamageable()) {
|
||||
this.damage = 0; // IGNORED
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.damage = stack.getItemDamage(); // might be important...
|
||||
}
|
||||
|
||||
@@ -197,20 +165,16 @@ public class OreHelper
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if( obj == null )
|
||||
{
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if( this.getClass() != obj.getClass() )
|
||||
{
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final ItemRef other = (ItemRef) obj;
|
||||
@@ -218,8 +182,7 @@ public class OreHelper
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return "ItemRef [ref=" + this.ref.getUnlocalizedName() + ", damage=" + this.damage + ", hash=" + this.hash + ']';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user