reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
+262 -331
View File
@@ -18,13 +18,12 @@
package appeng.util.item;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.Api;
import appeng.util.Platform;
import com.google.common.primitives.Ints;
import gregtech.api.items.IToolItem;
import ic2.api.item.ICustomDamageItem;
@@ -37,385 +36,317 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.ItemHandlerHelper;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.Api;
import appeng.util.Platform;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
{
private static final String NBT_STACKSIZE = "Cnt";
private static final String NBT_REQUESTABLE = "Req";
private static final String NBT_CRAFTABLE = "Craft";
public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack {
private static final String NBT_STACKSIZE = "Cnt";
private static final String NBT_REQUESTABLE = "Req";
private static final String NBT_CRAFTABLE = "Craft";
private final AESharedItemStack sharedStack;
private Optional<OreReference> oreReference;
private final AESharedItemStack sharedStack;
private final Optional<OreReference> oreReference;
@SideOnly( Side.CLIENT )
private String displayName;
@SideOnly( Side.CLIENT )
private List<String> tooltip;
private ItemStack cachedItemStack;
@SideOnly(Side.CLIENT)
private String displayName;
@SideOnly(Side.CLIENT)
private List<String> tooltip;
private ItemStack cachedItemStack;
private AEItemStack( final AEItemStack is )
{
this.setStackSize( is.getStackSize() );
this.setCraftable( is.isCraftable() );
this.setCountRequestable( is.getCountRequestable() );
this.sharedStack = is.sharedStack;
this.oreReference = is.oreReference;
this.cachedItemStack = is.cachedItemStack;
}
private AEItemStack(final AEItemStack is) {
this.setStackSize(is.getStackSize());
this.setCraftable(is.isCraftable());
this.setCountRequestable(is.getCountRequestable());
this.sharedStack = is.sharedStack;
this.oreReference = is.oreReference;
this.cachedItemStack = is.cachedItemStack;
}
private AEItemStack( final AESharedItemStack is, long size )
{
this.sharedStack = is;
this.setStackSize( size );
this.setCraftable( false );
this.setCountRequestable( 0 );
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
}
private AEItemStack(final AESharedItemStack is, long size) {
this.sharedStack = is;
this.setStackSize(size);
this.setCraftable(false);
this.setCountRequestable(0);
this.oreReference = OreHelper.INSTANCE.getOre(is.getDefinition());
}
@Nullable
public static AEItemStack fromItemStack( @Nonnull final ItemStack stack )
{
if( stack.isEmpty() )
{
return null;
}
@Nullable
public static AEItemStack fromItemStack(@Nonnull final ItemStack stack) {
if (stack.isEmpty()) {
return null;
}
return new AEItemStack( AEItemStackRegistry.getRegisteredStack( stack ), stack.getCount() );
}
return new AEItemStack(AEItemStackRegistry.getRegisteredStack(stack), stack.getCount());
}
public static IAEItemStack fromNBT( final NBTTagCompound i )
{
if( i == null )
{
return null;
}
public static IAEItemStack fromNBT(final NBTTagCompound i) {
if (i == null) {
return null;
}
final ItemStack itemstack = new ItemStack( i );
if( itemstack.isEmpty() )
{
return null;
}
final ItemStack itemstack = new ItemStack(i);
if (itemstack.isEmpty()) {
return null;
}
final AEItemStack item = AEItemStack.fromItemStack( itemstack );
final AEItemStack item = AEItemStack.fromItemStack(itemstack);
item.setStackSize( i.getLong( NBT_STACKSIZE ) );
item.setCountRequestable( i.getLong( NBT_REQUESTABLE ) );
item.setCraftable( i.getBoolean( NBT_CRAFTABLE ) );
return item;
}
item.setStackSize(i.getLong(NBT_STACKSIZE));
item.setCountRequestable(i.getLong(NBT_REQUESTABLE));
item.setCraftable(i.getBoolean(NBT_CRAFTABLE));
return item;
}
@Override
public void writeToNBT( final NBTTagCompound i )
{
this.getDefinition().writeToNBT( i );
@Override
public void writeToNBT(final NBTTagCompound i) {
this.getDefinition().writeToNBT(i);
i.setLong( NBT_STACKSIZE, this.getStackSize() );
i.setLong( NBT_REQUESTABLE, this.getCountRequestable() );
i.setBoolean( NBT_CRAFTABLE, this.isCraftable() );
}
i.setLong(NBT_STACKSIZE, this.getStackSize());
i.setLong(NBT_REQUESTABLE, this.getCountRequestable());
i.setBoolean(NBT_CRAFTABLE, this.isCraftable());
}
public static AEItemStack fromPacket( final ByteBuf data )
{
final byte mask = data.readByte();
final byte stackType = (byte) ( ( mask & 0x0C ) >> 2 );
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
final boolean isCraftable = ( mask & 0x40 ) > 0;
public static AEItemStack fromPacket(final ByteBuf data) {
final byte mask = data.readByte();
final byte stackType = (byte) ((mask & 0x0C) >> 2);
final byte countReqType = (byte) ((mask & 0x30) >> 4);
final boolean isCraftable = (mask & 0x40) > 0;
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
final long stackSize = getPacketValue( stackType, data );
final long countRequestable = getPacketValue( countReqType, data );
final ItemStack itemstack = new ItemStack(ByteBufUtils.readTag(data));
final long stackSize = getPacketValue(stackType, data);
final long countRequestable = getPacketValue(countReqType, data);
if( itemstack.isEmpty() )
{
return null;
}
if (itemstack.isEmpty()) {
return null;
}
final AEItemStack item = new AEItemStack( AEItemStackRegistry.getRegisteredStack( itemstack ), stackSize );
item.setCountRequestable( countRequestable );
item.setCraftable( isCraftable );
return item;
}
final AEItemStack item = new AEItemStack(AEItemStackRegistry.getRegisteredStack(itemstack), stackSize);
item.setCountRequestable(countRequestable);
item.setCraftable(isCraftable);
return item;
}
@Override
public void writeToPacket( final ByteBuf i )
{
final byte mask = (byte) ( ( this.getType( this.getStackSize() ) << 2 ) | ( this.getType( this.getCountRequestable() ) << 4 ) | ( (byte) ( this.isCraftable() ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
@Override
public void writeToPacket(final ByteBuf i) {
final byte mask = (byte) ((this.getType(this.getStackSize()) << 2) | (this.getType(this.getCountRequestable()) << 4) | ((byte) (this.isCraftable() ? 1 : 0) << 6) | (this.hasTagCompound() ? 1 : 0) << 7);
i.writeByte( mask );
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
this.putPacketValue( i, this.getStackSize() );
this.putPacketValue( i, this.getCountRequestable() );
}
i.writeByte(mask);
ByteBufUtils.writeTag(i, this.getDefinition().serializeNBT());
this.putPacketValue(i, this.getStackSize());
this.putPacketValue(i, this.getCountRequestable());
}
@Override
public void add( final IAEItemStack option )
{
if( option == null )
{
return;
}
@Override
public void add(final IAEItemStack option) {
if (option == null) {
return;
}
this.incStackSize( option.getStackSize() );
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
this.setCraftable( this.isCraftable() || option.isCraftable() );
}
this.incStackSize(option.getStackSize());
this.setCountRequestable(this.getCountRequestable() + option.getCountRequestable());
this.setCraftable(this.isCraftable() || option.isCraftable());
}
@Override
public boolean fuzzyComparison( final IAEItemStack other, final FuzzyMode mode )
{
final ItemStack itemStack = this.getDefinition();
final ItemStack otherStack = other.getDefinition();
@Override
public boolean fuzzyComparison(final IAEItemStack other, final FuzzyMode mode) {
final ItemStack itemStack = this.getDefinition();
final ItemStack otherStack = other.getDefinition();
return this.fuzzyItemStackComparison( itemStack, otherStack, mode );
}
return this.fuzzyItemStackComparison(itemStack, otherStack, mode);
}
@Override
public IAEItemStack copy()
{
return new AEItemStack( this );
}
@Override
public IAEItemStack copy() {
return new AEItemStack(this);
}
@Override
public boolean isItem()
{
return true;
}
@Override
public boolean isItem() {
return true;
}
@Override
public boolean isFluid()
{
return false;
}
@Override
public boolean isFluid() {
return false;
}
@Override
public IStorageChannel<IAEItemStack> getChannel()
{
return Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
public IStorageChannel<IAEItemStack> getChannel() {
return Api.INSTANCE.storage().getStorageChannel(IItemStorageChannel.class);
}
@Override
public ItemStack createItemStack()
{
return ItemHandlerHelper.copyStackWithSize( this.getDefinition(), (int) Math.min( Integer.MAX_VALUE, this.getStackSize() ) );
}
@Override
public ItemStack createItemStack() {
return ItemHandlerHelper.copyStackWithSize(this.getDefinition(), (int) Math.min(Integer.MAX_VALUE, this.getStackSize()));
}
@Override
public Item getItem()
{
return this.getDefinition().getItem();
}
@Override
public Item getItem() {
return this.getDefinition().getItem();
}
@Override
public int getItemDamage()
{
return this.sharedStack.getItemDamage();
}
@Override
public int getItemDamage() {
return this.sharedStack.getItemDamage();
}
@Override
public boolean sameOre( final IAEItemStack is )
{
return OreHelper.INSTANCE.sameOre( this, is );
}
@Override
public boolean sameOre(final IAEItemStack is) {
return OreHelper.INSTANCE.sameOre(this, is);
}
@Override
public boolean isSameType( final IAEItemStack otherStack )
{
if( otherStack == null )
{
return false;
}
@Override
public boolean isSameType(final IAEItemStack otherStack) {
if (otherStack == null) {
return false;
}
return Objects.equals( this.sharedStack, ( (AEItemStack) otherStack ).sharedStack );
}
return Objects.equals(this.sharedStack, ((AEItemStack) otherStack).sharedStack);
}
@Override
public boolean isSameType( final ItemStack otherStack )
{
if( otherStack.isEmpty() )
{
return false;
}
int oldSize = otherStack.getCount();
@Override
public boolean isSameType(final ItemStack otherStack) {
if (otherStack.isEmpty()) {
return false;
}
int oldSize = otherStack.getCount();
otherStack.setCount( 1 );
boolean ret = ItemStack.areItemStacksEqual( this.getDefinition(), otherStack );
otherStack.setCount( oldSize );
otherStack.setCount(1);
boolean ret = ItemStack.areItemStacksEqual(this.getDefinition(), otherStack);
otherStack.setCount(oldSize);
return ret;
}
return ret;
}
@Override
public int hashCode()
{
return this.sharedStack.hashCode();
}
@Override
public int hashCode() {
return this.sharedStack.hashCode();
}
@Override
public boolean equals( final Object ia )
{
if( ia instanceof AEItemStack )
{
return this.isSameType( (AEItemStack) ia );
}
else if( ia instanceof ItemStack )
{
// this actually breaks the equals contract (being equals to unrelated classes)
return equals( (ItemStack) ia );
}
return false;
}
@Override
public boolean equals(final Object ia) {
if (ia instanceof AEItemStack) {
return this.isSameType((AEItemStack) ia);
} else if (ia instanceof ItemStack) {
// this actually breaks the equals contract (being equals to unrelated classes)
return equals((ItemStack) ia);
}
return false;
}
@Override
public boolean equals( final ItemStack is )
{
return this.isSameType( is );
}
@Override
public boolean equals(final ItemStack is) {
return this.isSameType(is);
}
@Override
public ItemStack getCachedItemStack( long stackSize )
{
if( this.cachedItemStack != null )
{
ItemStack currentCached = this.cachedItemStack;
this.cachedItemStack = null;
currentCached.setCount( Ints.saturatedCast( stackSize ) );
return currentCached;
}
@Override
public ItemStack getCachedItemStack(long stackSize) {
if (this.cachedItemStack != null) {
ItemStack currentCached = this.cachedItemStack;
this.cachedItemStack = null;
currentCached.setCount(Ints.saturatedCast(stackSize));
return currentCached;
}
ItemStack itemStack = this.createItemStack();
itemStack.setCount( Ints.saturatedCast( stackSize ) );
ItemStack itemStack = this.createItemStack();
itemStack.setCount(Ints.saturatedCast(stackSize));
return itemStack;
}
return itemStack;
}
@Override
public void setCachedItemStack( ItemStack itemStack )
{
this.cachedItemStack = itemStack;
}
@Override
public void setCachedItemStack(ItemStack itemStack) {
this.cachedItemStack = itemStack;
}
@Override
public String toString()
{
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
}
@Override
public String toString() {
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
}
@SideOnly( Side.CLIENT )
public List<String> getToolTip()
{
if( this.tooltip == null )
{
this.tooltip = Platform.getTooltip( this.asItemStackRepresentation() );
}
return this.tooltip;
}
@SideOnly(Side.CLIENT)
public List<String> getToolTip() {
if (this.tooltip == null) {
this.tooltip = Platform.getTooltip(this.asItemStackRepresentation());
}
return this.tooltip;
}
@SideOnly( Side.CLIENT )
public String getDisplayName()
{
if( this.displayName == null )
{
this.displayName = Platform.getItemDisplayName( this.asItemStackRepresentation() );
}
return this.displayName;
}
@SideOnly(Side.CLIENT)
public String getDisplayName() {
if (this.displayName == null) {
this.displayName = Platform.getItemDisplayName(this.asItemStackRepresentation());
}
return this.displayName;
}
@SideOnly( Side.CLIENT )
public String getModID()
{
return this.getDefinition().getItem().getRegistryName().getResourceDomain();
}
@SideOnly(Side.CLIENT)
public String getModID() {
return this.getDefinition().getItem().getRegistryName().getResourceDomain();
}
public Optional<OreReference> getOre()
{
return this.oreReference;
}
public Optional<OreReference> getOre() {
return this.oreReference;
}
@Override
public boolean hasTagCompound()
{
return this.getDefinition().hasTagCompound();
}
@Override
public boolean hasTagCompound() {
return this.getDefinition().hasTagCompound();
}
@Override
public ItemStack asItemStackRepresentation()
{
return this.getDefinition().copy();
}
@Override
public ItemStack asItemStackRepresentation() {
return this.getDefinition().copy();
}
@Override
public ItemStack getDefinition()
{
return this.sharedStack.getDefinition();
}
@Override
public ItemStack getDefinition() {
return this.sharedStack.getDefinition();
}
AESharedItemStack getSharedStack()
{
return this.sharedStack;
}
AESharedItemStack getSharedStack() {
return this.sharedStack;
}
private boolean fuzzyItemStackComparison( ItemStack a, ItemStack b, FuzzyMode mode )
{
if( a.getItem() == b.getItem() && ( a.getItem().isDamageable() || Platform.isGTDamageableItem( a.getItem() ) ) )
{
if( mode == FuzzyMode.IGNORE_ALL )
{
if( a.getItem().isDamageable() )
{
return true;
}
else if( Platform.isGTDamageableItem( a.getItem() ) )
{
return a.getItemDamage() == b.getItemDamage();
}
}
else if( mode == FuzzyMode.PERCENT_99 )
{
if( Platform.isIC2DamageableItem( a.getItem() ) )
{
return ( (ICustomDamageItem) a.getItem() ).getCustomDamage( a ) > 1 == ( (ICustomDamageItem) b.getItem() ).getCustomDamage( b ) > 1;
}
else if( a.getItem().isDamageable() )
{
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
}
else if( Platform.isGTDamageableItem( a.getItem() ) )
{
return ( (IToolItem) a.getItem() ).getItemDamage( a ) > 1 == ( (IToolItem) b.getItem() ).getItemDamage( b ) > 1;
}
}
else
{
float percentDamageOfA = 0;
float percentDamageOfB = 0;
if( Platform.isIC2DamageableItem( a.getItem() ) )
{
percentDamageOfA = (float) ( (ICustomDamageItem) a.getItem() ).getCustomDamage( a ) / ( (ICustomDamageItem) a.getItem() ).getMaxCustomDamage( a );
percentDamageOfB = (float) ( (ICustomDamageItem) b.getItem() ).getCustomDamage( b ) / ( (ICustomDamageItem) b.getItem() ).getMaxCustomDamage( b );
}
else if( a.getItem().isDamageable() )
{
percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
}
else if( Platform.isGTDamageableItem( a.getItem() ) )
{
percentDamageOfA = (float) ( (IToolItem) a.getItem() ).getItemDamage( a ) / ( (IToolItem) a.getItem() ).getMaxItemDamage( a );
percentDamageOfB = (float) ( (IToolItem) b.getItem() ).getItemDamage( b ) / ( (IToolItem) b.getItem() ).getMaxItemDamage( b );
}
private boolean fuzzyItemStackComparison(ItemStack a, ItemStack b, FuzzyMode mode) {
if (a.getItem() == b.getItem() && (a.getItem().isDamageable() || Platform.isGTDamageableItem(a.getItem()))) {
if (mode == FuzzyMode.IGNORE_ALL) {
if (a.getItem().isDamageable()) {
return true;
} else if (Platform.isGTDamageableItem(a.getItem())) {
return a.getItemDamage() == b.getItemDamage();
}
} else if (mode == FuzzyMode.PERCENT_99) {
if (Platform.isIC2DamageableItem(a.getItem())) {
return ((ICustomDamageItem) a.getItem()).getCustomDamage(a) > 1 == ((ICustomDamageItem) b.getItem()).getCustomDamage(b) > 1;
} else if (a.getItem().isDamageable()) {
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
} else if (Platform.isGTDamageableItem(a.getItem())) {
return ((IToolItem) a.getItem()).getItemDamage(a) > 1 == ((IToolItem) b.getItem()).getItemDamage(b) > 1;
}
} else {
float percentDamageOfA = 0;
float percentDamageOfB = 0;
if (Platform.isIC2DamageableItem(a.getItem())) {
percentDamageOfA = (float) ((ICustomDamageItem) a.getItem()).getCustomDamage(a) / ((ICustomDamageItem) a.getItem()).getMaxCustomDamage(a);
percentDamageOfB = (float) ((ICustomDamageItem) b.getItem()).getCustomDamage(b) / ((ICustomDamageItem) b.getItem()).getMaxCustomDamage(b);
} else if (a.getItem().isDamageable()) {
percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
} else if (Platform.isGTDamageableItem(a.getItem())) {
percentDamageOfA = (float) ((IToolItem) a.getItem()).getItemDamage(a) / ((IToolItem) a.getItem()).getMaxItemDamage(a);
percentDamageOfB = (float) ((IToolItem) b.getItem()).getItemDamage(b) / ((IToolItem) b.getItem()).getMaxItemDamage(b);
}
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
}
}
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
}
}
return false;
}
return false;
}
}
@@ -23,12 +23,11 @@
package appeng.util.item;
import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
public final class AEItemStackRegistry {
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> REGISTRY = new WeakHashMap<>();
@@ -18,82 +18,70 @@
package appeng.util.item;
import java.util.Objects;
import com.google.common.base.Preconditions;
import net.minecraft.item.ItemStack;
import java.util.Objects;
final class AESharedItemStack
{
private final ItemStack itemStack;
private final int itemDamage;
private final int hashCode;
final class AESharedItemStack {
public AESharedItemStack( final ItemStack itemStack )
{
this( itemStack, itemStack.getItemDamage() );
}
private final ItemStack itemStack;
private final int itemDamage;
private final int hashCode;
/**
* A constructor to explicitly set the damage value and not fetch it from the {@link ItemStack}
*
* @param itemStack The {@link ItemStack} to filter
* @param damage The damage of the item
*/
private AESharedItemStack( ItemStack itemStack, int damage )
{
this.itemStack = itemStack;
this.itemDamage = damage;
public AESharedItemStack(final ItemStack itemStack) {
this(itemStack, itemStack.getItemDamage());
}
// Ensure this is always called last.
this.hashCode = this.makeHashCode();
}
/**
* A constructor to explicitly set the damage value and not fetch it from the {@link ItemStack}
*
* @param itemStack The {@link ItemStack} to filter
* @param damage The damage of the item
*/
private AESharedItemStack(ItemStack itemStack, int damage) {
this.itemStack = itemStack;
this.itemDamage = damage;
ItemStack getDefinition()
{
return this.itemStack;
}
// Ensure this is always called last.
this.hashCode = this.makeHashCode();
}
int getItemDamage()
{
return this.itemDamage;
}
ItemStack getDefinition() {
return this.itemStack;
}
@Override
public int hashCode()
{
return this.hashCode;
}
int getItemDamage() {
return this.itemDamage;
}
@Override
public boolean equals( final Object obj )
{
if( this == obj )
{
return true;
}
if( !( obj instanceof AESharedItemStack ) )
{
return false;
}
@Override
public int hashCode() {
return this.hashCode;
}
final AESharedItemStack other = (AESharedItemStack) obj;
Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" );
Preconditions.checkArgument( other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" );
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof AESharedItemStack)) {
return false;
}
if( this.itemStack == other.itemStack )
{
return true;
}
return ItemStack.areItemStacksEqual( this.itemStack, other.itemStack );
}
final AESharedItemStack other = (AESharedItemStack) obj;
Preconditions.checkState(this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1");
Preconditions.checkArgument(other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1");
private int makeHashCode()
{
return Objects.hash( this.itemStack.getItem(), this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
}
if (this.itemStack == other.itemStack) {
return true;
}
return ItemStack.areItemStacksEqual(this.itemStack, other.itemStack);
}
private int makeHashCode() {
return Objects.hash(this.itemStack.getItem(), this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0);
}
}
+18 -40
View File
@@ -28,22 +28,16 @@ public abstract class AEStack<T extends IAEStack<T>> implements IAEStack<T> {
private long stackSize;
private long countRequestable;
protected static long getPacketValue( final byte type, final ByteBuf tag )
{
if( type == 0 )
{
protected static long getPacketValue(final byte type, final ByteBuf tag) {
if (type == 0) {
long l = tag.readByte();
l -= Byte.MIN_VALUE;
return l;
}
else if( type == 1 )
{
} else if (type == 1) {
long l = tag.readShort();
l -= Short.MIN_VALUE;
return l;
}
else if( type == 2 )
{
} else if (type == 2) {
long l = tag.readInt();
l -= Integer.MIN_VALUE;
return l;
@@ -125,45 +119,29 @@ public abstract class AEStack<T extends IAEStack<T>> implements IAEStack<T> {
this.countRequestable -= i;
}
protected byte getType( final long num )
{
if( num <= 255 )
{
protected byte getType(final long num) {
if (num <= 255) {
return 0;
}
else if( num <= 65535 )
{
} else if (num <= 65535) {
return 1;
}
else if( num <= 4294967295L )
{
} else if (num <= 4294967295L) {
return 2;
}
else
{
} else {
return 3;
}
}
protected abstract boolean hasTagCompound();
protected void putPacketValue( final ByteBuf tag, final 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 );
protected void putPacketValue(final ByteBuf tag, final 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);
}
}
}
@@ -18,227 +18,189 @@
package appeng.util.item;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.Platform;
import com.google.common.base.Preconditions;
import gregtech.api.items.IToolItem;
import ic2.api.item.ICustomDamageItem;
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
import net.minecraft.item.ItemStack;
import java.util.Collection;
import java.util.Comparator;
import java.util.Map;
import appeng.util.Platform;
import com.google.common.base.Preconditions;
import gregtech.api.items.IToolItem;
import ic2.api.item.ICustomDamageItem;
import net.minecraft.item.ItemStack;
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
/**
* This variant list is optimized for damageable items, and supports selecting durability ranges with
* {@link #findFuzzy(IAEItemStack, FuzzyMode)}.
*/
class FuzzyItemVariantList extends ItemVariantList
{
class FuzzyItemVariantList extends ItemVariantList {
static final SharedStackComparator COMPARATOR = new SharedStackComparator();
static final SharedStackComparator COMPARATOR = new SharedStackComparator();
// NOTE: We only use Object as they key here so we can pass our special DamageBounds to the subMap method.
// We NEVER put any keys in this map that are not AESharedItemStacks.
private final Object2ObjectSortedMap<Object, IAEItemStack> records = new Object2ObjectAVLTreeMap<>( COMPARATOR );
// NOTE: We only use Object as they key here so we can pass our special DamageBounds to the subMap method.
// We NEVER put any keys in this map that are not AESharedItemStacks.
private final Object2ObjectSortedMap<Object, IAEItemStack> records = new Object2ObjectAVLTreeMap<>(COMPARATOR);
@Override
public Collection<IAEItemStack> findFuzzy( final IAEItemStack filter, final FuzzyMode fuzzy )
{
ItemStack itemStack = filter.getDefinition();
@Override
public Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy) {
ItemStack itemStack = filter.getDefinition();
ItemDamageBound lowerBound = makeLowerBound( itemStack, fuzzy );
ItemDamageBound upperBound = makeUpperBound( itemStack, fuzzy );
Preconditions.checkState( lowerBound.itemDamage > upperBound.itemDamage );
ItemDamageBound lowerBound = makeLowerBound(itemStack, fuzzy);
ItemDamageBound upperBound = makeUpperBound(itemStack, fuzzy);
Preconditions.checkState(lowerBound.itemDamage > upperBound.itemDamage);
return this.records.subMap( lowerBound, upperBound ).values();
}
return this.records.subMap(lowerBound, upperBound).values();
}
@SuppressWarnings( "unchecked" )
@Override
Map<AESharedItemStack, IAEItemStack> getRecords()
{
// We ensure on our end that we NEVER use anything but AESharedItemStack as the key in this map
return (Map<AESharedItemStack, IAEItemStack>) (Object) this.records;
}
@SuppressWarnings("unchecked")
@Override
Map<AESharedItemStack, IAEItemStack> getRecords() {
// We ensure on our end that we NEVER use anything but AESharedItemStack as the key in this map
return (Map<AESharedItemStack, IAEItemStack>) (Object) this.records;
}
static class ItemDamageBound
{
final int itemDamage;
static class ItemDamageBound {
final int itemDamage;
public ItemDamageBound( int itemDamage )
{
this.itemDamage = itemDamage;
}
}
public ItemDamageBound(int itemDamage) {
this.itemDamage = itemDamage;
}
}
/**
* This comparator creates a strict and total ordering over all {@link AESharedItemStack} of the same item. To
* support selecting ranges of durability, it is defined for type {@link Object} and also accepts
* {@link ItemDamageBound} as an argument to compare against.
*/
static class SharedStackComparator implements Comparator<Object>
{
@Override
public int compare( Object a, Object b )
{
// Either argument can either be a damage bound or a shared item stack
// Since we never put damage bounds into the map as keys, only one
// of the two arguments can possibly be a bound
ItemDamageBound boundA = null;
AESharedItemStack stackA = null;
int itemDamageA;
if( a instanceof ItemDamageBound )
{
boundA = (ItemDamageBound) a;
itemDamageA = boundA.itemDamage;
}
else
{
stackA = (AESharedItemStack) a;
itemDamageA = stackA.getItemDamage();
}
ItemDamageBound boundB = null;
AESharedItemStack stackB = null;
int itemDamageB;
if( b instanceof ItemDamageBound )
{
boundB = (ItemDamageBound) b;
itemDamageB = boundB.itemDamage;
}
else
{
stackB = (AESharedItemStack) b;
itemDamageB = stackB.getItemDamage();
}
/**
* This comparator creates a strict and total ordering over all {@link AESharedItemStack} of the same item. To
* support selecting ranges of durability, it is defined for type {@link Object} and also accepts
* {@link ItemDamageBound} as an argument to compare against.
*/
static class SharedStackComparator implements Comparator<Object> {
@Override
public int compare(Object a, Object b) {
// Either argument can either be a damage bound or a shared item stack
// Since we never put damage bounds into the map as keys, only one
// of the two arguments can possibly be a bound
ItemDamageBound boundA = null;
AESharedItemStack stackA = null;
int itemDamageA;
if (a instanceof ItemDamageBound) {
boundA = (ItemDamageBound) a;
itemDamageA = boundA.itemDamage;
} else {
stackA = (AESharedItemStack) a;
itemDamageA = stackA.getItemDamage();
}
ItemDamageBound boundB = null;
AESharedItemStack stackB = null;
int itemDamageB;
if (b instanceof ItemDamageBound) {
boundB = (ItemDamageBound) b;
itemDamageB = boundB.itemDamage;
} else {
stackB = (AESharedItemStack) b;
itemDamageB = stackB.getItemDamage();
}
// When either argument is a damage bound, we just compare the damage values because it is used
// only to get a certain damage range out of the map.
if( boundA != null || boundB != null )
{
return Integer.compare( itemDamageB, itemDamageA );
}
// When either argument is a damage bound, we just compare the damage values because it is used
// only to get a certain damage range out of the map.
if (boundA != null || boundB != null) {
return Integer.compare(itemDamageB, itemDamageA);
}
ItemStack itemStackA = stackA.getDefinition();
ItemStack itemStackB = stackB.getDefinition();
Preconditions.checkState( itemStackA.getCount() == 1, "ItemStack#getCount() has to be 1" );
Preconditions.checkArgument( itemStackB.getCount() == 1, "ItemStack#getCount() has to be 1" );
ItemStack itemStackA = stackA.getDefinition();
ItemStack itemStackB = stackB.getDefinition();
Preconditions.checkState(itemStackA.getCount() == 1, "ItemStack#getCount() has to be 1");
Preconditions.checkArgument(itemStackB.getCount() == 1, "ItemStack#getCount() has to be 1");
if( itemStackA == itemStackB )
{
return 0;
}
if (itemStackA == itemStackB) {
return 0;
}
// Damaged items are sorted before undamaged items
final int damageValue = Integer.compare( itemDamageB, itemDamageA );
if( damageValue != 0 )
{
return damageValue;
}
// Damaged items are sorted before undamaged items
final int damageValue = Integer.compare(itemDamageB, itemDamageA);
if (damageValue != 0) {
return damageValue;
}
// As a final tie breaker, order by the object identity of the item stack
// While this will order seemingly at random, we only need the order of
// damage values to be predictable, while still having to satisfy the
// complete order requirements of the sorted map
return Long.compare( System.identityHashCode( itemStackA ), System.identityHashCode( itemStackB ) );
}
}
// As a final tie breaker, order by the object identity of the item stack
// While this will order seemingly at random, we only need the order of
// damage values to be predictable, while still having to satisfy the
// complete order requirements of the sorted map
return Long.compare(System.identityHashCode(itemStackA), System.identityHashCode(itemStackB));
}
}
/**
* Minecraft reverses the damage values. So anything with a damage of 0 is undamaged and increases the more damaged
* the item is.
* <p>
* Further the used subMap follows [MAX_DAMAGE, MIN_DAMAGE), so to include undamaged items, we have to start with a
* lower damage value than 0, while it is fine to use {@link ItemStack#getMaxDamage()} for the upper bound.
*/
private static final int MIN_DAMAGE_VALUE = -1;
/**
* Minecraft reverses the damage values. So anything with a damage of 0 is undamaged and increases the more damaged
* the item is.
* <p>
* Further the used subMap follows [MAX_DAMAGE, MIN_DAMAGE), so to include undamaged items, we have to start with a
* lower damage value than 0, while it is fine to use {@link ItemStack#getMaxDamage()} for the upper bound.
*/
private static final int MIN_DAMAGE_VALUE = -1;
/*
* Keep in mind that the stack order is from most damaged to least damaged, so this lower bound will actually be a
* higher number than the upper bound.
*/
static ItemDamageBound makeLowerBound( final ItemStack stack, final FuzzyMode fuzzy )
{
Preconditions.checkState( stack.getItem().isDamageable() || ( Platform.isGTDamageableItem( stack.getItem() ) ), "Item#isDamageable() has to be true" );
/*
* Keep in mind that the stack order is from most damaged to least damaged, so this lower bound will actually be a
* higher number than the upper bound.
*/
static ItemDamageBound makeLowerBound(final ItemStack stack, final FuzzyMode fuzzy) {
Preconditions.checkState(stack.getItem().isDamageable() || (Platform.isGTDamageableItem(stack.getItem())), "Item#isDamageable() has to be true");
int damage;
int maxDamage;
if( Platform.isIC2DamageableItem( stack.getItem() ) )
{
maxDamage = ( (ICustomDamageItem) stack.getItem() ).getMaxCustomDamage( stack );
damage = ( (ICustomDamageItem) stack.getItem() ).getCustomDamage( stack );
}
else if( Platform.isGTDamageableItem( stack.getItem() ) )
{
maxDamage = ( (IToolItem) stack.getItem() ).getMaxItemDamage( stack );
damage = ( (IToolItem) stack.getItem() ).getItemDamage( stack );
}
else
{
maxDamage = stack.getMaxDamage();
damage = stack.getItemDamage();
}
int damage;
int maxDamage;
if (Platform.isIC2DamageableItem(stack.getItem())) {
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
} else if (Platform.isGTDamageableItem(stack.getItem())) {
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
} else {
maxDamage = stack.getMaxDamage();
damage = stack.getItemDamage();
}
if( fuzzy == FuzzyMode.IGNORE_ALL )
{
if( maxDamage != 0 )
{
damage = maxDamage;
}
}
else
{
final int breakpoint = fuzzy.calculateBreakPoint( maxDamage );
damage = damage <= breakpoint ? breakpoint : maxDamage;
}
if (fuzzy == FuzzyMode.IGNORE_ALL) {
if (maxDamage != 0) {
damage = maxDamage;
}
} else {
final int breakpoint = fuzzy.calculateBreakPoint(maxDamage);
damage = damage <= breakpoint ? breakpoint : maxDamage;
}
return new ItemDamageBound( damage );
}
return new ItemDamageBound(damage);
}
/*
* Keep in mind that the stack order is from most damaged to least damaged, so this upper bound will actually be a
* lower number than the lower bound. It also is exclusive.
*/
static ItemDamageBound makeUpperBound( final ItemStack stack, final FuzzyMode fuzzy )
{
Preconditions.checkState( stack.getItem().isDamageable() || ( Platform.isGTDamageableItem( stack.getItem() ) ), "Item#isDamageable() has to be true" );
/*
* Keep in mind that the stack order is from most damaged to least damaged, so this upper bound will actually be a
* lower number than the lower bound. It also is exclusive.
*/
static ItemDamageBound makeUpperBound(final ItemStack stack, final FuzzyMode fuzzy) {
Preconditions.checkState(stack.getItem().isDamageable() || (Platform.isGTDamageableItem(stack.getItem())), "Item#isDamageable() has to be true");
int damage;
if( fuzzy == FuzzyMode.IGNORE_ALL )
{
damage = MIN_DAMAGE_VALUE;
}
else
{
int maxDamage;
if( Platform.isIC2DamageableItem( stack.getItem() ) )
{
maxDamage = ( (ICustomDamageItem) stack.getItem() ).getMaxCustomDamage( stack );
damage = ( (ICustomDamageItem) stack.getItem() ).getCustomDamage( stack );
}
else if( Platform.isGTDamageableItem( stack.getItem() ) )
{
maxDamage = ( (IToolItem) stack.getItem() ).getMaxItemDamage( stack );
damage = ( (IToolItem) stack.getItem() ).getItemDamage( stack );
}
else
{
maxDamage = stack.getMaxDamage();
damage = stack.getItemDamage();
}
int damage;
if (fuzzy == FuzzyMode.IGNORE_ALL) {
damage = MIN_DAMAGE_VALUE;
} else {
int maxDamage;
if (Platform.isIC2DamageableItem(stack.getItem())) {
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
} else if (Platform.isGTDamageableItem(stack.getItem())) {
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
} else {
maxDamage = stack.getMaxDamage();
damage = stack.getItemDamage();
}
final int breakpoint = fuzzy.calculateBreakPoint( maxDamage );
damage = damage <= breakpoint ? MIN_DAMAGE_VALUE : breakpoint;
}
final int breakpoint = fuzzy.calculateBreakPoint(maxDamage);
damage = damage <= breakpoint ? MIN_DAMAGE_VALUE : breakpoint;
}
return new ItemDamageBound( damage );
}
return new ItemDamageBound(damage);
}
}
+147 -189
View File
@@ -18,234 +18,192 @@
package appeng.util.item;
import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;
import appeng.util.Platform;
import net.minecraft.item.Item;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.util.Platform;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import net.minecraft.item.Item;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public final class ItemList implements IItemList<IAEItemStack>
{
public final class ItemList implements IItemList<IAEItemStack> {
private final Reference2ObjectMap<Item, ItemVariantList> records = new Reference2ObjectOpenHashMap<>();
/**
* We increment this version field everytime an attempt to mutate this item list (or potentially one of its
* sub-lists) is made. Iterators will copy the version when they are created and compare it against the current
* version whenever they advance to trigger a {@link ConcurrentModificationException}.
*/
private final AtomicInteger version = new AtomicInteger( 0 );
private final Reference2ObjectMap<Item, ItemVariantList> records = new Reference2ObjectOpenHashMap<>();
/**
* We increment this version field everytime an attempt to mutate this item list (or potentially one of its
* sub-lists) is made. Iterators will copy the version when they are created and compare it against the current
* version whenever they advance to trigger a {@link ConcurrentModificationException}.
*/
private final AtomicInteger version = new AtomicInteger(0);
@Override
public IAEItemStack findPrecise( final IAEItemStack itemStack )
{
if( itemStack == null )
{
return null;
}
@Override
public IAEItemStack findPrecise(final IAEItemStack itemStack) {
if (itemStack == null) {
return null;
}
ItemVariantList record = this.records.get( itemStack.getItem() );
return record != null ? record.findPrecise( itemStack ) : null;
}
ItemVariantList record = this.records.get(itemStack.getItem());
return record != null ? record.findPrecise(itemStack) : null;
}
@Override
public Collection<IAEItemStack> findFuzzy( final IAEItemStack filter, final FuzzyMode fuzzy )
{
if( filter == null )
{
return Collections.emptyList();
}
@Override
public Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy) {
if (filter == null) {
return Collections.emptyList();
}
ItemVariantList record = this.records.get( filter.getItem() );
return record != null ? record.findFuzzy( filter, fuzzy ) : Collections.emptyList();
}
ItemVariantList record = this.records.get(filter.getItem());
return record != null ? record.findFuzzy(filter, fuzzy) : Collections.emptyList();
}
@Override
public boolean isEmpty()
{
return !this.iterator().hasNext();
}
@Override
public boolean isEmpty() {
return !this.iterator().hasNext();
}
@Override
public void add( final IAEItemStack itemStack )
{
version.incrementAndGet();
@Override
public void add(final IAEItemStack itemStack) {
version.incrementAndGet();
if( itemStack == null )
{
return;
}
if (itemStack == null) {
return;
}
this.getOrCreateRecord( itemStack.getItem() ).add( itemStack );
}
this.getOrCreateRecord(itemStack.getItem()).add(itemStack);
}
@Override
public void addStorage( final IAEItemStack itemStack )
{
version.incrementAndGet();
@Override
public void addStorage(final IAEItemStack itemStack) {
version.incrementAndGet();
if( itemStack == null )
{
return;
}
if (itemStack == null) {
return;
}
this.getOrCreateRecord( itemStack.getItem() ).addStorage( itemStack );
}
this.getOrCreateRecord(itemStack.getItem()).addStorage(itemStack);
}
@Override
public void addCrafting( final IAEItemStack itemStack )
{
version.incrementAndGet();
@Override
public void addCrafting(final IAEItemStack itemStack) {
version.incrementAndGet();
if( itemStack == null )
{
return;
}
if (itemStack == null) {
return;
}
this.getOrCreateRecord( itemStack.getItem() ).addCrafting( itemStack );
}
this.getOrCreateRecord(itemStack.getItem()).addCrafting(itemStack);
}
@Override
public void addRequestable( final IAEItemStack itemStack )
{
version.incrementAndGet();
@Override
public void addRequestable(final IAEItemStack itemStack) {
version.incrementAndGet();
if( itemStack == null )
{
return;
}
if (itemStack == null) {
return;
}
this.getOrCreateRecord( itemStack.getItem() ).addRequestable( itemStack );
}
this.getOrCreateRecord(itemStack.getItem()).addRequestable(itemStack);
}
@Override
public IAEItemStack getFirstItem()
{
for( final IAEItemStack stackType : this )
{
return stackType;
}
@Override
public IAEItemStack getFirstItem() {
for (final IAEItemStack stackType : this) {
return stackType;
}
return null;
}
return null;
}
@Override
public int size()
{
int size = 0;
for( ItemVariantList entry : records.values() )
{
size += entry.size();
}
@Override
public int size() {
int size = 0;
for (ItemVariantList entry : records.values()) {
size += entry.size();
}
return size;
}
return size;
}
@Override
public Iterator<IAEItemStack> iterator()
{
return new ChainedIterator( this.records.values().iterator(), version );
}
@Override
public Iterator<IAEItemStack> iterator() {
return new ChainedIterator(this.records.values().iterator(), version);
}
@Override
public void resetStatus()
{
for( final IAEItemStack i : this )
{
i.reset();
}
}
@Override
public void resetStatus() {
for (final IAEItemStack i : this) {
i.reset();
}
}
private ItemVariantList getOrCreateRecord( Item item )
{
return this.records.computeIfAbsent( item, this::makeRecordMap );
}
private ItemVariantList getOrCreateRecord(Item item) {
return this.records.computeIfAbsent(item, this::makeRecordMap);
}
private ItemVariantList makeRecordMap( Item item )
{
if( item.isDamageable() || Platform.isGTDamageableItem( item ) )
{
return new FuzzyItemVariantList();
}
else
{
return new NormalItemVariantList();
}
}
private ItemVariantList makeRecordMap(Item item) {
if (item.isDamageable() || Platform.isGTDamageableItem(item)) {
return new FuzzyItemVariantList();
} else {
return new NormalItemVariantList();
}
}
/**
* Iterates over multiple item lists as if they were one list.
*/
private static class ChainedIterator implements Iterator<IAEItemStack>
{
/**
* Iterates over multiple item lists as if they were one list.
*/
private static class ChainedIterator implements Iterator<IAEItemStack> {
private final AtomicInteger parentVersion;
private final int version;
private final Iterator<ItemVariantList> parent;
private Iterator<IAEItemStack> next;
private final AtomicInteger parentVersion;
private final int version;
private final Iterator<ItemVariantList> parent;
private Iterator<IAEItemStack> next;
public ChainedIterator( Iterator<ItemVariantList> iterator, AtomicInteger parentVersion )
{
this.parent = iterator;
this.parentVersion = parentVersion;
this.version = parentVersion.get();
this.ensureItems();
}
public ChainedIterator(Iterator<ItemVariantList> iterator, AtomicInteger parentVersion) {
this.parent = iterator;
this.parentVersion = parentVersion;
this.version = parentVersion.get();
this.ensureItems();
}
@Override
public boolean hasNext()
{
return next != null && next.hasNext();
}
@Override
public boolean hasNext() {
return next != null && next.hasNext();
}
@Override
public IAEItemStack next()
{
if( this.next == null )
{
throw new NoSuchElementException();
}
if( this.version != this.parentVersion.get() )
{
throw new ConcurrentModificationException();
}
@Override
public IAEItemStack next() {
if (this.next == null) {
throw new NoSuchElementException();
}
if (this.version != this.parentVersion.get()) {
throw new ConcurrentModificationException();
}
IAEItemStack result = this.next.next();
this.ensureItems();
return result;
}
IAEItemStack result = this.next.next();
this.ensureItems();
return result;
}
private void ensureItems()
{
if( hasNext() )
{
return; // Still items left in the current one
}
private void ensureItems() {
if (hasNext()) {
return; // Still items left in the current one
}
// Find the next iterator willing to return some items...
while ( this.parent.hasNext() )
{
this.next = this.parent.next().iterator();
// Find the next iterator willing to return some items...
while (this.parent.hasNext()) {
this.next = this.parent.next().iterator();
if( this.next.hasNext() )
{
return; // Found one!
}
}
if (this.next.hasNext()) {
return; // Found one!
}
}
// No more items
this.next = null;
}
}
// No more items
this.next = null;
}
}
}
+39 -52
View File
@@ -19,69 +19,56 @@
package appeng.util.item;
import java.util.Collection;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemContainer;
import java.util.Collection;
public class ItemModList implements IItemContainer<IAEItemStack>
{
private final IItemContainer<IAEItemStack> backingStore;
private final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
public class ItemModList implements IItemContainer<IAEItemStack> {
public ItemModList( final IItemContainer<IAEItemStack> backend )
{
this.backingStore = backend;
}
private final IItemContainer<IAEItemStack> backingStore;
private final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
@Override
public void add( final IAEItemStack option )
{
IAEItemStack over = this.overrides.findPrecise( option );
if( over == null )
{
over = this.backingStore.findPrecise( option );
if( over == null )
{
this.overrides.add( option );
}
else
{
option.add( over );
this.overrides.add( option );
}
}
else
{
this.overrides.add( option );
}
}
public ItemModList(final IItemContainer<IAEItemStack> backend) {
this.backingStore = backend;
}
@Override
public IAEItemStack findPrecise( final IAEItemStack i )
{
final IAEItemStack over = this.overrides.findPrecise( i );
if( over == null )
{
return this.backingStore.findPrecise( i );
}
return over;
}
@Override
public void add(final IAEItemStack option) {
IAEItemStack over = this.overrides.findPrecise(option);
if (over == null) {
over = this.backingStore.findPrecise(option);
if (over == null) {
this.overrides.add(option);
} else {
option.add(over);
this.overrides.add(option);
}
} else {
this.overrides.add(option);
}
}
@Override
public Collection<IAEItemStack> findFuzzy( final IAEItemStack input, final FuzzyMode fuzzy )
{
return this.overrides.findFuzzy( input, fuzzy );
}
@Override
public IAEItemStack findPrecise(final IAEItemStack i) {
final IAEItemStack over = this.overrides.findPrecise(i);
if (over == null) {
return this.backingStore.findPrecise(i);
}
return over;
}
@Override
public boolean isEmpty()
{
return this.overrides.isEmpty() && this.backingStore.isEmpty();
}
@Override
public Collection<IAEItemStack> findFuzzy(final IAEItemStack input, final FuzzyMode fuzzy) {
return this.overrides.findFuzzy(input, fuzzy);
}
@Override
public boolean isEmpty() {
return this.overrides.isEmpty() && this.backingStore.isEmpty();
}
}
@@ -18,13 +18,13 @@
package appeng.util.item;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
/**
* Stores variants of a single type of {@link net.minecraft.item.Item}, i.e. versions with different durability, or
* different NBT or capabilities.
@@ -18,12 +18,12 @@
package appeng.util.item;
import appeng.api.storage.data.IAEItemStack;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import appeng.api.storage.data.IAEItemStack;
/**
* This iterator will only return items from a collection that are meaningful (w.r.t.
* {@link IAEItemStack#isMeaningful()}. Items that are not meaningful are automatically removed from the collection as
@@ -18,14 +18,13 @@
package appeng.util.item;
import java.util.Collection;
import java.util.Map;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import java.util.Collection;
import java.util.Map;
/**
* This variant list is optimized for items that cannot be damaged and thus do not support querying durability ranges
@@ -8,8 +8,7 @@ import java.util.List;
* @author brachy84
* @butcherer PrototypeTrousers
*/
public class OreDictFilterMatcher
{
public class OreDictFilterMatcher {
/**
* Parses the given expression and creates a List.
@@ -17,10 +16,9 @@ public class OreDictFilterMatcher
* @param expression expr to parse
* @return match rule list
*/
public static List<MatchRule> parseExpression( String expression )
{
public static List<MatchRule> parseExpression(String expression) {
List<MatchRule> rules = new ArrayList<>();
parseExpression( rules, expression );
parseExpression(rules, expression);
return rules;
}
@@ -31,55 +29,47 @@ public class OreDictFilterMatcher
* @param expression expr to parse
* @return the position of the expr. Is only relevant for sub rules
*/
public static int parseExpression( List<MatchRule> rules, String expression )
{
public static int parseExpression(List<MatchRule> rules, String expression) {
rules.clear();
StringBuilder builder = new StringBuilder();
for( int i = 0; i < expression.length(); i++ )
{
char c = expression.charAt( i );
if( c == ' ' )
{
for (int i = 0; i < expression.length(); i++) {
char c = expression.charAt(i);
if (c == ' ') {
continue;
}
if( c == '(' )
{
if (c == '(') {
List<MatchRule> subRules = new ArrayList<>();
i = parseExpression( subRules, expression.substring( i + 1 ) ) + i + 1;
rules.add( MatchRule.group( subRules, builder.toString() ) );
i = parseExpression(subRules, expression.substring(i + 1)) + i + 1;
rules.add(MatchRule.group(subRules, builder.toString()));
builder = new StringBuilder();
}
else
{
switch ( c )
{
} else {
switch (c) {
case '&':
rules.add( new MatchRule( builder.toString() ) );
rules.add( new MatchRule( MatchLogic.AND ) );
rules.add(new MatchRule(builder.toString()));
rules.add(new MatchRule(MatchLogic.AND));
builder = new StringBuilder();
break;
case '|':
rules.add( new MatchRule( builder.toString() ) );
rules.add( new MatchRule( MatchLogic.OR ) );
rules.add(new MatchRule(builder.toString()));
rules.add(new MatchRule(MatchLogic.OR));
builder = new StringBuilder();
break;
case '^':
rules.add( new MatchRule( builder.toString() ) );
rules.add( new MatchRule( MatchLogic.XOR ) );
rules.add(new MatchRule(builder.toString()));
rules.add(new MatchRule(MatchLogic.XOR));
builder = new StringBuilder();
break;
case ')':
rules.add( new MatchRule( builder.toString() ) );
rules.add(new MatchRule(builder.toString()));
return i + 1;
default:
builder.append( c );
builder.append(c);
}
}
}
if( builder.length() > 0 )
{
rules.add( new MatchRule( builder.toString() ) );
if (builder.length() > 0) {
rules.add(new MatchRule(builder.toString()));
}
return expression.length();
}
@@ -92,39 +82,28 @@ public class OreDictFilterMatcher
* @param oreDict string to check
* @return if the string matches the rules
*/
public static boolean matches( List<MatchRule> rules, String oreDict )
{
public static boolean matches(List<MatchRule> rules, String oreDict) {
boolean first = true;
boolean lastResult = false;
MatchLogic lastLogic = null;
for( MatchRule rule : rules )
{
if( lastLogic == null )
{
if( rule.logic == MatchLogic.AND || rule.logic == MatchLogic.OR || rule.logic == MatchLogic.XOR )
{
for (MatchRule rule : rules) {
if (lastLogic == null) {
if (rule.logic == MatchLogic.AND || rule.logic == MatchLogic.OR || rule.logic == MatchLogic.XOR) {
lastLogic = rule.logic;
continue;
}
}
if( lastLogic != null || first )
{
if( lastLogic != null )
{
switch ( lastLogic )
{
case AND:
{
if( !lastResult )
{
if (lastLogic != null || first) {
if (lastLogic != null) {
switch (lastLogic) {
case AND: {
if (!lastResult) {
return false;
}
break;
}
case OR:
{
if( lastResult )
{
case OR: {
if (lastResult) {
return true;
}
break;
@@ -133,19 +112,14 @@ public class OreDictFilterMatcher
}
boolean newResult;
if( rule.isGroup() )
{
newResult = rule.logic == MatchLogic.NOT ^ matches( rule.subRules, oreDict );
}
else
{
newResult = matches( rule, oreDict );
if (rule.isGroup()) {
newResult = rule.logic == MatchLogic.NOT ^ matches(rule.subRules, oreDict);
} else {
newResult = matches(rule, oreDict);
}
if( lastLogic == MatchLogic.XOR )
{
if( lastResult == newResult )
{
if (lastLogic == MatchLogic.XOR) {
if (lastResult == newResult) {
return false;
}
}
@@ -160,45 +134,37 @@ public class OreDictFilterMatcher
return lastResult;
}
private static boolean matches( MatchRule rule, String oreDict )
{
private static boolean matches(MatchRule rule, String oreDict) {
String filter = rule.expression;
if( filter.equals( "*" ) )
{
if (filter.equals("*")) {
return true;
}
boolean startWild = filter.startsWith( "*" ), endWild = filter.endsWith( "*" );
if( startWild )
{
filter = filter.substring( 1 );
boolean startWild = filter.startsWith("*"), endWild = filter.endsWith("*");
if (startWild) {
filter = filter.substring(1);
}
String[] parts = filter.split( "\\*+" );
String[] parts = filter.split("\\*+");
return ( rule.logic == MatchLogic.NOT ) ^ matches( parts, oreDict, startWild, endWild );
return (rule.logic == MatchLogic.NOT) ^ matches(parts, oreDict, startWild, endWild);
}
private static boolean matches( String[] filter, String oreDict, boolean startWild, boolean endWild )
{
private static boolean matches(String[] filter, String oreDict, boolean startWild, boolean endWild) {
String lastlastPart = filter[0];
String lastPart = filter[0];
int index = oreDict.indexOf( lastPart );
if( ( !startWild && index != 0 ) || index < 0 )
{
int index = oreDict.indexOf(lastPart);
if ((!startWild && index != 0) || index < 0) {
return false;
}
boolean didGoBack = false;
for( int i = 1; i < filter.length; i++ )
{
for (int i = 1; i < filter.length; i++) {
String part = filter[i];
int newIndex = oreDict.indexOf( part, index + lastPart.length() );
if( newIndex < 0 )
{
if( i > 1 && !didGoBack )
{
int newIndex = oreDict.indexOf(part, index + lastPart.length());
if (newIndex < 0) {
if (i > 1 && !didGoBack) {
i -= 2;
lastPart = lastlastPart;
didGoBack = true;
@@ -209,25 +175,20 @@ public class OreDictFilterMatcher
lastlastPart = lastPart;
lastPart = part;
index = newIndex;
if( didGoBack )
{
if (didGoBack) {
didGoBack = false;
}
}
if( endWild || lastPart.length() + index == oreDict.length() )
{
if (endWild || lastPart.length() + index == oreDict.length()) {
return true;
}
for( int i = filter.length - 1; i < filter.length; i++ )
{
for (int i = filter.length - 1; i < filter.length; i++) {
String part = filter[i];
int newIndex = oreDict.indexOf( part, index + lastPart.length() );
if( newIndex < 0 )
{
if( i > 1 && !didGoBack )
{
int newIndex = oreDict.indexOf(part, index + lastPart.length());
if (newIndex < 0) {
if (i > 1 && !didGoBack) {
i -= 2;
lastPart = lastlastPart;
didGoBack = true;
@@ -238,142 +199,115 @@ public class OreDictFilterMatcher
lastlastPart = lastPart;
lastPart = part;
index = newIndex;
if( didGoBack )
{
if (didGoBack) {
didGoBack = false;
}
}
return lastPart.length() + index == oreDict.length();
}
public static String validateExp( String input )
{
public static String validateExp(String input) {
// remove all operators that are double
input = input.replaceAll( "\\*{2,}", "*" );
input = input.replaceAll( "&{2,}", "&" );
input = input.replaceAll( "\\|{2,}", "|" );
input = input.replaceAll( "!{2,}", "!" );
input = input.replaceAll( "\\^{2,}", "^" );
input = input.replaceAll( " {2,}", " " );
input = input.replaceAll("\\*{2,}", "*");
input = input.replaceAll("&{2,}", "&");
input = input.replaceAll("\\|{2,}", "|");
input = input.replaceAll("!{2,}", "!");
input = input.replaceAll("\\^{2,}", "^");
input = input.replaceAll(" {2,}", " ");
// move ( and ) so it doesn't create invalid expressions f.e. xxx (& yyy) => xxx & (yyy)
// append or prepend ( and ) if the amount is not equal
StringBuilder builder = new StringBuilder();
int unclosed = 0;
char last = ' ';
for( int i = 0; i < input.length(); i++ )
{
char c = input.charAt( i );
if( c == ' ' )
{
if( last != '(' )
{
builder.append( " " );
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c == ' ') {
if (last != '(') {
builder.append(" ");
}
continue;
}
if( c == '(' )
{
if (c == '(') {
unclosed++;
}
else if( c == ')' )
{
} else if (c == ')') {
unclosed--;
if( last == '&' || last == '|' || last == '^' )
{
int l = builder.lastIndexOf( " " + last );
int l2 = builder.lastIndexOf( "" + last );
builder.insert( l == l2 - 1 ? l : l2, ")" );
if (last == '&' || last == '|' || last == '^') {
int l = builder.lastIndexOf(" " + last);
int l2 = builder.lastIndexOf("" + last);
builder.insert(l == l2 - 1 ? l : l2, ")");
continue;
}
if( i > 0 && builder.charAt( builder.length() - 1 ) == ' ' )
{
builder.deleteCharAt( builder.length() - 1 );
if (i > 0 && builder.charAt(builder.length() - 1) == ' ') {
builder.deleteCharAt(builder.length() - 1);
}
}
else if( ( c == '&' || c == '|' || c == '^' ) && last == '(' )
{
builder.deleteCharAt( builder.lastIndexOf( "(" ) );
builder.append( c ).append( " (" );
} else if ((c == '&' || c == '|' || c == '^') && last == '(') {
builder.deleteCharAt(builder.lastIndexOf("("));
builder.append(c).append(" (");
continue;
}
builder.append( c );
builder.append(c);
last = c;
}
if( unclosed > 0 )
{
for( int i = 0; i < unclosed; i++ )
{
builder.append( ")" );
if (unclosed > 0) {
for (int i = 0; i < unclosed; i++) {
builder.append(")");
}
}
else if( unclosed < 0 )
{
} else if (unclosed < 0) {
unclosed = -unclosed;
for( int i = 0; i < unclosed; i++ )
{
builder.insert( 0, "(" );
for (int i = 0; i < unclosed; i++) {
builder.insert(0, "(");
}
}
input = builder.toString();
input = input.replaceAll( " {2,}", " " );
input = input.replaceAll(" {2,}", " ");
return input;
}
public static class MatchRule
{
public static class MatchRule {
public final MatchLogic logic;
public final String expression;
private final List<MatchRule> subRules;
private MatchRule( MatchLogic logic, String expression, List<MatchRule> subRules )
{
if( expression.startsWith( "!" ) )
{
private MatchRule(MatchLogic logic, String expression, List<MatchRule> subRules) {
if (expression.startsWith("!")) {
logic = MatchLogic.NOT;
expression = expression.substring( 1 );
expression = expression.substring(1);
}
this.logic = logic;
this.expression = expression;
this.subRules = subRules;
}
public MatchRule( MatchLogic logic, String expression )
{
this( logic, expression, null );
public MatchRule(MatchLogic logic, String expression) {
this(logic, expression, null);
}
public MatchRule( MatchLogic logic )
{
this( logic, "" );
public MatchRule(MatchLogic logic) {
this(logic, "");
}
public MatchRule( String expression )
{
this( MatchLogic.ANY, expression );
public MatchRule(String expression) {
this(MatchLogic.ANY, expression);
}
public static MatchRule not( String expression, boolean not )
{
return new MatchRule( not ? MatchLogic.NOT : MatchLogic.ANY, expression );
public static MatchRule not(String expression, boolean not) {
return new MatchRule(not ? MatchLogic.NOT : MatchLogic.ANY, expression);
}
public static MatchRule group( List<MatchRule> subRules, String expression )
{
MatchLogic logic = expression.startsWith( "!" ) ? MatchLogic.NOT : MatchLogic.ANY;
return new MatchRule( logic, "", subRules );
public static MatchRule group(List<MatchRule> subRules, String expression) {
MatchLogic logic = expression.startsWith("!") ? MatchLogic.NOT : MatchLogic.ANY;
return new MatchRule(logic, "", subRules);
}
public boolean isGroup()
{
public boolean isGroup() {
return subRules != null;
}
}
public enum MatchLogic
{
public enum MatchLogic {
OR,
AND,
XOR,
+52 -89
View File
@@ -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 + ']';
}
}
@@ -19,54 +19,41 @@
package appeng.util.item;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import appeng.api.storage.data.IAEItemStack;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import appeng.api.storage.data.IAEItemStack;
import java.util.*;
public class OreReference
{
public class OreReference {
private final List<String> otherOptions = new ArrayList<>();
private final Set<Integer> ores = new HashSet<>();
private List<IAEItemStack> aeOtherOptions = null;
private final List<String> otherOptions = new ArrayList<>();
private final Set<Integer> ores = new HashSet<>();
private List<IAEItemStack> aeOtherOptions = null;
Collection<String> getEquivalents()
{
return this.otherOptions;
}
Collection<String> getEquivalents() {
return this.otherOptions;
}
public List<IAEItemStack> getAEEquivalents()
{
if( this.aeOtherOptions == null )
{
this.aeOtherOptions = new ArrayList<>( this.otherOptions.size() );
public List<IAEItemStack> getAEEquivalents() {
if (this.aeOtherOptions == null) {
this.aeOtherOptions = new ArrayList<>(this.otherOptions.size());
// SUMMON AE STACKS!
for( final String oreName : this.otherOptions )
{
for( final ItemStack is : OreHelper.INSTANCE.getCachedOres( oreName ) )
{
if( is.getItem() != Items.AIR )
{
this.aeOtherOptions.add( AEItemStack.fromItemStack( is ) );
}
}
}
}
// SUMMON AE STACKS!
for (final String oreName : this.otherOptions) {
for (final ItemStack is : OreHelper.INSTANCE.getCachedOres(oreName)) {
if (is.getItem() != Items.AIR) {
this.aeOtherOptions.add(AEItemStack.fromItemStack(is));
}
}
}
}
return this.aeOtherOptions;
}
return this.aeOtherOptions;
}
public Collection<Integer> getOres()
{
public Collection<Integer> getOres() {
return this.ores;
}
}