Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,10 +18,12 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
public class BlockUpdate implements Callable
|
||||
{
|
||||
|
||||
@@ -30,7 +32,8 @@ public class BlockUpdate implements Callable
|
||||
final int y;
|
||||
final int z;
|
||||
|
||||
public BlockUpdate(World w, int x, int y, int z) {
|
||||
public BlockUpdate( World w, int x, int y, int z )
|
||||
{
|
||||
this.w = w;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -40,10 +43,9 @@ public class BlockUpdate implements Callable
|
||||
@Override
|
||||
public Object call() throws Exception
|
||||
{
|
||||
if ( this.w.blockExists( this.x, this.y, this.z ) )
|
||||
if( this.w.blockExists( this.x, this.y, this.z ) )
|
||||
this.w.notifyBlocksOfNeighborChange( this.x, this.y, this.z, Platform.AIR );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,37 +41,37 @@ public class ClassInstantiation<T>
|
||||
public Optional<T> get()
|
||||
{
|
||||
@SuppressWarnings( "unchecked" )
|
||||
Constructor<T>[] constructors = ( Constructor<T>[] ) this.template.getConstructors();
|
||||
Constructor<T>[] constructors = (Constructor<T>[]) this.template.getConstructors();
|
||||
|
||||
for ( Constructor<T> constructor : constructors )
|
||||
for( Constructor<T> constructor : constructors )
|
||||
{
|
||||
Class<?>[] paramTypes = constructor.getParameterTypes();
|
||||
if ( paramTypes.length == this.args.length )
|
||||
if( paramTypes.length == this.args.length )
|
||||
{
|
||||
boolean valid = true;
|
||||
|
||||
for ( int idx = 0; idx < paramTypes.length; idx++ )
|
||||
for( int idx = 0; idx < paramTypes.length; idx++ )
|
||||
{
|
||||
Class<?> cz = this.args[idx].getClass();
|
||||
if ( !this.isClassMatch( paramTypes[idx], cz, this.args[idx] ) )
|
||||
if( !this.isClassMatch( paramTypes[idx], cz, this.args[idx] ) )
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if ( valid )
|
||||
if( valid )
|
||||
{
|
||||
try
|
||||
{
|
||||
return Optional.of( constructor.newInstance( this.args ) );
|
||||
}
|
||||
catch ( InstantiationException e )
|
||||
catch( InstantiationException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( IllegalAccessException e )
|
||||
catch( IllegalAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( InvocationTargetException e )
|
||||
catch( InvocationTargetException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class ClassInstantiation<T>
|
||||
|
||||
private boolean isClassMatch( Class<?> expected, Class<?> got, Object value )
|
||||
{
|
||||
if ( value == null && !expected.isPrimitive() )
|
||||
if( value == null && !expected.isPrimitive() )
|
||||
return true;
|
||||
|
||||
expected = this.condense( expected, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class );
|
||||
@@ -96,16 +96,16 @@ public class ClassInstantiation<T>
|
||||
|
||||
private Class<?> condense( Class<?> expected, Class<?>... wrappers )
|
||||
{
|
||||
if ( expected.isPrimitive() )
|
||||
if( expected.isPrimitive() )
|
||||
{
|
||||
for ( Class clz : wrappers )
|
||||
for( Class clz : wrappers )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( expected == clz.getField( "TYPE" ).get( null ) )
|
||||
if( expected == clz.getField( "TYPE" ).get( null ) )
|
||||
return clz;
|
||||
}
|
||||
catch ( Throwable t )
|
||||
catch( Throwable t )
|
||||
{
|
||||
AELog.error( t );
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class ConfigManager implements IConfigManager
|
||||
{
|
||||
Enum<?> oldValue = this.settings.get( settingName );
|
||||
|
||||
if ( oldValue != null )
|
||||
if( oldValue != null )
|
||||
return oldValue;
|
||||
|
||||
throw new RuntimeException( "Invalid Config setting" );
|
||||
@@ -83,7 +83,7 @@ public final class ConfigManager implements IConfigManager
|
||||
public void writeToNBT( NBTTagCompound tagCompound )
|
||||
{
|
||||
|
||||
for ( Settings setting : this.settings.keySet() )
|
||||
for( Settings setting : this.settings.keySet() )
|
||||
{
|
||||
tagCompound.setString( setting.name(), this.settings.get( setting ).toString() );
|
||||
}
|
||||
@@ -97,20 +97,20 @@ public final class ConfigManager implements IConfigManager
|
||||
@Override
|
||||
public void readFromNBT( NBTTagCompound tagCompound )
|
||||
{
|
||||
for ( Settings key : this.settings.keySet() )
|
||||
for( Settings key : this.settings.keySet() )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( tagCompound.hasKey( key.name() ) )
|
||||
if( tagCompound.hasKey( key.name() ) )
|
||||
{
|
||||
String value = tagCompound.getString( key.name() );
|
||||
|
||||
// Provides an upgrade path for the rename of this value in the API between rv1 and rv2
|
||||
if ( value.equals( "EXTACTABLE_ONLY" ) )
|
||||
if( value.equals( "EXTACTABLE_ONLY" ) )
|
||||
{
|
||||
value = StorageFilter.EXTRACTABLE_ONLY.toString();
|
||||
}
|
||||
else if ( value.equals( "STOREABLE_AMOUNT" ) )
|
||||
else if( value.equals( "STOREABLE_AMOUNT" ) )
|
||||
{
|
||||
value = LevelEmitterMode.STORABLE_AMOUNT.toString();
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public final class ConfigManager implements IConfigManager
|
||||
this.putSetting( key, newValue );
|
||||
}
|
||||
}
|
||||
catch ( IllegalArgumentException e )
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import appeng.api.util.IConfigManager;
|
||||
|
||||
|
||||
public interface IConfigManagerHost
|
||||
{
|
||||
|
||||
void updateSetting(IConfigManager manager, Enum settingName, Enum newValue);
|
||||
|
||||
void updateSetting( IConfigManager manager, Enum settingName, Enum newValue );
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -25,24 +26,43 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAir;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class InWorldToolOperationResult
|
||||
{
|
||||
|
||||
public final ItemStack BlockItem;
|
||||
public final List<ItemStack> Drops;
|
||||
|
||||
public static InWorldToolOperationResult getBlockOperationResult(ItemStack[] items)
|
||||
public InWorldToolOperationResult()
|
||||
{
|
||||
this.BlockItem = null;
|
||||
this.Drops = null;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult( ItemStack block, List<ItemStack> drops )
|
||||
{
|
||||
this.BlockItem = block;
|
||||
this.Drops = drops;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult( ItemStack block )
|
||||
{
|
||||
this.BlockItem = block;
|
||||
this.Drops = null;
|
||||
}
|
||||
|
||||
public static InWorldToolOperationResult getBlockOperationResult( ItemStack[] items )
|
||||
{
|
||||
List<ItemStack> temp = new ArrayList<ItemStack>();
|
||||
ItemStack b = null;
|
||||
|
||||
for (ItemStack l : items)
|
||||
for( ItemStack l : items )
|
||||
{
|
||||
if ( b == null )
|
||||
if( b == null )
|
||||
{
|
||||
Block bl = Block.getBlockFromItem( l.getItem() );
|
||||
|
||||
if ( bl != null && !(bl instanceof BlockAir) )
|
||||
if( bl != null && !( bl instanceof BlockAir ) )
|
||||
{
|
||||
b = l;
|
||||
continue;
|
||||
@@ -54,19 +74,4 @@ public class InWorldToolOperationResult
|
||||
|
||||
return new InWorldToolOperationResult( b, temp );
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult() {
|
||||
this.BlockItem = null;
|
||||
this.Drops = null;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult(ItemStack block, List<ItemStack> drops) {
|
||||
this.BlockItem = block;
|
||||
this.Drops = drops;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult(ItemStack block) {
|
||||
this.BlockItem = block;
|
||||
this.Drops = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -38,67 +39,68 @@ import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import appeng.util.inv.WrapperMCISidedInventory;
|
||||
|
||||
|
||||
public abstract class InventoryAdaptor implements Iterable<ItemSlot>
|
||||
{
|
||||
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination);
|
||||
|
||||
public abstract ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination);
|
||||
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination);
|
||||
|
||||
public abstract ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination);
|
||||
|
||||
// return what isn't used...
|
||||
public abstract ItemStack addItems(ItemStack toBeAdded);
|
||||
|
||||
public abstract ItemStack simulateAdd(ItemStack toBeSimulated);
|
||||
|
||||
public abstract boolean containsItems();
|
||||
|
||||
// returns an appropriate adaptor, or null
|
||||
public static InventoryAdaptor getAdaptor(Object te, ForgeDirection d)
|
||||
public static InventoryAdaptor getAdaptor( Object te, ForgeDirection d )
|
||||
{
|
||||
if ( te == null )
|
||||
if( te == null )
|
||||
return null;
|
||||
|
||||
IBetterStorage bs = (IBetterStorage) (AppEng.instance.isIntegrationEnabled( IntegrationType.BetterStorage ) ? AppEng.instance.getIntegration( IntegrationType.BetterStorage ) : null);
|
||||
IBetterStorage bs = (IBetterStorage) ( AppEng.instance.isIntegrationEnabled( IntegrationType.BetterStorage ) ? AppEng.instance.getIntegration( IntegrationType.BetterStorage ) : null );
|
||||
|
||||
if ( te instanceof EntityPlayer )
|
||||
if( te instanceof EntityPlayer )
|
||||
{
|
||||
return new AdaptorIInventory( new AdaptorPlayerInventory( ((EntityPlayer) te).inventory, false ) );
|
||||
return new AdaptorIInventory( new AdaptorPlayerInventory( ( (EntityPlayer) te ).inventory, false ) );
|
||||
}
|
||||
else if ( te instanceof ArrayList )
|
||||
else if( te instanceof ArrayList )
|
||||
{
|
||||
@SuppressWarnings( "unchecked" )
|
||||
final ArrayList<ItemStack> list = ( ArrayList<ItemStack> ) te;
|
||||
final ArrayList<ItemStack> list = (ArrayList<ItemStack>) te;
|
||||
|
||||
return new AdaptorList( list );
|
||||
}
|
||||
else if ( bs != null && bs.isStorageCrate( te ) )
|
||||
else if( bs != null && bs.isStorageCrate( te ) )
|
||||
{
|
||||
return bs.getAdaptor( te, d );
|
||||
}
|
||||
else if ( te instanceof TileEntityChest )
|
||||
else if( te instanceof TileEntityChest )
|
||||
{
|
||||
return new AdaptorIInventory( Platform.GetChestInv( te ) );
|
||||
}
|
||||
else if ( te instanceof ISidedInventory )
|
||||
else if( te instanceof ISidedInventory )
|
||||
{
|
||||
ISidedInventory si =(ISidedInventory)te;
|
||||
ISidedInventory si = (ISidedInventory) te;
|
||||
int[] slots = si.getAccessibleSlotsFromSide( d.ordinal() );
|
||||
if ( si.getSizeInventory() > 0 && slots != null && slots.length > 0 )
|
||||
if( si.getSizeInventory() > 0 && slots != null && slots.length > 0 )
|
||||
return new AdaptorIInventory( new WrapperMCISidedInventory( si, d ) );
|
||||
}
|
||||
else if ( te instanceof IInventory )
|
||||
else if( te instanceof IInventory )
|
||||
{
|
||||
IInventory i =(IInventory)te;
|
||||
if ( i.getSizeInventory() > 0 )
|
||||
IInventory i = (IInventory) te;
|
||||
if( i.getSizeInventory() > 0 )
|
||||
return new AdaptorIInventory( i );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination );
|
||||
|
||||
public abstract ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination );
|
||||
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination );
|
||||
|
||||
public abstract ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination );
|
||||
|
||||
// return what isn't used...
|
||||
public abstract ItemStack addItems( ItemStack toBeAdded );
|
||||
|
||||
public abstract ItemStack simulateAdd( ItemStack toBeSimulated );
|
||||
|
||||
public abstract boolean containsItems();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import appeng.api.config.SortDir;
|
||||
@@ -27,108 +28,108 @@ import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IInvTweaks;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class ItemSorters
|
||||
{
|
||||
|
||||
public static SortDir Direction = SortDir.ASCENDING;
|
||||
private static IInvTweaks api;
|
||||
|
||||
public static void init()
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_NAME = new Comparator<IAEItemStack>()
|
||||
{
|
||||
if ( api != null )
|
||||
return;
|
||||
|
||||
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.InvTweaks ) )
|
||||
api = (IInvTweaks) AppEng.instance.getIntegration( IntegrationType.InvTweaks );
|
||||
else
|
||||
api = null;
|
||||
}
|
||||
|
||||
public static int compareInt(int a, int b)
|
||||
{
|
||||
if ( a == b )
|
||||
return 0;
|
||||
if ( a < b )
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int compareLong(long a, long b)
|
||||
{
|
||||
if ( a == b )
|
||||
return 0;
|
||||
if ( a < b )
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int compareDouble(double a, double b)
|
||||
{
|
||||
if ( a == b )
|
||||
return 0;
|
||||
if ( a < b )
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_NAME = new Comparator<IAEItemStack>() {
|
||||
|
||||
@Override
|
||||
public int compare(IAEItemStack o1, IAEItemStack o2)
|
||||
public int compare( IAEItemStack o1, IAEItemStack o2 )
|
||||
{
|
||||
if ( Direction == SortDir.ASCENDING )
|
||||
if( Direction == SortDir.ASCENDING )
|
||||
return Platform.getItemDisplayName( o1 ).compareToIgnoreCase( Platform.getItemDisplayName( o2 ) );
|
||||
return Platform.getItemDisplayName( o2 ).compareToIgnoreCase( Platform.getItemDisplayName( o1 ) );
|
||||
}
|
||||
};
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_MOD = new Comparator<IAEItemStack>() {
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_MOD = new Comparator<IAEItemStack>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(IAEItemStack o1, IAEItemStack o2)
|
||||
public int compare( IAEItemStack o1, IAEItemStack o2 )
|
||||
{
|
||||
AEItemStack op1 = (AEItemStack) o1;
|
||||
AEItemStack op2 = (AEItemStack) o2;
|
||||
|
||||
if ( Direction == SortDir.ASCENDING )
|
||||
if( Direction == SortDir.ASCENDING )
|
||||
return this.secondarySort( op2.getModID().compareToIgnoreCase( op1.getModID() ), o1, o2 );
|
||||
return this.secondarySort( op1.getModID().compareToIgnoreCase( op2.getModID() ), o2, o1 );
|
||||
}
|
||||
|
||||
private int secondarySort(int compareToIgnoreCase, IAEItemStack o1, IAEItemStack o2)
|
||||
private int secondarySort( int compareToIgnoreCase, IAEItemStack o1, IAEItemStack o2 )
|
||||
{
|
||||
if ( compareToIgnoreCase == 0 )
|
||||
if( compareToIgnoreCase == 0 )
|
||||
return Platform.getItemDisplayName( o2 ).compareToIgnoreCase( Platform.getItemDisplayName( o1 ) );
|
||||
|
||||
return compareToIgnoreCase;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_SIZE = new Comparator<IAEItemStack>() {
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_SIZE = new Comparator<IAEItemStack>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(IAEItemStack o1, IAEItemStack o2)
|
||||
public int compare( IAEItemStack o1, IAEItemStack o2 )
|
||||
{
|
||||
if ( Direction == SortDir.ASCENDING )
|
||||
if( Direction == SortDir.ASCENDING )
|
||||
return compareLong( o2.getStackSize(), o1.getStackSize() );
|
||||
return compareLong( o1.getStackSize(), o2.getStackSize() );
|
||||
}
|
||||
};
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_INV_TWEAKS = new Comparator<IAEItemStack>() {
|
||||
private static IInvTweaks api;
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_INV_TWEAKS = new Comparator<IAEItemStack>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(IAEItemStack o1, IAEItemStack o2)
|
||||
public int compare( IAEItemStack o1, IAEItemStack o2 )
|
||||
{
|
||||
if ( api == null )
|
||||
if( api == null )
|
||||
return CONFIG_BASED_SORT_BY_NAME.compare( o1, o2 );
|
||||
|
||||
int cmp = api.compareItems( o1.getItemStack(), o2.getItemStack() );
|
||||
|
||||
if ( Direction == SortDir.ASCENDING )
|
||||
if( Direction == SortDir.ASCENDING )
|
||||
return cmp;
|
||||
return -cmp;
|
||||
}
|
||||
};
|
||||
|
||||
public static void init()
|
||||
{
|
||||
if( api != null )
|
||||
return;
|
||||
|
||||
if( AppEng.instance.isIntegrationEnabled( IntegrationType.InvTweaks ) )
|
||||
api = (IInvTweaks) AppEng.instance.getIntegration( IntegrationType.InvTweaks );
|
||||
else
|
||||
api = null;
|
||||
}
|
||||
|
||||
public static int compareInt( int a, int b )
|
||||
{
|
||||
if( a == b )
|
||||
return 0;
|
||||
if( a < b )
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int compareLong( long a, long b )
|
||||
{
|
||||
if( a == b )
|
||||
return 0;
|
||||
if( a < b )
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int compareDouble( double a, double b )
|
||||
{
|
||||
if( a == b )
|
||||
return 0;
|
||||
if( a < b )
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,15 +18,18 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
|
||||
public class LookDirection
|
||||
{
|
||||
|
||||
public final Vec3 a;
|
||||
public final Vec3 b;
|
||||
|
||||
public LookDirection(Vec3 a, Vec3 b) {
|
||||
public LookDirection( Vec3 a, Vec3 b )
|
||||
{
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,17 +18,20 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.util.IReadOnlyCollection;
|
||||
|
||||
|
||||
public class ReadOnlyCollection<T> implements IReadOnlyCollection<T>
|
||||
{
|
||||
|
||||
private final Collection<T> c;
|
||||
|
||||
public ReadOnlyCollection(Collection<T> in) {
|
||||
public ReadOnlyCollection( Collection<T> in )
|
||||
{
|
||||
this.c = in;
|
||||
}
|
||||
|
||||
@@ -51,9 +54,8 @@ public class ReadOnlyCollection<T> implements IReadOnlyCollection<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object node)
|
||||
public boolean contains( Object node )
|
||||
{
|
||||
return this.c.contains( node );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,6 +58,25 @@ public enum ReadableNumberConverter
|
||||
return String.format( "%s%d%s", sign, result, postFix );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets character representation of the sign of a number
|
||||
*
|
||||
* @param number maybe signed number
|
||||
*
|
||||
* @return '-' if the number is signed, else an empty character
|
||||
*/
|
||||
private String getSign( long number )
|
||||
{
|
||||
if( number < 0 )
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a number into a human readable form. It will not round the number, but floor it.
|
||||
* Will try to cut the number down 1 decimal earlier. This will limit the String size to 3 chars.
|
||||
@@ -92,23 +111,4 @@ public enum ReadableNumberConverter
|
||||
return String.format( "%s%d%s", sign, result, postFix );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets character representation of the sign of a number
|
||||
*
|
||||
* @param number maybe signed number
|
||||
*
|
||||
* @return '-' if the number is signed, else an empty character
|
||||
*/
|
||||
private String getSign( long number )
|
||||
{
|
||||
if ( number < 0 )
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
public enum SettingsFrom
|
||||
{
|
||||
// moved the item, and replaced it.
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -31,6 +32,7 @@ import appeng.integration.abstraction.IBC;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.iterators.NullIterator;
|
||||
|
||||
|
||||
public class AdaptorBCPipe extends InventoryAdaptor
|
||||
{
|
||||
|
||||
@@ -38,11 +40,12 @@ public class AdaptorBCPipe extends InventoryAdaptor
|
||||
final private TileEntity i;
|
||||
final private ForgeDirection d;
|
||||
|
||||
public AdaptorBCPipe(TileEntity s, ForgeDirection dd) {
|
||||
public AdaptorBCPipe( TileEntity s, ForgeDirection dd )
|
||||
{
|
||||
this.bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
||||
if ( this.bc != null )
|
||||
if( this.bc != null )
|
||||
{
|
||||
if ( this.bc.isPipe( s, dd ) )
|
||||
if( this.bc.isPipe( s, dd ) )
|
||||
{
|
||||
this.i = s;
|
||||
this.d = dd;
|
||||
@@ -54,48 +57,48 @@ public class AdaptorBCPipe extends InventoryAdaptor
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination)
|
||||
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination)
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack toBeAdded )
|
||||
public ItemStack addItems( ItemStack toBeAdded )
|
||||
{
|
||||
if ( this.i == null )
|
||||
if( this.i == null )
|
||||
return toBeAdded;
|
||||
if ( toBeAdded == null )
|
||||
if( toBeAdded == null )
|
||||
return null;
|
||||
if ( toBeAdded.stackSize == 0 )
|
||||
if( toBeAdded.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
if ( this.bc.addItemsToPipe( this.i, toBeAdded, this.d ) )
|
||||
if( this.bc.addItemsToPipe( this.i, toBeAdded, this.d ) )
|
||||
return null;
|
||||
return toBeAdded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack toBeSimulated )
|
||||
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
||||
{
|
||||
if ( this.i == null )
|
||||
if( this.i == null )
|
||||
return toBeSimulated;
|
||||
return null;
|
||||
}
|
||||
@@ -111,5 +114,4 @@ public class AdaptorBCPipe extends InventoryAdaptor
|
||||
{
|
||||
return new NullIterator<ItemSlot>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,117 +41,26 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
this.wrapperEnabled = s instanceof IInventoryWrapper;
|
||||
}
|
||||
|
||||
boolean canRemoveStackFromSlot( int x, ItemStack is )
|
||||
{
|
||||
if ( this.wrapperEnabled )
|
||||
return ( ( IInventoryWrapper ) this.i ).canRemoveItemFromSlot( x, is );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
int s = this.i.getSizeInventory();
|
||||
for ( int x = 0; x < s; x++ )
|
||||
{
|
||||
if ( this.i.getStackInSlot( x ) != null )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
int s = this.i.getSizeInventory();
|
||||
for ( int x = 0; x < s; x++ )
|
||||
{
|
||||
ItemStack is = this.i.getStackInSlot( x );
|
||||
if ( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
int newAmount = amount;
|
||||
if ( newAmount > is.stackSize )
|
||||
newAmount = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
newAmount = 0;
|
||||
|
||||
ItemStack rv = null;
|
||||
if ( newAmount > 0 )
|
||||
{
|
||||
rv = is.copy();
|
||||
rv.stackSize = newAmount;
|
||||
|
||||
if ( is.stackSize == rv.stackSize )
|
||||
{
|
||||
this.i.setInventorySlotContents( x, null );
|
||||
this.i.markDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack po = is.copy();
|
||||
po.stackSize -= rv.stackSize;
|
||||
this.i.setInventorySlotContents( x, po );
|
||||
this.i.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
if ( rv != null )
|
||||
{
|
||||
// i.markDirty();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
int s = this.i.getSizeInventory();
|
||||
for ( int x = 0; x < s; x++ )
|
||||
{
|
||||
ItemStack is = this.i.getStackInSlot( x );
|
||||
|
||||
if ( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
int boundAmount = amount;
|
||||
if ( boundAmount > is.stackSize )
|
||||
boundAmount = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
boundAmount = 0;
|
||||
|
||||
if ( boundAmount > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = boundAmount;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
int s = this.i.getSizeInventory();
|
||||
ItemStack rv = null;
|
||||
|
||||
for ( int x = 0; x < s && amount > 0; x++ )
|
||||
for( int x = 0; x < s && amount > 0; x++ )
|
||||
{
|
||||
ItemStack is = this.i.getStackInSlot( x );
|
||||
if ( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
|
||||
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
|
||||
{
|
||||
int boundAmounts = amount;
|
||||
if ( boundAmounts > is.stackSize )
|
||||
if( boundAmounts > is.stackSize )
|
||||
boundAmounts = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
boundAmounts = 0;
|
||||
|
||||
if ( boundAmounts > 0 )
|
||||
if( boundAmounts > 0 )
|
||||
{
|
||||
if ( rv == null )
|
||||
if( rv == null )
|
||||
{
|
||||
rv = is.copy();
|
||||
filter = rv;
|
||||
@@ -164,7 +73,7 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
amount -= boundAmounts;
|
||||
}
|
||||
|
||||
if ( is.stackSize == boundAmounts )
|
||||
if( is.stackSize == boundAmounts )
|
||||
{
|
||||
this.i.setInventorySlotContents( x, null );
|
||||
this.i.markDirty();
|
||||
@@ -192,20 +101,20 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
int s = this.i.getSizeInventory();
|
||||
ItemStack rv = null;
|
||||
|
||||
for ( int x = 0; x < s && amount > 0; x++ )
|
||||
for( int x = 0; x < s && amount > 0; x++ )
|
||||
{
|
||||
ItemStack is = this.i.getStackInSlot( x );
|
||||
if ( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
|
||||
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
|
||||
{
|
||||
int boundAmount = amount;
|
||||
if ( boundAmount > is.stackSize )
|
||||
if( boundAmount > is.stackSize )
|
||||
boundAmount = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
boundAmount = 0;
|
||||
|
||||
if ( boundAmount > 0 )
|
||||
if( boundAmount > 0 )
|
||||
{
|
||||
if ( rv == null )
|
||||
if( rv == null )
|
||||
{
|
||||
rv = is.copy();
|
||||
rv.stackSize = boundAmount;
|
||||
@@ -223,6 +132,78 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
return rv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
int s = this.i.getSizeInventory();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
ItemStack is = this.i.getStackInSlot( x );
|
||||
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
int newAmount = amount;
|
||||
if( newAmount > is.stackSize )
|
||||
newAmount = is.stackSize;
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
newAmount = 0;
|
||||
|
||||
ItemStack rv = null;
|
||||
if( newAmount > 0 )
|
||||
{
|
||||
rv = is.copy();
|
||||
rv.stackSize = newAmount;
|
||||
|
||||
if( is.stackSize == rv.stackSize )
|
||||
{
|
||||
this.i.setInventorySlotContents( x, null );
|
||||
this.i.markDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack po = is.copy();
|
||||
po.stackSize -= rv.stackSize;
|
||||
this.i.setInventorySlotContents( x, po );
|
||||
this.i.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
if( rv != null )
|
||||
{
|
||||
// i.markDirty();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
int s = this.i.getSizeInventory();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
ItemStack is = this.i.getStackInSlot( x );
|
||||
|
||||
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
int boundAmount = amount;
|
||||
if( boundAmount > is.stackSize )
|
||||
boundAmount = is.stackSize;
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
boundAmount = 0;
|
||||
|
||||
if( boundAmount > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = boundAmount;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( ItemStack toBeAdded )
|
||||
{
|
||||
@@ -235,6 +216,18 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
return this.addItems( toBeSimulated, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
int s = this.i.getSizeInventory();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
if( this.i.getStackInSlot( x ) != null )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an {@link ItemStack} to the adapted {@link IInventory}.
|
||||
*
|
||||
@@ -243,13 +236,13 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
* than the limit.
|
||||
*
|
||||
* @param itemsToAdd itemStack to add to the inventory
|
||||
* @param modulate true to modulate, false for simulate
|
||||
* @param modulate true to modulate, false for simulate
|
||||
*
|
||||
* @return the left itemstack, which could not be added
|
||||
*/
|
||||
private ItemStack addItems( ItemStack itemsToAdd, boolean modulate )
|
||||
{
|
||||
if ( itemsToAdd == null || itemsToAdd.stackSize == 0 )
|
||||
if( itemsToAdd == null || itemsToAdd.stackSize == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -259,35 +252,35 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
int perOperationLimit = Math.min( this.i.getInventoryStackLimit(), stackLimit );
|
||||
int inventorySize = this.i.getSizeInventory();
|
||||
|
||||
for ( int slot = 0; slot < inventorySize; slot++ )
|
||||
for( int slot = 0; slot < inventorySize; slot++ )
|
||||
{
|
||||
ItemStack next = left.copy();
|
||||
next.stackSize = Math.min( perOperationLimit, next.stackSize );
|
||||
|
||||
if ( this.i.isItemValidForSlot( slot, next ) )
|
||||
if( this.i.isItemValidForSlot( slot, next ) )
|
||||
{
|
||||
ItemStack is = this.i.getStackInSlot( slot );
|
||||
if ( is == null )
|
||||
if( is == null )
|
||||
{
|
||||
left.stackSize -= next.stackSize;
|
||||
|
||||
if ( modulate )
|
||||
if( modulate )
|
||||
{
|
||||
this.i.setInventorySlotContents( slot, next );
|
||||
this.i.markDirty();
|
||||
}
|
||||
|
||||
if ( left.stackSize <= 0 )
|
||||
if( left.stackSize <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if ( Platform.isSameItemPrecise( is, left ) && is.stackSize < perOperationLimit )
|
||||
else if( Platform.isSameItemPrecise( is, left ) && is.stackSize < perOperationLimit )
|
||||
{
|
||||
int room = perOperationLimit - is.stackSize;
|
||||
int used = Math.min( left.stackSize, room );
|
||||
|
||||
if ( modulate )
|
||||
if( modulate )
|
||||
{
|
||||
is.stackSize += used;
|
||||
this.i.setInventorySlotContents( slot, is );
|
||||
@@ -295,7 +288,7 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
}
|
||||
|
||||
left.stackSize -= used;
|
||||
if ( left.stackSize <= 0 )
|
||||
if( left.stackSize <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -306,6 +299,19 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
return left;
|
||||
}
|
||||
|
||||
boolean canRemoveStackFromSlot( int x, ItemStack is )
|
||||
{
|
||||
if( this.wrapperEnabled )
|
||||
return ( (IInventoryWrapper) this.i ).canRemoveItemFromSlot( x, is );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new InvIterator();
|
||||
}
|
||||
|
||||
class InvIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
|
||||
@@ -336,13 +342,5 @@ public class AdaptorIInventory extends InventoryAdaptor
|
||||
{
|
||||
// nothing!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new InvIterator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -28,96 +29,39 @@ import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.StackToSlotIterator;
|
||||
|
||||
|
||||
public class AdaptorList extends InventoryAdaptor
|
||||
{
|
||||
|
||||
private final List<ItemStack> i;
|
||||
|
||||
public AdaptorList(List<ItemStack> s) {
|
||||
public AdaptorList( List<ItemStack> s )
|
||||
{
|
||||
this.i = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
int s = this.i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
ItemStack is = this.i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
if( is != null && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
|
||||
{
|
||||
if ( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
how_many = 0;
|
||||
|
||||
if ( how_many > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = how_many;
|
||||
is.stackSize -= how_many;
|
||||
|
||||
// remove it..
|
||||
if ( is.stackSize <= 0 )
|
||||
this.i.remove( x );
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
for (ItemStack is : this.i)
|
||||
{
|
||||
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
{
|
||||
if ( amount > is.stackSize )
|
||||
{
|
||||
if( amount > is.stackSize )
|
||||
amount = is.stackSize;
|
||||
}
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
if ( amount > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = amount;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
int s = this.i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = this.i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
{
|
||||
if ( amount > is.stackSize )
|
||||
amount = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
amount = 0;
|
||||
|
||||
if ( amount > 0 )
|
||||
if( amount > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = amount;
|
||||
is.stackSize -= amount;
|
||||
|
||||
// remove it..
|
||||
if ( is.stackSize <= 0 )
|
||||
if( is.stackSize <= 0 )
|
||||
this.i.remove( x );
|
||||
|
||||
return rv;
|
||||
@@ -128,22 +72,22 @@ public class AdaptorList extends InventoryAdaptor
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination)
|
||||
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
for (ItemStack is : this.i)
|
||||
for( ItemStack is : this.i )
|
||||
{
|
||||
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
if( is != null && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
|
||||
{
|
||||
if ( amount > is.stackSize )
|
||||
if( amount > is.stackSize )
|
||||
{
|
||||
amount = is.stackSize;
|
||||
}
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
if ( amount > 0 )
|
||||
if( amount > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = amount;
|
||||
@@ -152,22 +96,79 @@ public class AdaptorList extends InventoryAdaptor
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack toBeAdded )
|
||||
public ItemStack removeSimilarItems( int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
if ( toBeAdded == null )
|
||||
int s = this.i.size();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
ItemStack is = this.i.get( x );
|
||||
if( is != null && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
if( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
how_many = 0;
|
||||
|
||||
if( how_many > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = how_many;
|
||||
is.stackSize -= how_many;
|
||||
|
||||
// remove it..
|
||||
if( is.stackSize <= 0 )
|
||||
this.i.remove( x );
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
for( ItemStack is : this.i )
|
||||
{
|
||||
if( is != null && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
if( amount > is.stackSize )
|
||||
{
|
||||
amount = is.stackSize;
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
if( amount > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = amount;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( ItemStack toBeAdded )
|
||||
{
|
||||
if( toBeAdded == null )
|
||||
return null;
|
||||
if ( toBeAdded.stackSize == 0 )
|
||||
if( toBeAdded.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
ItemStack left = toBeAdded.copy();
|
||||
|
||||
for (ItemStack is : this.i)
|
||||
for( ItemStack is : this.i )
|
||||
{
|
||||
if ( Platform.isSameItem( is, left ) )
|
||||
if( Platform.isSameItem( is, left ) )
|
||||
{
|
||||
is.stackSize += left.stackSize;
|
||||
return null;
|
||||
@@ -179,7 +180,7 @@ public class AdaptorList extends InventoryAdaptor
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack toBeSimulated )
|
||||
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -187,9 +188,9 @@ public class AdaptorList extends InventoryAdaptor
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
for (ItemStack is : this.i)
|
||||
for( ItemStack is : this.i )
|
||||
{
|
||||
if ( is != null )
|
||||
if( is != null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -202,5 +203,4 @@ public class AdaptorList extends InventoryAdaptor
|
||||
{
|
||||
return new StackToSlotIterator( this.i.iterator() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
@@ -44,57 +43,19 @@ public class AdaptorPlayerHand extends InventoryAdaptor
|
||||
this.p = _p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int how_many, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack hand = this.p.inventory.getItemStack();
|
||||
if ( hand == null )
|
||||
return null;
|
||||
|
||||
if ( Filter == null || Platform.isSameItemFuzzy( Filter, hand, fuzzyMode ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
|
||||
hand.stackSize -= how_many;
|
||||
if ( hand.stackSize <= 0 )
|
||||
this.p.inventory.setItemStack( null );
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
|
||||
ItemStack hand = this.p.inventory.getItemStack();
|
||||
if ( hand == null )
|
||||
return null;
|
||||
|
||||
if ( Filter == null || Platform.isSameItemFuzzy( Filter, hand, fuzzyMode ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack hand = this.p.inventory.getItemStack();
|
||||
if ( hand == null )
|
||||
if( hand == null )
|
||||
return null;
|
||||
|
||||
if ( filter == null || Platform.isSameItemPrecise( filter, hand ) )
|
||||
if( filter == null || Platform.isSameItemPrecise( filter, hand ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
|
||||
hand.stackSize -= amount;
|
||||
if ( hand.stackSize <= 0 )
|
||||
if( hand.stackSize <= 0 )
|
||||
this.p.inventory.setItemStack( null );
|
||||
return result;
|
||||
}
|
||||
@@ -107,10 +68,48 @@ public class AdaptorPlayerHand extends InventoryAdaptor
|
||||
{
|
||||
|
||||
ItemStack hand = this.p.inventory.getItemStack();
|
||||
if ( hand == null )
|
||||
if( hand == null )
|
||||
return null;
|
||||
|
||||
if ( filter == null || Platform.isSameItemPrecise( filter, hand ) )
|
||||
if( filter == null || Platform.isSameItemPrecise( filter, hand ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int how_many, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack hand = this.p.inventory.getItemStack();
|
||||
if( hand == null )
|
||||
return null;
|
||||
|
||||
if( Filter == null || Platform.isSameItemFuzzy( Filter, hand, fuzzyMode ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
|
||||
hand.stackSize -= how_many;
|
||||
if( hand.stackSize <= 0 )
|
||||
this.p.inventory.setItemStack( null );
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
|
||||
ItemStack hand = this.p.inventory.getItemStack();
|
||||
if( hand == null )
|
||||
return null;
|
||||
|
||||
if( Filter == null || Platform.isSameItemFuzzy( Filter, hand, fuzzyMode ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
|
||||
@@ -124,23 +123,23 @@ public class AdaptorPlayerHand extends InventoryAdaptor
|
||||
public ItemStack addItems( ItemStack toBeAdded )
|
||||
{
|
||||
|
||||
if ( toBeAdded == null )
|
||||
if( toBeAdded == null )
|
||||
return null;
|
||||
if ( toBeAdded.stackSize == 0 )
|
||||
if( toBeAdded.stackSize == 0 )
|
||||
return null;
|
||||
if ( this.p == null )
|
||||
if( this.p == null )
|
||||
return toBeAdded;
|
||||
if ( this.p.inventory == null )
|
||||
if( this.p.inventory == null )
|
||||
return toBeAdded;
|
||||
|
||||
ItemStack hand = this.p.inventory.getItemStack();
|
||||
|
||||
if ( hand != null && !Platform.isSameItemPrecise( toBeAdded, hand ) )
|
||||
if( hand != null && !Platform.isSameItemPrecise( toBeAdded, hand ) )
|
||||
return toBeAdded;
|
||||
|
||||
int original = 0;
|
||||
ItemStack newHand = null;
|
||||
if ( hand == null )
|
||||
if( hand == null )
|
||||
newHand = toBeAdded.copy();
|
||||
else
|
||||
{
|
||||
@@ -149,7 +148,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor
|
||||
newHand.stackSize += toBeAdded.stackSize;
|
||||
}
|
||||
|
||||
if ( newHand.stackSize > newHand.getMaxStackSize() )
|
||||
if( newHand.stackSize > newHand.getMaxStackSize() )
|
||||
{
|
||||
newHand.stackSize = newHand.getMaxStackSize();
|
||||
ItemStack B = toBeAdded.copy();
|
||||
@@ -166,15 +165,15 @@ public class AdaptorPlayerHand extends InventoryAdaptor
|
||||
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
||||
{
|
||||
ItemStack hand = this.p.inventory.getItemStack();
|
||||
if ( toBeSimulated == null )
|
||||
if( toBeSimulated == null )
|
||||
return null;
|
||||
|
||||
if ( hand != null && !Platform.isSameItem( toBeSimulated, hand ) )
|
||||
if( hand != null && !Platform.isSameItem( toBeSimulated, hand ) )
|
||||
return toBeSimulated;
|
||||
|
||||
int original = 0;
|
||||
ItemStack newHand = null;
|
||||
if ( hand == null )
|
||||
if( hand == null )
|
||||
newHand = toBeSimulated.copy();
|
||||
else
|
||||
{
|
||||
@@ -183,7 +182,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor
|
||||
newHand.stackSize += toBeSimulated.stackSize;
|
||||
}
|
||||
|
||||
if ( newHand.stackSize > newHand.getMaxStackSize() )
|
||||
if( newHand.stackSize > newHand.getMaxStackSize() )
|
||||
{
|
||||
newHand.stackSize = newHand.getMaxStackSize();
|
||||
ItemStack B = toBeSimulated.copy();
|
||||
|
||||
@@ -18,25 +18,26 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class AdaptorPlayerInventory implements IInventory
|
||||
{
|
||||
|
||||
private final IInventory src;
|
||||
private final int min=0;
|
||||
private final int size=36;
|
||||
private final int min = 0;
|
||||
private final int size = 36;
|
||||
|
||||
public AdaptorPlayerInventory(IInventory playerInv, boolean swap)
|
||||
public AdaptorPlayerInventory( IInventory playerInv, boolean swap )
|
||||
{
|
||||
|
||||
if ( swap )
|
||||
this.src = new WrapperChainedInventory( new WrapperInventoryRange( playerInv, 9, this.size -9, false ), new WrapperInventoryRange( playerInv, 0, 9, false ) );
|
||||
if( swap )
|
||||
this.src = new WrapperChainedInventory( new WrapperInventoryRange( playerInv, 9, this.size - 9, false ), new WrapperInventoryRange( playerInv, 0, 9, false ) );
|
||||
else
|
||||
this.src = playerInv;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,25 +47,25 @@ public class AdaptorPlayerInventory implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1)
|
||||
public ItemStack getStackInSlot( int var1 )
|
||||
{
|
||||
return this.src.getStackInSlot( var1 + this.min );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2)
|
||||
public ItemStack decrStackSize( int var1, int var2 )
|
||||
{
|
||||
return this.src.decrStackSize( this.min + var1, var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1)
|
||||
public ItemStack getStackInSlotOnClosing( int var1 )
|
||||
{
|
||||
return this.src.getStackInSlotOnClosing( this.min + var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int var1, ItemStack var2)
|
||||
public void setInventorySlotContents( int var1, ItemStack var2 )
|
||||
{
|
||||
this.src.setInventorySlotContents( var1 + this.min, var2 );
|
||||
}
|
||||
@@ -75,6 +76,12 @@ public class AdaptorPlayerInventory implements IInventory
|
||||
return this.src.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
@@ -88,7 +95,7 @@ public class AdaptorPlayerInventory implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
public boolean isUseableByPlayer( EntityPlayer var1 )
|
||||
{
|
||||
return this.src.isUseableByPlayer( var1 );
|
||||
}
|
||||
@@ -106,15 +113,8 @@ public class AdaptorPlayerInventory implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
return this.src.isItemValidForSlot( i, itemstack );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public interface IInventoryDestination
|
||||
{
|
||||
|
||||
boolean canInsert( ItemStack stack );
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public interface IInventoryWrapper
|
||||
{
|
||||
|
||||
boolean canRemoveItemFromSlot(int x, ItemStack is);
|
||||
|
||||
boolean canRemoveItemFromSlot( int x, ItemStack is );
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
@@ -34,6 +35,7 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class IMEAdaptor extends InventoryAdaptor
|
||||
{
|
||||
|
||||
@@ -41,52 +43,37 @@ public class IMEAdaptor extends InventoryAdaptor
|
||||
final BaseActionSource src;
|
||||
int maxSlots = 0;
|
||||
|
||||
public IMEAdaptor(IMEInventory<IAEItemStack> input, BaseActionSource src) {
|
||||
public IMEAdaptor( IMEInventory<IAEItemStack> input, BaseActionSource src )
|
||||
{
|
||||
this.target = input;
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
IItemList<IAEItemStack> getList()
|
||||
{
|
||||
return this.target.getAvailableItems( AEApi.instance().storage().createItemList() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new IMEAdaptorIterator( this, this.getList() );
|
||||
}
|
||||
|
||||
public ItemStack doRemoveItemsFuzzy(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type, FuzzyMode fuzzyMode)
|
||||
IItemList<IAEItemStack> getList()
|
||||
{
|
||||
IAEItemStack reqFilter = AEItemStack.create( Filter );
|
||||
if ( reqFilter == null )
|
||||
return null;
|
||||
|
||||
IAEItemStack out = null;
|
||||
|
||||
for (IAEItemStack req : ImmutableList.copyOf( this.getList().findFuzzy( reqFilter, fuzzyMode ) ))
|
||||
{
|
||||
if ( req != null )
|
||||
{
|
||||
req.setStackSize( how_many );
|
||||
out = this.target.extractItems( req, type, this.src );
|
||||
if ( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return this.target.getAvailableItems( AEApi.instance().storage().createItemList() );
|
||||
}
|
||||
|
||||
public ItemStack doRemoveItems(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type)
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
return this.doRemoveItems( amount, filter, destination, Actionable.MODULATE );
|
||||
}
|
||||
|
||||
public ItemStack doRemoveItems( int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type )
|
||||
{
|
||||
IAEItemStack req = null;
|
||||
|
||||
if ( Filter == null )
|
||||
if( Filter == null )
|
||||
{
|
||||
IItemList<IAEItemStack> list = this.getList();
|
||||
if ( !list.isEmpty() )
|
||||
if( !list.isEmpty() )
|
||||
req = list.getFirstItem();
|
||||
}
|
||||
else
|
||||
@@ -94,67 +81,83 @@ public class IMEAdaptor extends InventoryAdaptor
|
||||
|
||||
IAEItemStack out = null;
|
||||
|
||||
if ( req != null )
|
||||
if( req != null )
|
||||
{
|
||||
req.setStackSize( how_many );
|
||||
out = this.target.extractItems( req, type, this.src );
|
||||
}
|
||||
|
||||
if ( out != null )
|
||||
if( out != null )
|
||||
return out.getItemStack();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
return this.doRemoveItems( amount, filter, destination, Actionable.MODULATE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination)
|
||||
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
return this.doRemoveItems( amount, filter, destination, Actionable.SIMULATE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
public ItemStack removeSimilarItems( int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
if ( filter == null )
|
||||
if( filter == null )
|
||||
return this.doRemoveItems( how_many, null, destination, Actionable.MODULATE );
|
||||
return this.doRemoveItemsFuzzy( how_many, filter, destination, Actionable.MODULATE, fuzzyMode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
public ItemStack doRemoveItemsFuzzy( int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type, FuzzyMode fuzzyMode )
|
||||
{
|
||||
if ( filter == null )
|
||||
IAEItemStack reqFilter = AEItemStack.create( Filter );
|
||||
if( reqFilter == null )
|
||||
return null;
|
||||
|
||||
IAEItemStack out = null;
|
||||
|
||||
for( IAEItemStack req : ImmutableList.copyOf( this.getList().findFuzzy( reqFilter, fuzzyMode ) ) )
|
||||
{
|
||||
if( req != null )
|
||||
{
|
||||
req.setStackSize( how_many );
|
||||
out = this.target.extractItems( req, type, this.src );
|
||||
if( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
if( filter == null )
|
||||
return this.doRemoveItems( amount, null, destination, Actionable.SIMULATE );
|
||||
return this.doRemoveItemsFuzzy( amount, filter, destination, Actionable.SIMULATE, fuzzyMode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack toBeAdded )
|
||||
public ItemStack addItems( ItemStack toBeAdded )
|
||||
{
|
||||
IAEItemStack in = AEItemStack.create( toBeAdded );
|
||||
if ( in != null )
|
||||
if( in != null )
|
||||
{
|
||||
IAEItemStack out = this.target.injectItems( in, Actionable.MODULATE, this.src );
|
||||
if ( out != null )
|
||||
if( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack toBeSimulated )
|
||||
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
||||
{
|
||||
IAEItemStack in = AEItemStack.create( toBeSimulated );
|
||||
if ( in != null )
|
||||
if( in != null )
|
||||
{
|
||||
IAEItemStack out = this.target.injectItems( in, Actionable.SIMULATE, this.src );
|
||||
if ( out != null )
|
||||
if( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
return null;
|
||||
@@ -165,5 +168,4 @@ public class IMEAdaptor extends InventoryAdaptor
|
||||
{
|
||||
return !this.getList().isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,25 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class IMEAdaptorIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
|
||||
final Iterator<IAEItemStack> stack;
|
||||
final ItemSlot slot = new ItemSlot();
|
||||
final IMEAdaptor parent;
|
||||
final int containerSize;
|
||||
int offset = 0;
|
||||
boolean hasNext;
|
||||
|
||||
final IMEAdaptor parent;
|
||||
final int containerSize;
|
||||
|
||||
public IMEAdaptorIterator(IMEAdaptor parent, IItemList<IAEItemStack> availableItems) {
|
||||
public IMEAdaptorIterator( IMEAdaptor parent, IItemList<IAEItemStack> availableItems )
|
||||
{
|
||||
this.stack = availableItems.iterator();
|
||||
this.containerSize = parent.maxSlots;
|
||||
this.parent = parent;
|
||||
@@ -52,12 +54,12 @@ public class IMEAdaptorIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
this.slot.slot = this.offset;
|
||||
this.offset++;
|
||||
this.slot.isExtractable=true;
|
||||
this.slot.isExtractable = true;
|
||||
|
||||
if ( this.parent.maxSlots < this.offset )
|
||||
if( this.parent.maxSlots < this.offset )
|
||||
this.parent.maxSlots = this.offset;
|
||||
|
||||
if ( this.hasNext )
|
||||
if( this.hasNext )
|
||||
{
|
||||
IAEItemStack item = this.stack.next();
|
||||
this.slot.setAEItemStack( item );
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -25,27 +26,28 @@ import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class IMEInventoryDestination implements IInventoryDestination
|
||||
{
|
||||
|
||||
final IMEInventory<IAEItemStack> me;
|
||||
|
||||
public IMEInventoryDestination(IMEInventory<IAEItemStack> o) {
|
||||
public IMEInventoryDestination( IMEInventory<IAEItemStack> o )
|
||||
{
|
||||
this.me = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack)
|
||||
public boolean canInsert( ItemStack stack )
|
||||
{
|
||||
|
||||
if ( stack == null )
|
||||
if( stack == null )
|
||||
return false;
|
||||
|
||||
IAEItemStack failed = this.me.injectItems( AEItemStack.create( stack ), Actionable.SIMULATE, null );
|
||||
|
||||
if ( failed == null )
|
||||
if( failed == null )
|
||||
return true;
|
||||
return failed.getStackSize() != stack.stackSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -25,19 +26,21 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class ItemListIgnoreCrafting<T extends IAEStack> implements IItemList<T>
|
||||
{
|
||||
|
||||
final IItemList<T> target;
|
||||
|
||||
public ItemListIgnoreCrafting(IItemList<T> cla) {
|
||||
public ItemListIgnoreCrafting( IItemList<T> cla )
|
||||
{
|
||||
this.target = cla;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(T option)
|
||||
public void add( T option )
|
||||
{
|
||||
if ( option != null && option.isCraftable() )
|
||||
if( option != null && option.isCraftable() )
|
||||
{
|
||||
option = (T) option.copy();
|
||||
option.setCraftable( false );
|
||||
@@ -47,19 +50,13 @@ public class ItemListIgnoreCrafting<T extends IAEStack> implements IItemList<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting(T option)
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findPrecise(T i)
|
||||
public T findPrecise( T i )
|
||||
{
|
||||
return this.target.findPrecise( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> findFuzzy(T input, FuzzyMode fuzzy)
|
||||
public Collection<T> findFuzzy( T input, FuzzyMode fuzzy )
|
||||
{
|
||||
return this.target.findFuzzy( input, fuzzy );
|
||||
}
|
||||
@@ -71,13 +68,19 @@ public class ItemListIgnoreCrafting<T extends IAEStack> implements IItemList<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage(T option)
|
||||
public void addStorage( T option )
|
||||
{
|
||||
this.target.addStorage( option );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable(T option)
|
||||
public void addCrafting( T option )
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable( T option )
|
||||
{
|
||||
this.target.addRequestable( option );
|
||||
}
|
||||
|
||||
@@ -18,42 +18,41 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class ItemSlot
|
||||
{
|
||||
|
||||
public int slot;
|
||||
|
||||
public boolean isExtractable;
|
||||
// one or the other..
|
||||
private IAEItemStack aeItemStack;
|
||||
private ItemStack itemStack;
|
||||
|
||||
public boolean isExtractable;
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return this.itemStack == null ? ( this.aeItemStack == null ? null : ( this.itemStack = this.aeItemStack.getItemStack() ) ) : this.itemStack;
|
||||
}
|
||||
|
||||
public void setItemStack(ItemStack is)
|
||||
public void setItemStack( ItemStack is )
|
||||
{
|
||||
this.aeItemStack = null;
|
||||
this.itemStack = is;
|
||||
}
|
||||
|
||||
public void setAEItemStack(IAEItemStack is)
|
||||
public IAEItemStack getAEItemStack()
|
||||
{
|
||||
return this.aeItemStack == null ? ( this.itemStack == null ? null : ( this.aeItemStack = AEItemStack.create( this.itemStack ) ) ) : this.aeItemStack;
|
||||
}
|
||||
|
||||
public void setAEItemStack( IAEItemStack is )
|
||||
{
|
||||
this.aeItemStack = is;
|
||||
this.itemStack = null;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return this.itemStack == null ? (this.aeItemStack == null ? null : (this.itemStack = this.aeItemStack.getItemStack())) : this.itemStack;
|
||||
}
|
||||
|
||||
public IAEItemStack getAEItemStack()
|
||||
{
|
||||
return this.aeItemStack == null ? (this.itemStack == null ? null : (this.aeItemStack = AEItemStack.create( this.itemStack ))) : this.aeItemStack;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -28,6 +29,7 @@ import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
|
||||
|
||||
public class WrapperBCPipe implements IInventory
|
||||
{
|
||||
|
||||
@@ -35,7 +37,8 @@ public class WrapperBCPipe implements IInventory
|
||||
final private TileEntity ad;
|
||||
final private ForgeDirection dir;
|
||||
|
||||
public WrapperBCPipe(TileEntity te, ForgeDirection d) {
|
||||
public WrapperBCPipe( TileEntity te, ForgeDirection d )
|
||||
{
|
||||
this.bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
||||
this.ad = te;
|
||||
this.dir = d;
|
||||
@@ -48,25 +51,25 @@ public class WrapperBCPipe implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
public ItemStack getStackInSlot( int i )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
public ItemStack decrStackSize( int i, int j )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
public ItemStack getStackInSlotOnClosing( int i )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
public void setInventorySlotContents( int i, ItemStack itemstack )
|
||||
{
|
||||
this.bc.addItemsToPipe( this.ad, itemstack, this.dir );
|
||||
}
|
||||
@@ -83,18 +86,6 @@ public class WrapperBCPipe implements IInventory
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
@@ -108,15 +99,26 @@ public class WrapperBCPipe implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
public boolean isUseableByPlayer( EntityPlayer entityplayer )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
public void openInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
return this.bc.canAddItemsToPipe( this.ad, itemstack, this.dir );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,50 +18,34 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
|
||||
public class WrapperChainedInventory implements IInventory
|
||||
{
|
||||
|
||||
static class InvOffset
|
||||
{
|
||||
|
||||
int offset;
|
||||
int size;
|
||||
IInventory i;
|
||||
}
|
||||
|
||||
int fullSize = 0;
|
||||
|
||||
private List<IInventory> l;
|
||||
private HashMap<Integer, InvOffset> offsets;
|
||||
|
||||
public WrapperChainedInventory(IInventory... inventories) {
|
||||
this.setInventory( inventories );
|
||||
}
|
||||
|
||||
public WrapperChainedInventory(List<IInventory> inventories) {
|
||||
this.setInventory( inventories );
|
||||
}
|
||||
|
||||
public void cycleOrder()
|
||||
public WrapperChainedInventory( IInventory... inventories )
|
||||
{
|
||||
if ( this.l.size() > 1 )
|
||||
{
|
||||
List<IInventory> newOrder = new ArrayList<IInventory>( this.l.size() );
|
||||
newOrder.add( this.l.get( this.l.size() - 1 ) );
|
||||
for (int x = 0; x < this.l.size() - 1; x++)
|
||||
newOrder.add( this.l.get( x ) );
|
||||
this.setInventory( newOrder );
|
||||
}
|
||||
this.setInventory( inventories );
|
||||
}
|
||||
|
||||
public void setInventory( IInventory... a )
|
||||
{
|
||||
this.l = ImmutableList.copyOf( a );
|
||||
this.calculateSizes();
|
||||
}
|
||||
|
||||
public void calculateSizes()
|
||||
@@ -69,14 +53,14 @@ public class WrapperChainedInventory implements IInventory
|
||||
this.offsets = new HashMap<Integer, WrapperChainedInventory.InvOffset>();
|
||||
|
||||
int offset = 0;
|
||||
for (IInventory in : this.l)
|
||||
for( IInventory in : this.l )
|
||||
{
|
||||
InvOffset io = new InvOffset();
|
||||
io.offset = offset;
|
||||
io.size = in.getSizeInventory();
|
||||
io.i = in;
|
||||
|
||||
for (int y = 0; y < io.size; y++)
|
||||
for( int y = 0; y < io.size; y++ )
|
||||
{
|
||||
this.offsets.put( y + io.offset, io );
|
||||
}
|
||||
@@ -87,32 +71,43 @@ public class WrapperChainedInventory implements IInventory
|
||||
this.fullSize = offset;
|
||||
}
|
||||
|
||||
public void setInventory(IInventory... a)
|
||||
public WrapperChainedInventory( List<IInventory> inventories )
|
||||
{
|
||||
this.l = ImmutableList.copyOf( a );
|
||||
this.calculateSizes();
|
||||
this.setInventory( inventories );
|
||||
}
|
||||
|
||||
public void setInventory(List<IInventory> a)
|
||||
public void setInventory( List<IInventory> a )
|
||||
{
|
||||
this.l = a;
|
||||
this.calculateSizes();
|
||||
}
|
||||
|
||||
public IInventory getInv(int idx)
|
||||
public void cycleOrder()
|
||||
{
|
||||
if( this.l.size() > 1 )
|
||||
{
|
||||
List<IInventory> newOrder = new ArrayList<IInventory>( this.l.size() );
|
||||
newOrder.add( this.l.get( this.l.size() - 1 ) );
|
||||
for( int x = 0; x < this.l.size() - 1; x++ )
|
||||
newOrder.add( this.l.get( x ) );
|
||||
this.setInventory( newOrder );
|
||||
}
|
||||
}
|
||||
|
||||
public IInventory getInv( int idx )
|
||||
{
|
||||
InvOffset io = this.offsets.get( idx );
|
||||
if ( io != null )
|
||||
if( io != null )
|
||||
{
|
||||
return io.i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getInvSlot(int idx)
|
||||
public int getInvSlot( int idx )
|
||||
{
|
||||
InvOffset io = this.offsets.get( idx );
|
||||
if ( io != null )
|
||||
if( io != null )
|
||||
{
|
||||
return idx - io.offset;
|
||||
}
|
||||
@@ -126,10 +121,10 @@ public class WrapperChainedInventory implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int idx)
|
||||
public ItemStack getStackInSlot( int idx )
|
||||
{
|
||||
InvOffset io = this.offsets.get( idx );
|
||||
if ( io != null )
|
||||
if( io != null )
|
||||
{
|
||||
return io.i.getStackInSlot( idx - io.offset );
|
||||
}
|
||||
@@ -137,10 +132,10 @@ public class WrapperChainedInventory implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int idx, int var2)
|
||||
public ItemStack decrStackSize( int idx, int var2 )
|
||||
{
|
||||
InvOffset io = this.offsets.get( idx );
|
||||
if ( io != null )
|
||||
if( io != null )
|
||||
{
|
||||
return io.i.decrStackSize( idx - io.offset, var2 );
|
||||
}
|
||||
@@ -148,10 +143,10 @@ public class WrapperChainedInventory implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int idx)
|
||||
public ItemStack getStackInSlotOnClosing( int idx )
|
||||
{
|
||||
InvOffset io = this.offsets.get( idx );
|
||||
if ( io != null )
|
||||
if( io != null )
|
||||
{
|
||||
return io.i.getStackInSlotOnClosing( idx - io.offset );
|
||||
}
|
||||
@@ -159,10 +154,10 @@ public class WrapperChainedInventory implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int idx, ItemStack var2)
|
||||
public void setInventorySlotContents( int idx, ItemStack var2 )
|
||||
{
|
||||
InvOffset io = this.offsets.get( idx );
|
||||
if ( io != null )
|
||||
if( io != null )
|
||||
{
|
||||
io.i.setInventorySlotContents( idx - io.offset, var2 );
|
||||
}
|
||||
@@ -174,12 +169,18 @@ public class WrapperChainedInventory implements IInventory
|
||||
return "ChainedInv";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
int smallest = 64;
|
||||
|
||||
for (IInventory i : this.l)
|
||||
for( IInventory i : this.l )
|
||||
smallest = Math.min( smallest, i.getInventoryStackLimit() );
|
||||
|
||||
return smallest;
|
||||
@@ -188,14 +189,14 @@ public class WrapperChainedInventory implements IInventory
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
for (IInventory i : this.l)
|
||||
for( IInventory i : this.l )
|
||||
{
|
||||
i.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
public boolean isUseableByPlayer( EntityPlayer var1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -211,20 +212,21 @@ public class WrapperChainedInventory implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int idx, ItemStack itemstack)
|
||||
public boolean isItemValidForSlot( int idx, ItemStack itemstack )
|
||||
{
|
||||
InvOffset io = this.offsets.get( idx );
|
||||
if ( io != null )
|
||||
if( io != null )
|
||||
{
|
||||
return io.i.isItemValidForSlot( idx - io.offset, itemstack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static class InvOffset
|
||||
{
|
||||
|
||||
int offset;
|
||||
int size;
|
||||
IInventory i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,20 +18,40 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class WrapperInvSlot
|
||||
{
|
||||
|
||||
private final IInventory inv;
|
||||
|
||||
public WrapperInvSlot( IInventory inv )
|
||||
{
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public IInventory getWrapper( int slot )
|
||||
{
|
||||
return new InternalInterfaceWrapper( this.inv, slot );
|
||||
}
|
||||
|
||||
protected boolean isItemValid( ItemStack itemstack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
class InternalInterfaceWrapper implements IInventory
|
||||
{
|
||||
|
||||
private final IInventory inv;
|
||||
private final int slot;
|
||||
|
||||
public InternalInterfaceWrapper(IInventory target, int slot) {
|
||||
public InternalInterfaceWrapper( IInventory target, int slot )
|
||||
{
|
||||
this.inv = target;
|
||||
this.slot = slot;
|
||||
}
|
||||
@@ -43,25 +63,25 @@ public class WrapperInvSlot
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
public ItemStack getStackInSlot( int i )
|
||||
{
|
||||
return this.inv.getStackInSlot( this.slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int num)
|
||||
public ItemStack decrStackSize( int i, int num )
|
||||
{
|
||||
return this.inv.decrStackSize( this.slot, num );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
public ItemStack getStackInSlotOnClosing( int i )
|
||||
{
|
||||
return this.inv.getStackInSlotOnClosing( this.slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
public void setInventorySlotContents( int i, ItemStack itemstack )
|
||||
{
|
||||
this.inv.setInventorySlotContents( this.slot, itemstack );
|
||||
}
|
||||
@@ -91,7 +111,7 @@ public class WrapperInvSlot
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
public boolean isUseableByPlayer( EntityPlayer entityplayer )
|
||||
{
|
||||
return this.inv.isUseableByPlayer( entityplayer );
|
||||
}
|
||||
@@ -109,26 +129,9 @@ public class WrapperInvSlot
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
return WrapperInvSlot.this.isItemValid( itemstack ) && this.inv.isItemValidForSlot( this.slot, itemstack );
|
||||
}
|
||||
}
|
||||
|
||||
private final IInventory inv;
|
||||
|
||||
public WrapperInvSlot(IInventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public IInventory getWrapper(int slot)
|
||||
{
|
||||
return new InternalInterfaceWrapper( this.inv, slot );
|
||||
}
|
||||
|
||||
protected boolean isItemValid(ItemStack itemstack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,25 +18,47 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class WrapperInventoryRange implements IInventory
|
||||
{
|
||||
|
||||
private final IInventory src;
|
||||
int[] slots;
|
||||
protected boolean ignoreValidItems = false;
|
||||
int[] slots;
|
||||
|
||||
public static String concatLines(int[] s, String separator)
|
||||
public WrapperInventoryRange( IInventory a, int[] s, boolean ignoreValid )
|
||||
{
|
||||
if ( s.length > 0 )
|
||||
this.src = a;
|
||||
this.slots = s;
|
||||
|
||||
if( this.slots == null )
|
||||
this.slots = new int[0];
|
||||
|
||||
this.ignoreValidItems = ignoreValid;
|
||||
}
|
||||
|
||||
public WrapperInventoryRange( IInventory a, int _min, int _size, boolean ignoreValid )
|
||||
{
|
||||
this.src = a;
|
||||
this.slots = new int[_size];
|
||||
for( int x = 0; x < _size; x++ )
|
||||
this.slots[x] = _min + x;
|
||||
this.ignoreValidItems = ignoreValid;
|
||||
}
|
||||
|
||||
public static String concatLines( int[] s, String separator )
|
||||
{
|
||||
if( s.length > 0 )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int value : s)
|
||||
for( int value : s )
|
||||
{
|
||||
if ( sb.length() > 0 )
|
||||
if( sb.length() > 0 )
|
||||
{
|
||||
sb.append( separator );
|
||||
}
|
||||
@@ -47,24 +69,6 @@ public class WrapperInventoryRange implements IInventory
|
||||
return "";
|
||||
}
|
||||
|
||||
public WrapperInventoryRange(IInventory a, int[] s, boolean ignoreValid) {
|
||||
this.src = a;
|
||||
this.slots = s;
|
||||
|
||||
if ( this.slots == null )
|
||||
this.slots = new int[0];
|
||||
|
||||
this.ignoreValidItems = ignoreValid;
|
||||
}
|
||||
|
||||
public WrapperInventoryRange(IInventory a, int _min, int _size, boolean ignoreValid) {
|
||||
this.src = a;
|
||||
this.slots = new int[_size];
|
||||
for (int x = 0; x < _size; x++)
|
||||
this.slots[x] = _min + x;
|
||||
this.ignoreValidItems = ignoreValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
@@ -72,25 +76,25 @@ public class WrapperInventoryRange implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1)
|
||||
public ItemStack getStackInSlot( int var1 )
|
||||
{
|
||||
return this.src.getStackInSlot( this.slots[var1] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2)
|
||||
public ItemStack decrStackSize( int var1, int var2 )
|
||||
{
|
||||
return this.src.decrStackSize( this.slots[var1], var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1)
|
||||
public ItemStack getStackInSlotOnClosing( int var1 )
|
||||
{
|
||||
return this.src.getStackInSlotOnClosing( this.slots[var1] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int var1, ItemStack var2)
|
||||
public void setInventorySlotContents( int var1, ItemStack var2 )
|
||||
{
|
||||
this.src.setInventorySlotContents( this.slots[var1], var2 );
|
||||
}
|
||||
@@ -101,6 +105,12 @@ public class WrapperInventoryRange implements IInventory
|
||||
return this.src.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
@@ -114,7 +124,7 @@ public class WrapperInventoryRange implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
public boolean isUseableByPlayer( EntityPlayer var1 )
|
||||
{
|
||||
return this.src.isUseableByPlayer( var1 );
|
||||
}
|
||||
@@ -132,18 +142,11 @@ public class WrapperInventoryRange implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
if ( this.ignoreValidItems )
|
||||
if( this.ignoreValidItems )
|
||||
return true;
|
||||
|
||||
return this.src.isItemValidForSlot( this.slots[i], itemstack );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,50 +18,52 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
|
||||
public class WrapperMCISidedInventory extends WrapperInventoryRange implements IInventoryWrapper
|
||||
{
|
||||
|
||||
private final ForgeDirection dir;
|
||||
final ISidedInventory side;
|
||||
private final ForgeDirection dir;
|
||||
|
||||
public WrapperMCISidedInventory(ISidedInventory a, ForgeDirection d) {
|
||||
public WrapperMCISidedInventory( ISidedInventory a, ForgeDirection d )
|
||||
{
|
||||
super( a, a.getAccessibleSlotsFromSide( d.ordinal() ), false );
|
||||
this.side = a;
|
||||
this.dir = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
public ItemStack decrStackSize( int var1, int var2 )
|
||||
{
|
||||
if( this.canRemoveItemFromSlot( var1, this.getStackInSlot( var1 ) ) )
|
||||
return super.decrStackSize( var1, var2 );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
|
||||
if ( this.ignoreValidItems )
|
||||
if( this.ignoreValidItems )
|
||||
return true;
|
||||
|
||||
if ( this.side.isItemValidForSlot( this.slots[i], itemstack ) )
|
||||
if( this.side.isItemValidForSlot( this.slots[i], itemstack ) )
|
||||
return this.side.canInsertItem( this.slots[i], itemstack, this.dir.ordinal() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveItemFromSlot(int i, ItemStack is)
|
||||
public boolean canRemoveItemFromSlot( int i, ItemStack is )
|
||||
{
|
||||
if ( is == null )
|
||||
if( is == null )
|
||||
return false;
|
||||
|
||||
return this.side.canExtractItem( this.slots[i], is, this.dir.ordinal() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2)
|
||||
{
|
||||
if ( this.canRemoveItemFromSlot( var1, this.getStackInSlot( var1 ) ) )
|
||||
return super.decrStackSize( var1, var2 );
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,19 +18,22 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
|
||||
public class WrapperTEPipe implements IInventory
|
||||
{
|
||||
|
||||
final TileEntity ad;
|
||||
final ForgeDirection dir;
|
||||
|
||||
public WrapperTEPipe(TileEntity te, ForgeDirection d) {
|
||||
public WrapperTEPipe( TileEntity te, ForgeDirection d )
|
||||
{
|
||||
this.ad = te;
|
||||
this.dir = d;
|
||||
}
|
||||
@@ -42,25 +45,25 @@ public class WrapperTEPipe implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
public ItemStack getStackInSlot( int i )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
public ItemStack decrStackSize( int i, int j )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
public ItemStack getStackInSlotOnClosing( int i )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
public void setInventorySlotContents( int i, ItemStack itemstack )
|
||||
{
|
||||
// ITE.addItemsToPipe( ad, itemstack, dir );
|
||||
}
|
||||
@@ -90,7 +93,7 @@ public class WrapperTEPipe implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
public boolean isUseableByPlayer( EntityPlayer entityplayer )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -108,9 +111,8 @@ public class WrapperTEPipe implements IInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
@@ -38,6 +39,7 @@ import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAETagCompound;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFluidStack, Comparable<AEFluidStack>
|
||||
{
|
||||
|
||||
@@ -45,33 +47,8 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
Fluid fluid;
|
||||
private IAETagCompound tagCompound;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
private AEFluidStack( AEFluidStack is )
|
||||
{
|
||||
return this.getFluidStack().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAETagCompound getTagCompound()
|
||||
{
|
||||
return this.tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(IAEFluidStack option)
|
||||
{
|
||||
if ( option == null )
|
||||
return;
|
||||
|
||||
// if ( priority < ((AEFluidStack) option).priority )
|
||||
// priority = ((AEFluidStack) option).priority;
|
||||
|
||||
this.incStackSize( option.getStackSize() );
|
||||
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
|
||||
this.setCraftable( this.isCraftable() || option.isCraftable() );
|
||||
}
|
||||
|
||||
private AEFluidStack(AEFluidStack is) {
|
||||
|
||||
this.fluid = is.fluid;
|
||||
this.stackSize = is.stackSize;
|
||||
@@ -83,85 +60,109 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
this.myHash = is.myHash;
|
||||
}
|
||||
|
||||
private AEFluidStack( FluidStack is ) {
|
||||
if ( is == null )
|
||||
private AEFluidStack( FluidStack is )
|
||||
{
|
||||
if( is == null )
|
||||
throw new RuntimeException( "Invalid Itemstack." );
|
||||
|
||||
this.fluid = is.getFluid();
|
||||
|
||||
if ( this.fluid == null )
|
||||
if( this.fluid == null )
|
||||
throw new RuntimeException( "Fluid is null." );
|
||||
|
||||
this.stackSize = is.amount;
|
||||
this.setCraftable( false );
|
||||
this.setCountRequestable( 0 );
|
||||
|
||||
this.myHash = this.fluid.hashCode() ^ (this.tagCompound == null ? 0 : System.identityHashCode( this.tagCompound ));
|
||||
this.myHash = this.fluid.hashCode() ^ ( this.tagCompound == null ? 0 : System.identityHashCode( this.tagCompound ) );
|
||||
}
|
||||
|
||||
public static AEFluidStack create(Object a)
|
||||
public static IAEFluidStack loadFluidStackFromNBT( NBTTagCompound i )
|
||||
{
|
||||
if ( a == null )
|
||||
ItemStack itemstack = ItemStack.loadItemStackFromNBT( i );
|
||||
if( itemstack == null )
|
||||
return null;
|
||||
if ( a instanceof AEFluidStack )
|
||||
((AEFluidStack) a).copy();
|
||||
if ( a instanceof FluidStack )
|
||||
AEFluidStack fluid = AEFluidStack.create( itemstack );
|
||||
// fluid.priority = i.getInteger( "Priority" );
|
||||
fluid.stackSize = i.getLong( "Cnt" );
|
||||
fluid.setCountRequestable( i.getLong( "Req" ) );
|
||||
fluid.setCraftable( i.getBoolean( "Craft" ) );
|
||||
return fluid;
|
||||
}
|
||||
|
||||
public static AEFluidStack create( Object a )
|
||||
{
|
||||
if( a == null )
|
||||
return null;
|
||||
if( a instanceof AEFluidStack )
|
||||
( (AEFluidStack) a ).copy();
|
||||
if( a instanceof FluidStack )
|
||||
return new AEFluidStack( (FluidStack) a );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object ia)
|
||||
public static IAEFluidStack loadFluidStackFromPacket( ByteBuf data ) throws IOException
|
||||
{
|
||||
if ( ia instanceof AEFluidStack )
|
||||
byte mask = data.readByte();
|
||||
// byte PriorityType = (byte) (mask & 0x03);
|
||||
byte StackType = (byte) ( ( mask & 0x0C ) >> 2 );
|
||||
byte CountReqType = (byte) ( ( mask & 0x30 ) >> 4 );
|
||||
boolean isCraftable = ( mask & 0x40 ) > 0;
|
||||
boolean hasTagCompound = ( mask & 0x80 ) > 0;
|
||||
|
||||
// don't send this...
|
||||
NBTTagCompound d = new NBTTagCompound();
|
||||
|
||||
byte len2 = data.readByte();
|
||||
byte[] name = new byte[len2];
|
||||
data.readBytes( name, 0, len2 );
|
||||
|
||||
d.setString( "FluidName", new String( name, "UTF-8" ) );
|
||||
d.setByte( "Count", (byte) 0 );
|
||||
|
||||
if( hasTagCompound )
|
||||
{
|
||||
return ((AEFluidStack) ia).fluid == this.fluid && this.tagCompound == ((AEFluidStack) ia).tagCompound;
|
||||
int len = data.readInt();
|
||||
|
||||
byte[] bd = new byte[len];
|
||||
data.readBytes( bd );
|
||||
|
||||
DataInputStream di = new DataInputStream( new ByteArrayInputStream( bd ) );
|
||||
d.setTag( "tag", CompressedStreamTools.read( di ) );
|
||||
}
|
||||
else if ( ia instanceof FluidStack )
|
||||
{
|
||||
FluidStack is = (FluidStack) ia;
|
||||
|
||||
if ( is.fluidID == this.fluid.getID() )
|
||||
{
|
||||
NBTTagCompound ta = (NBTTagCompound) this.tagCompound;
|
||||
NBTTagCompound tb = is.tag;
|
||||
if ( ta == tb )
|
||||
return true;
|
||||
// long priority = getPacketValue( PriorityType, data );
|
||||
long stackSize = getPacketValue( StackType, data );
|
||||
long countRequestable = getPacketValue( CountReqType, data );
|
||||
|
||||
if ( (ta == null && tb == null) || (ta != null && ta.hasNoTags() && tb == null) || (tb != null && tb.hasNoTags() && ta == null)
|
||||
|| (ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags()) )
|
||||
return true;
|
||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( d );
|
||||
if( fluidStack == null )
|
||||
return null;
|
||||
|
||||
if ( (ta == null && tb != null) || (ta != null && tb == null) )
|
||||
return false;
|
||||
|
||||
if ( AESharedNBT.isShared( tb ) )
|
||||
return ta == tb;
|
||||
|
||||
return Platform.NBTEqualityTest( ta, tb );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
AEFluidStack fluid = AEFluidStack.create( fluidStack );
|
||||
// fluid.priority = (int) priority;
|
||||
fluid.stackSize = stackSize;
|
||||
fluid.setCountRequestable( countRequestable );
|
||||
fluid.setCraftable( isCraftable );
|
||||
return fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluidStack()
|
||||
public void add( IAEFluidStack option )
|
||||
{
|
||||
FluidStack is = new FluidStack( this.fluid, (int) Math.min( Integer.MAX_VALUE, this.stackSize ) );
|
||||
if ( this.tagCompound != null )
|
||||
is.tag = this.tagCompound.getNBTTagCompoundCopy();
|
||||
if( option == null )
|
||||
return;
|
||||
|
||||
return is;
|
||||
// if ( priority < ((AEFluidStack) option).priority )
|
||||
// priority = ((AEFluidStack) option).priority;
|
||||
|
||||
this.incStackSize( option.getStackSize() );
|
||||
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
|
||||
this.setCraftable( this.isCraftable() || option.isCraftable() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack copy()
|
||||
{
|
||||
return new AEFluidStack( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound i)
|
||||
public void writeToNBT( NBTTagCompound i )
|
||||
{
|
||||
/*
|
||||
* Mojang Fucked this over ; GC Optimization - Ugly Yes, but it saves a lot in the memory department.
|
||||
@@ -196,123 +197,35 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
/*
|
||||
* if ( Craft != null && Craft instanceof NBTTagByte ) ((NBTTagByte) Craft).data = (byte) (this.isCraftable() ?
|
||||
* 1 : 0); else
|
||||
*/i.setBoolean( "Craft", this.isCraftable() );
|
||||
*/
|
||||
i.setBoolean( "Craft", this.isCraftable() );
|
||||
|
||||
if ( this.tagCompound != null )
|
||||
if( this.tagCompound != null )
|
||||
i.setTag( "tag", (NBTTagCompound) this.tagCompound );
|
||||
else
|
||||
i.removeTag( "tag" );
|
||||
|
||||
}
|
||||
|
||||
public static IAEFluidStack loadFluidStackFromNBT(NBTTagCompound i)
|
||||
{
|
||||
ItemStack itemstack = ItemStack.loadItemStackFromNBT( i );
|
||||
if ( itemstack == null )
|
||||
return null;
|
||||
AEFluidStack fluid = AEFluidStack.create( itemstack );
|
||||
// fluid.priority = i.getInteger( "Priority" );
|
||||
fluid.stackSize = i.getLong( "Cnt" );
|
||||
fluid.setCountRequestable( i.getLong( "Req" ) );
|
||||
fluid.setCraftable( i.getBoolean( "Craft" ) );
|
||||
return fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
public boolean fuzzyComparison( Object st, FuzzyMode mode )
|
||||
{
|
||||
return this.tagCompound != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.myHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AEFluidStack b)
|
||||
{
|
||||
int diff = this.hashCode() - b.hashCode();
|
||||
return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeIdentity(ByteBuf i) throws IOException
|
||||
{
|
||||
byte[] name = this.fluid.getName().getBytes( "UTF-8" );
|
||||
i.writeByte( (byte) name.length );
|
||||
i.writeBytes( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
void readNBT(ByteBuf i) throws IOException
|
||||
{
|
||||
if ( this.hasTagCompound() )
|
||||
if( st instanceof FluidStack )
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
CompressedStreamTools.write( (NBTTagCompound) this.tagCompound, data );
|
||||
|
||||
byte[] tagBytes = bytes.toByteArray();
|
||||
int size = tagBytes.length;
|
||||
|
||||
i.writeInt( size );
|
||||
i.writeBytes( tagBytes );
|
||||
}
|
||||
}
|
||||
|
||||
public static IAEFluidStack loadFluidStackFromPacket(ByteBuf data) throws IOException
|
||||
{
|
||||
byte mask = data.readByte();
|
||||
// byte PriorityType = (byte) (mask & 0x03);
|
||||
byte StackType = (byte) ((mask & 0x0C) >> 2);
|
||||
byte CountReqType = (byte) ((mask & 0x30) >> 4);
|
||||
boolean isCraftable = (mask & 0x40) > 0;
|
||||
boolean hasTagCompound = (mask & 0x80) > 0;
|
||||
|
||||
// don't send this...
|
||||
NBTTagCompound d = new NBTTagCompound();
|
||||
|
||||
byte len2 = data.readByte();
|
||||
byte[] name = new byte[len2];
|
||||
data.readBytes( name, 0, len2 );
|
||||
|
||||
d.setString( "FluidName", new String( name, "UTF-8" ) );
|
||||
d.setByte( "Count", (byte) 0 );
|
||||
|
||||
if ( hasTagCompound )
|
||||
{
|
||||
int len = data.readInt();
|
||||
|
||||
byte[] bd = new byte[len];
|
||||
data.readBytes( bd );
|
||||
|
||||
DataInputStream di = new DataInputStream( new ByteArrayInputStream( bd ) );
|
||||
d.setTag( "tag", CompressedStreamTools.read( di ) );
|
||||
return ( (FluidStack) st ).getFluid() == this.fluid;
|
||||
}
|
||||
|
||||
// long priority = getPacketValue( PriorityType, data );
|
||||
long stackSize = getPacketValue( StackType, data );
|
||||
long countRequestable = getPacketValue( CountReqType, data );
|
||||
if( st instanceof IAEFluidStack )
|
||||
{
|
||||
return ( (IAEFluidStack) st ).getFluid() == this.fluid;
|
||||
}
|
||||
|
||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( d );
|
||||
if ( fluidStack == null )
|
||||
return null;
|
||||
|
||||
AEFluidStack fluid = AEFluidStack.create( fluidStack );
|
||||
// fluid.priority = (int) priority;
|
||||
fluid.stackSize = stackSize;
|
||||
fluid.setCountRequestable( countRequestable );
|
||||
fluid.setCraftable( isCraftable );
|
||||
return fluid;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fluid getFluid()
|
||||
public IAEFluidStack copy()
|
||||
{
|
||||
return this.fluid;
|
||||
return new AEFluidStack( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -324,19 +237,9 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fuzzyComparison(Object st, FuzzyMode mode)
|
||||
public IAETagCompound getTagCompound()
|
||||
{
|
||||
if ( st instanceof FluidStack )
|
||||
{
|
||||
return ((FluidStack) st).getFluid() == this.fluid;
|
||||
}
|
||||
|
||||
if ( st instanceof IAEFluidStack )
|
||||
{
|
||||
return ((IAEFluidStack) st).getFluid() == this.fluid;
|
||||
}
|
||||
|
||||
return false;
|
||||
return this.tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -357,4 +260,103 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
return StorageChannel.FLUIDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo( AEFluidStack b )
|
||||
{
|
||||
int diff = this.hashCode() - b.hashCode();
|
||||
return diff > 0 ? 1 : ( diff < 0 ? -1 : 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.myHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object ia )
|
||||
{
|
||||
if( ia instanceof AEFluidStack )
|
||||
{
|
||||
return ( (AEFluidStack) ia ).fluid == this.fluid && this.tagCompound == ( (AEFluidStack) ia ).tagCompound;
|
||||
}
|
||||
else if( ia instanceof FluidStack )
|
||||
{
|
||||
FluidStack is = (FluidStack) ia;
|
||||
|
||||
if( is.fluidID == this.fluid.getID() )
|
||||
{
|
||||
NBTTagCompound ta = (NBTTagCompound) this.tagCompound;
|
||||
NBTTagCompound tb = is.tag;
|
||||
if( ta == tb )
|
||||
return true;
|
||||
|
||||
if( ( ta == null && tb == null ) || ( ta != null && ta.hasNoTags() && tb == null ) || ( tb != null && tb.hasNoTags() && ta == null ) || ( ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags() ) )
|
||||
return true;
|
||||
|
||||
if( ( ta == null && tb != null ) || ( ta != null && tb == null ) )
|
||||
return false;
|
||||
|
||||
if( AESharedNBT.isShared( tb ) )
|
||||
return ta == tb;
|
||||
|
||||
return Platform.NBTEqualityTest( ta, tb );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getFluidStack().toString();
|
||||
} @Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return this.tagCompound != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluidStack()
|
||||
{
|
||||
FluidStack is = new FluidStack( this.fluid, (int) Math.min( Integer.MAX_VALUE, this.stackSize ) );
|
||||
if( this.tagCompound != null )
|
||||
is.tag = this.tagCompound.getNBTTagCompoundCopy();
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fluid getFluid()
|
||||
{
|
||||
return this.fluid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
void writeIdentity( ByteBuf i ) throws IOException
|
||||
{
|
||||
byte[] name = this.fluid.getName().getBytes( "UTF-8" );
|
||||
i.writeByte( (byte) name.length );
|
||||
i.writeBytes( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
void readNBT( ByteBuf i ) throws IOException
|
||||
{
|
||||
if( this.hasTagCompound() )
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
CompressedStreamTools.write( (NBTTagCompound) this.tagCompound, data );
|
||||
|
||||
byte[] tagBytes = bytes.toByteArray();
|
||||
int size = tagBytes.length;
|
||||
|
||||
i.writeInt( size );
|
||||
i.writeBytes( tagBytes );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
@@ -30,37 +31,30 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class AEItemDef
|
||||
{
|
||||
|
||||
public int myHash;
|
||||
|
||||
public int def;
|
||||
|
||||
public final int itemID;
|
||||
public final Item item;
|
||||
public int damageValue;
|
||||
|
||||
public int displayDamage;
|
||||
public int maxDamage;
|
||||
|
||||
public AESharedNBT tagCompound;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String displayName;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List tooltip;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public UniqueIdentifier uniqueID;
|
||||
|
||||
public OreReference isOre;
|
||||
|
||||
static final AESharedNBT LOW_TAG = new AESharedNBT( Integer.MIN_VALUE );
|
||||
static final AESharedNBT HIGH_TAG = new AESharedNBT( Integer.MAX_VALUE );
|
||||
public final int itemID;
|
||||
public final Item item;
|
||||
public int myHash;
|
||||
public int def;
|
||||
public int damageValue;
|
||||
public int displayDamage;
|
||||
public int maxDamage;
|
||||
public AESharedNBT tagCompound;
|
||||
@SideOnly( Side.CLIENT )
|
||||
public String displayName;
|
||||
@SideOnly( Side.CLIENT )
|
||||
public List tooltip;
|
||||
@SideOnly( Side.CLIENT )
|
||||
public UniqueIdentifier uniqueID;
|
||||
public OreReference isOre;
|
||||
|
||||
public AEItemDef(Item it) {
|
||||
public AEItemDef( Item it )
|
||||
{
|
||||
this.item = it;
|
||||
this.itemID = Item.getIdFromItem( it );
|
||||
}
|
||||
@@ -78,32 +72,27 @@ public class AEItemDef
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( obj == null )
|
||||
if( obj == null )
|
||||
return false;
|
||||
if ( this.getClass() != obj.getClass() )
|
||||
if( this.getClass() != obj.getClass() )
|
||||
return false;
|
||||
AEItemDef other = (AEItemDef) obj;
|
||||
return other.damageValue == this.damageValue && other.item == this.item && this.tagCompound == other.tagCompound;
|
||||
}
|
||||
|
||||
public int getDamageValueHack(ItemStack is)
|
||||
{
|
||||
return Items.blaze_rod.getDamage( is );
|
||||
}
|
||||
|
||||
public boolean isItem(ItemStack otherStack)
|
||||
public boolean isItem( ItemStack otherStack )
|
||||
{
|
||||
// hackery!
|
||||
int dmg = this.getDamageValueHack( otherStack );
|
||||
|
||||
if ( this.item == otherStack.getItem() && dmg == this.damageValue )
|
||||
if( this.item == otherStack.getItem() && dmg == this.damageValue )
|
||||
{
|
||||
if ( (this.tagCompound != null) == otherStack.hasTagCompound() )
|
||||
if( ( this.tagCompound != null ) == otherStack.hasTagCompound() )
|
||||
return true;
|
||||
|
||||
if ( this.tagCompound != null && otherStack.hasTagCompound() )
|
||||
if( this.tagCompound != null && otherStack.hasTagCompound() )
|
||||
return Platform.NBTEqualityTest( this.tagCompound, otherStack.getTagCompound() );
|
||||
|
||||
return true;
|
||||
@@ -111,9 +100,14 @@ public class AEItemDef
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getDamageValueHack( ItemStack is )
|
||||
{
|
||||
return Items.blaze_rod.getDamage( is );
|
||||
}
|
||||
|
||||
public void reHash()
|
||||
{
|
||||
this.def = this.itemID << Platform.DEF_OFFSET | this.damageValue;
|
||||
this.myHash = this.def ^ (this.tagCompound == null ? 0 : System.identityHashCode( this.tagCompound ));
|
||||
this.myHash = this.def ^ ( this.tagCompound == null ? 0 : System.identityHashCode( this.tagCompound ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,51 +396,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.def.myHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object ia )
|
||||
{
|
||||
if( ia instanceof AEItemStack )
|
||||
{
|
||||
return ( (AEItemStack) ia ).def.equals( this.def );// && def.tagCompound == ((AEItemStack) ia).def.tagCompound;
|
||||
}
|
||||
else if( ia instanceof ItemStack )
|
||||
{
|
||||
ItemStack is = (ItemStack) ia;
|
||||
|
||||
if( is.getItem() == this.def.item && is.getItemDamage() == this.def.damageValue )
|
||||
{
|
||||
NBTTagCompound ta = this.def.tagCompound;
|
||||
NBTTagCompound tb = is.getTagCompound();
|
||||
if( ta == tb )
|
||||
return true;
|
||||
|
||||
if( ( ta == null && tb == null ) || ( ta != null && ta.hasNoTags() && tb == null ) || ( tb != null && tb.hasNoTags() && ta == null ) || ( ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags() ) )
|
||||
return true;
|
||||
|
||||
if( ( ta == null && tb != null ) || ( ta != null && tb == null ) )
|
||||
return false;
|
||||
|
||||
if( AESharedNBT.isShared( tb ) )
|
||||
return ta == tb;
|
||||
|
||||
return Platform.NBTEqualityTest( ta, tb );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getItemStack().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
@@ -487,6 +442,51 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
return this.def.isItem( otherStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.def.myHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object ia )
|
||||
{
|
||||
if( ia instanceof AEItemStack )
|
||||
{
|
||||
return ( (AEItemStack) ia ).def.equals( this.def );// && def.tagCompound == ((AEItemStack) ia).def.tagCompound;
|
||||
}
|
||||
else if( ia instanceof ItemStack )
|
||||
{
|
||||
ItemStack is = (ItemStack) ia;
|
||||
|
||||
if( is.getItem() == this.def.item && is.getItemDamage() == this.def.damageValue )
|
||||
{
|
||||
NBTTagCompound ta = this.def.tagCompound;
|
||||
NBTTagCompound tb = is.getTagCompound();
|
||||
if( ta == tb )
|
||||
return true;
|
||||
|
||||
if( ( ta == null && tb == null ) || ( ta != null && ta.hasNoTags() && tb == null ) || ( tb != null && tb.hasNoTags() && ta == null ) || ( ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags() ) )
|
||||
return true;
|
||||
|
||||
if( ( ta == null && tb != null ) || ( ta != null && tb == null ) )
|
||||
return false;
|
||||
|
||||
if( AESharedNBT.isShared( tb ) )
|
||||
return ta == tb;
|
||||
|
||||
return Platform.NBTEqualityTest( ta, tb );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getItemStack().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo( AEItemStack b )
|
||||
{
|
||||
@@ -553,37 +553,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
return uniqueIdentifier.modId == null ? "** Null" : uniqueIdentifier.modId;
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeIdentity( ByteBuf i ) throws IOException
|
||||
{
|
||||
i.writeShort( Item.itemRegistry.getIDForObject( this.def.item ) );
|
||||
i.writeShort( this.getItemDamage() );
|
||||
}
|
||||
|
||||
@Override
|
||||
void readNBT( ByteBuf i ) throws IOException
|
||||
{
|
||||
if( this.hasTagCompound() )
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
CompressedStreamTools.write( (NBTTagCompound) this.getTagCompound(), data );
|
||||
|
||||
byte[] tagBytes = bytes.toByteArray();
|
||||
int size = tagBytes.length;
|
||||
|
||||
i.writeInt( size );
|
||||
i.writeBytes( tagBytes );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return this.def.tagCompound != null;
|
||||
}
|
||||
|
||||
public IAEItemStack getLow( FuzzyMode fuzzy, boolean ignoreMeta )
|
||||
{
|
||||
AEItemStack bottom = new AEItemStack( this );
|
||||
@@ -666,4 +635,35 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
{
|
||||
return this.def.isOre != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeIdentity( ByteBuf i ) throws IOException
|
||||
{
|
||||
i.writeShort( Item.itemRegistry.getIDForObject( this.def.item ) );
|
||||
i.writeShort( this.getItemDamage() );
|
||||
}
|
||||
|
||||
@Override
|
||||
void readNBT( ByteBuf i ) throws IOException
|
||||
{
|
||||
if( this.hasTagCompound() )
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
CompressedStreamTools.write( (NBTTagCompound) this.getTagCompound(), data );
|
||||
|
||||
byte[] tagBytes = bytes.toByteArray();
|
||||
int size = tagBytes.length;
|
||||
|
||||
i.writeInt( size );
|
||||
i.writeBytes( tagBytes );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return this.def.tagCompound != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@@ -30,54 +31,100 @@ import appeng.api.features.IItemComparison;
|
||||
import appeng.api.storage.data.IAETagCompound;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
/*
|
||||
* this is used for the shared NBT Cache.
|
||||
*/
|
||||
public class AESharedNBT extends NBTTagCompound implements IAETagCompound
|
||||
{
|
||||
|
||||
/*
|
||||
* Shared Tag Compound Cache.
|
||||
*/
|
||||
private static final WeakHashMap<SharedSearchObject, WeakReference<SharedSearchObject>> SHARED_TAG_COMPOUND = new WeakHashMap<SharedSearchObject, WeakReference<SharedSearchObject>>();
|
||||
private final Item item;
|
||||
private final int meta;
|
||||
private int hash;
|
||||
public SharedSearchObject sso;
|
||||
private int hash;
|
||||
private IItemComparison comp;
|
||||
|
||||
public int getHash()
|
||||
private AESharedNBT( Item itemID, int damageValue )
|
||||
{
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemComparison getSpecialComparison()
|
||||
{
|
||||
return this.comp;
|
||||
}
|
||||
|
||||
private AESharedNBT(Item itemID, int damageValue) {
|
||||
super();
|
||||
this.item = itemID;
|
||||
this.meta = damageValue;
|
||||
}
|
||||
|
||||
public AESharedNBT(int fakeValue) {
|
||||
public AESharedNBT( int fakeValue )
|
||||
{
|
||||
super();
|
||||
this.item = null;
|
||||
this.meta = 0;
|
||||
this.hash = fakeValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTTagCompoundCopy()
|
||||
/*
|
||||
* Debug purposes.
|
||||
*/
|
||||
public static int sharedTagLoad()
|
||||
{
|
||||
return (NBTTagCompound) this.copy();
|
||||
return SHARED_TAG_COMPOUND.size();
|
||||
}
|
||||
|
||||
public static AESharedNBT createFromCompound(Item itemID, int damageValue, NBTTagCompound c)
|
||||
/*
|
||||
* Returns an NBT Compound that is used for accelerating comparisons.
|
||||
*/
|
||||
synchronized public static NBTTagCompound getSharedTagCompound( NBTTagCompound tagCompound, ItemStack s )
|
||||
{
|
||||
if( tagCompound.hasNoTags() )
|
||||
return null;
|
||||
|
||||
Item item = s.getItem();
|
||||
int meta = -1;
|
||||
if( s.getItem() != null && s.isItemStackDamageable() && s.getHasSubtypes() )
|
||||
meta = s.getItemDamage();
|
||||
|
||||
if( isShared( tagCompound ) )
|
||||
return tagCompound;
|
||||
|
||||
SharedSearchObject sso = new SharedSearchObject( item, meta, tagCompound );
|
||||
|
||||
WeakReference<SharedSearchObject> c = SHARED_TAG_COMPOUND.get( sso );
|
||||
if( c != null )
|
||||
{
|
||||
SharedSearchObject cg = c.get();
|
||||
if( cg != null )
|
||||
return cg.shared; // I don't think I really need to check this
|
||||
// as its already certain to exist..
|
||||
}
|
||||
|
||||
AESharedNBT clone = AESharedNBT.createFromCompound( item, meta, tagCompound );
|
||||
sso.compound = (NBTTagCompound) sso.compound.copy(); // prevent
|
||||
// modification
|
||||
// of data based
|
||||
// on original
|
||||
// item.
|
||||
sso.shared = clone;
|
||||
clone.sso = sso;
|
||||
|
||||
SHARED_TAG_COMPOUND.put( sso, new WeakReference<SharedSearchObject>( sso ) );
|
||||
return clone;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns true if the compound is part of the shared compound system ( and can thus be compared directly ).
|
||||
*/
|
||||
public static boolean isShared( NBTTagCompound ta )
|
||||
{
|
||||
return ta instanceof AESharedNBT;
|
||||
}
|
||||
|
||||
public static AESharedNBT createFromCompound( Item itemID, int damageValue, NBTTagCompound c )
|
||||
{
|
||||
AESharedNBT x = new AESharedNBT( itemID, damageValue );
|
||||
|
||||
// c.getTags()
|
||||
for (Object o : c.func_150296_c())
|
||||
for( Object o : c.func_150296_c() )
|
||||
{
|
||||
String name = (String) o;
|
||||
x.setTag( name, c.getTag( name ).copy() );
|
||||
@@ -92,25 +139,42 @@ public class AESharedNBT extends NBTTagCompound implements IAETagCompound
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object par1Obj)
|
||||
public int getHash()
|
||||
{
|
||||
if ( par1Obj instanceof AESharedNBT )
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTTagCompoundCopy()
|
||||
{
|
||||
return (NBTTagCompound) this.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemComparison getSpecialComparison()
|
||||
{
|
||||
return this.comp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object par1Obj )
|
||||
{
|
||||
if( par1Obj instanceof AESharedNBT )
|
||||
return this == par1Obj;
|
||||
return super.equals( par1Obj );
|
||||
}
|
||||
|
||||
public boolean matches(Item item, int meta, int orderlessHash)
|
||||
public boolean matches( Item item, int meta, int orderlessHash )
|
||||
{
|
||||
return item == this.item && this.meta == meta && this.hash == orderlessHash;
|
||||
}
|
||||
|
||||
public boolean comparePreciseWithRegistry(AESharedNBT tagCompound)
|
||||
public boolean comparePreciseWithRegistry( AESharedNBT tagCompound )
|
||||
{
|
||||
if ( this == tagCompound )
|
||||
if( this == tagCompound )
|
||||
return true;
|
||||
|
||||
if ( this.comp != null && tagCompound.comp != null )
|
||||
if( this.comp != null && tagCompound.comp != null )
|
||||
{
|
||||
return this.comp.sameAsPrecise( tagCompound.comp );
|
||||
}
|
||||
@@ -118,83 +182,21 @@ public class AESharedNBT extends NBTTagCompound implements IAETagCompound
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean compareFuzzyWithRegistry(AESharedNBT tagCompound)
|
||||
public boolean compareFuzzyWithRegistry( AESharedNBT tagCompound )
|
||||
{
|
||||
if ( this == tagCompound )
|
||||
if( this == tagCompound )
|
||||
return true;
|
||||
if ( tagCompound == null )
|
||||
if( tagCompound == null )
|
||||
return false;
|
||||
|
||||
if ( this.comp == tagCompound.comp )
|
||||
if( this.comp == tagCompound.comp )
|
||||
return true;
|
||||
|
||||
if ( this.comp != null )
|
||||
if( this.comp != null )
|
||||
{
|
||||
return this.comp.sameAsFuzzy( tagCompound.comp );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Shared Tag Compound Cache.
|
||||
*/
|
||||
private static final WeakHashMap<SharedSearchObject, WeakReference<SharedSearchObject>> SHARED_TAG_COMPOUND = new WeakHashMap<SharedSearchObject, WeakReference<SharedSearchObject>>();
|
||||
|
||||
/*
|
||||
* Debug purposes.
|
||||
*/
|
||||
public static int sharedTagLoad()
|
||||
{
|
||||
return SHARED_TAG_COMPOUND.size();
|
||||
}
|
||||
|
||||
/*
|
||||
* returns true if the compound is part of the shared compound system ( and can thus be compared directly ).
|
||||
*/
|
||||
public static boolean isShared(NBTTagCompound ta)
|
||||
{
|
||||
return ta instanceof AESharedNBT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns an NBT Compound that is used for accelerating comparisons.
|
||||
*/
|
||||
synchronized public static NBTTagCompound getSharedTagCompound(NBTTagCompound tagCompound, ItemStack s)
|
||||
{
|
||||
if ( tagCompound.hasNoTags() )
|
||||
return null;
|
||||
|
||||
Item item = s.getItem();
|
||||
int meta = -1;
|
||||
if ( s.getItem() != null && s.isItemStackDamageable() && s.getHasSubtypes() )
|
||||
meta = s.getItemDamage();
|
||||
|
||||
if ( isShared( tagCompound ) )
|
||||
return tagCompound;
|
||||
|
||||
SharedSearchObject sso = new SharedSearchObject( item, meta, tagCompound );
|
||||
|
||||
WeakReference<SharedSearchObject> c = SHARED_TAG_COMPOUND.get( sso );
|
||||
if ( c != null )
|
||||
{
|
||||
SharedSearchObject cg = c.get();
|
||||
if ( cg != null )
|
||||
return cg.shared; // I don't think I really need to check this
|
||||
// as its already certain to exist..
|
||||
}
|
||||
|
||||
AESharedNBT clone = AESharedNBT.createFromCompound( item, meta, tagCompound );
|
||||
sso.compound = (NBTTagCompound) sso.compound.copy(); // prevent
|
||||
// modification
|
||||
// of data based
|
||||
// on original
|
||||
// item.
|
||||
sso.shared = clone;
|
||||
clone.sso = sso;
|
||||
|
||||
SHARED_TAG_COMPOUND.put( sso, new WeakReference<SharedSearchObject>( sso ) );
|
||||
return clone;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,12 +18,14 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
|
||||
public abstract class AEStack<StackType extends IAEStack> implements IAEStack<StackType>
|
||||
{
|
||||
|
||||
@@ -31,10 +33,67 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
|
||||
protected long stackSize;
|
||||
protected long countRequestable;
|
||||
|
||||
@Override
|
||||
public boolean isMeaningful()
|
||||
static long getPacketValue( byte type, ByteBuf tag )
|
||||
{
|
||||
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
|
||||
if( type == 0 )
|
||||
{
|
||||
long l = tag.readByte();
|
||||
l -= Byte.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if( type == 1 )
|
||||
{
|
||||
long l = tag.readShort();
|
||||
l -= Short.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if( type == 2 )
|
||||
{
|
||||
long l = tag.readInt();
|
||||
l -= Integer.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
|
||||
return tag.readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStackSize()
|
||||
{
|
||||
return this.stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setStackSize( long ss )
|
||||
{
|
||||
this.stackSize = ss;
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCountRequestable()
|
||||
{
|
||||
return this.countRequestable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setCountRequestable( long countRequestable )
|
||||
{
|
||||
this.countRequestable = countRequestable;
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftable()
|
||||
{
|
||||
return this.isCraftable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setCraftable( boolean isCraftable )
|
||||
{
|
||||
this.isCraftable = isCraftable;
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,127 +107,39 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStackSize()
|
||||
public boolean isMeaningful()
|
||||
{
|
||||
return this.stackSize;
|
||||
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setStackSize(long ss)
|
||||
{
|
||||
this.stackSize = ss;
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCountRequestable()
|
||||
{
|
||||
return this.countRequestable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setCountRequestable(long countRequestable)
|
||||
{
|
||||
this.countRequestable = countRequestable;
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftable()
|
||||
{
|
||||
return this.isCraftable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setCraftable(boolean isCraftable)
|
||||
{
|
||||
this.isCraftable = isCraftable;
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decStackSize(long i)
|
||||
{
|
||||
this.stackSize -= i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incStackSize(long i)
|
||||
public void incStackSize( long i )
|
||||
{
|
||||
this.stackSize += i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decCountRequestable(long i)
|
||||
public void decStackSize( long i )
|
||||
{
|
||||
this.stackSize -= i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incCountRequestable( long i )
|
||||
{
|
||||
this.countRequestable += i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decCountRequestable( long i )
|
||||
{
|
||||
this.countRequestable -= i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incCountRequestable(long i)
|
||||
public void writeToPacket( ByteBuf i ) throws IOException
|
||||
{
|
||||
this.countRequestable += i;
|
||||
}
|
||||
|
||||
void putPacketValue(ByteBuf tag, 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 );
|
||||
}
|
||||
|
||||
static long getPacketValue(byte type, ByteBuf tag)
|
||||
{
|
||||
if ( type == 0 )
|
||||
{
|
||||
long l = tag.readByte();
|
||||
l -= Byte.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if ( type == 1 )
|
||||
{
|
||||
long l = tag.readShort();
|
||||
l -= Short.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if ( type == 2 )
|
||||
{
|
||||
long l = tag.readInt();
|
||||
l -= Integer.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
|
||||
return tag.readLong();
|
||||
}
|
||||
|
||||
byte getType(long num)
|
||||
{
|
||||
if ( num <= 255 )
|
||||
return 0;
|
||||
else if ( num <= 65535 )
|
||||
return 1;
|
||||
else if ( num <= 4294967295L )
|
||||
return 2;
|
||||
else
|
||||
return 3;
|
||||
}
|
||||
|
||||
abstract void writeIdentity(ByteBuf i) throws IOException;
|
||||
|
||||
abstract void readNBT(ByteBuf i) throws IOException;
|
||||
|
||||
abstract boolean hasTagCompound();
|
||||
|
||||
@Override
|
||||
public void writeToPacket(ByteBuf i) throws IOException
|
||||
{
|
||||
byte mask = (byte) (this.getType( 0 ) | (this.getType( this.stackSize ) << 2) | (this.getType( this.countRequestable ) << 4) | ((byte) (this.isCraftable ? 1 : 0) << 6) | (this.hasTagCompound() ? 1
|
||||
: 0) << 7);
|
||||
byte mask = (byte) ( this.getType( 0 ) | ( this.getType( this.stackSize ) << 2 ) | ( this.getType( this.countRequestable ) << 4 ) | ( (byte) ( this.isCraftable ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
|
||||
|
||||
i.writeByte( mask );
|
||||
this.writeIdentity( i );
|
||||
@@ -180,4 +151,33 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
|
||||
this.putPacketValue( i, this.countRequestable );
|
||||
}
|
||||
|
||||
byte getType( long num )
|
||||
{
|
||||
if( num <= 255 )
|
||||
return 0;
|
||||
else if( num <= 65535 )
|
||||
return 1;
|
||||
else if( num <= 4294967295L )
|
||||
return 2;
|
||||
else
|
||||
return 3;
|
||||
}
|
||||
|
||||
abstract boolean hasTagCompound();
|
||||
|
||||
abstract void writeIdentity( ByteBuf i ) throws IOException;
|
||||
|
||||
abstract void readNBT( ByteBuf i ) throws IOException;
|
||||
|
||||
void putPacketValue( ByteBuf tag, 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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
@@ -28,10 +27,10 @@ import java.util.List;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
@@ -46,84 +45,157 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
||||
private final Class<? extends IAEStack> clz;
|
||||
|
||||
// private int currentPriority = Integer.MIN_VALUE;
|
||||
|
||||
int iteration = Integer.MIN_VALUE;
|
||||
public Throwable stacktrace;
|
||||
int iteration = Integer.MIN_VALUE;
|
||||
|
||||
public ItemList( Class<? extends IAEStack> cla )
|
||||
{
|
||||
this.clz = cla;
|
||||
}
|
||||
|
||||
private boolean checkStackType( StackType st )
|
||||
{
|
||||
if ( st == null )
|
||||
return true;
|
||||
|
||||
if ( !this.clz.isInstance( st ) )
|
||||
throw new RuntimeException( "WRONG TYPE - got " + st.getClass().getName() + " expected " + this.clz.getName() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void add( StackType option )
|
||||
{
|
||||
if ( this.checkStackType( option ) )
|
||||
if( this.checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = this.records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
if( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
st.add( option );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
this.records.put( opt, opt );
|
||||
}
|
||||
|
||||
private boolean checkStackType( StackType st )
|
||||
{
|
||||
if( st == null )
|
||||
return true;
|
||||
|
||||
if( !this.clz.isInstance( st ) )
|
||||
throw new RuntimeException( "WRONG TYPE - got " + st.getClass().getName() + " expected " + this.clz.getName() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public StackType findPrecise( StackType i )
|
||||
{
|
||||
if( this.checkStackType( i ) )
|
||||
return null;
|
||||
|
||||
StackType is = this.records.get( i );
|
||||
if( is != null )
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StackType> findFuzzy( StackType filter, FuzzyMode fuzzy )
|
||||
{
|
||||
if( this.checkStackType( filter ) )
|
||||
return new ArrayList<StackType>();
|
||||
|
||||
if( filter instanceof IAEFluidStack )
|
||||
{
|
||||
List<StackType> result = Lists.newArrayList();
|
||||
|
||||
if( filter.equals( this ) )
|
||||
{
|
||||
result.add( filter );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
AEItemStack ais = (AEItemStack) filter;
|
||||
if( ais.isOre() )
|
||||
{
|
||||
OreReference or = ais.def.isOre;
|
||||
if( or.getAEEquivalents().size() == 1 )
|
||||
{
|
||||
IAEItemStack is = or.getAEEquivalents().get( 0 );
|
||||
return this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<StackType> output = new LinkedList<StackType>();
|
||||
|
||||
for( IAEItemStack is : or.getAEEquivalents() )
|
||||
output.addAll( this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return this.findFuzzyDamage( ais, fuzzy, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
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 this.records.subMap( low, true, high, true ).descendingMap().values();
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void addStorage( StackType option ) // adds a stack as
|
||||
// stored.
|
||||
// stored.
|
||||
{
|
||||
if ( this.checkStackType( option ) )
|
||||
if( this.checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = this.records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
if( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
st.incStackSize( option.getStackSize() );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
this.records.put( opt, opt );
|
||||
}
|
||||
|
||||
/*
|
||||
* synchronized public void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
|
||||
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
|
||||
*/
|
||||
|
||||
@Override
|
||||
synchronized public void addCrafting( StackType option ) // adds a stack as
|
||||
// craftable.
|
||||
// craftable.
|
||||
{
|
||||
if ( this.checkStackType( option ) )
|
||||
if( this.checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = this.records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
if( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
st.setCraftable( true );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( true );
|
||||
@@ -133,22 +205,22 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
||||
|
||||
@Override
|
||||
synchronized public void addRequestable( StackType option ) // adds a stack
|
||||
// as
|
||||
// requestable.
|
||||
// as
|
||||
// requestable.
|
||||
{
|
||||
if ( this.checkStackType( option ) )
|
||||
if( this.checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = this.records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
if( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
( ( IAEItemStack ) st ).setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
|
||||
( (IAEItemStack) st ).setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( false );
|
||||
@@ -160,46 +232,13 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
||||
@Override
|
||||
synchronized public StackType getFirstItem()
|
||||
{
|
||||
for ( StackType stackType : this )
|
||||
for( StackType stackType : this )
|
||||
{
|
||||
return stackType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void resetStatus()
|
||||
{
|
||||
for ( StackType i : this )
|
||||
i.reset();
|
||||
}
|
||||
|
||||
/*
|
||||
* synchronized public void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
|
||||
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
|
||||
*/
|
||||
|
||||
@Override
|
||||
synchronized public Iterator<StackType> iterator()
|
||||
{
|
||||
return new MeaningfulIterator<StackType>( this.records.values().iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public StackType findPrecise( StackType i )
|
||||
{
|
||||
if ( this.checkStackType( i ) )
|
||||
return null;
|
||||
|
||||
StackType is = this.records.get( i );
|
||||
if ( is != null )
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public int size()
|
||||
{
|
||||
@@ -207,56 +246,15 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
synchronized public Iterator<StackType> iterator()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
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 this.records.subMap( low, true, high, true ).descendingMap().values();
|
||||
return new MeaningfulIterator<StackType>( this.records.values().iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StackType> findFuzzy( StackType filter, FuzzyMode fuzzy )
|
||||
synchronized public void resetStatus()
|
||||
{
|
||||
if ( this.checkStackType( filter ) )
|
||||
return new ArrayList<StackType>();
|
||||
|
||||
if ( filter instanceof IAEFluidStack )
|
||||
{
|
||||
List<StackType> result = Lists.newArrayList();
|
||||
|
||||
if ( filter.equals( this ) )
|
||||
{
|
||||
result.add( filter );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
AEItemStack ais = ( AEItemStack ) filter;
|
||||
if ( ais.isOre() )
|
||||
{
|
||||
OreReference or = ais.def.isOre;
|
||||
if ( or.getAEEquivalents().size() == 1 )
|
||||
{
|
||||
IAEItemStack is = or.getAEEquivalents().get( 0 );
|
||||
return this.findFuzzyDamage( ( AEItemStack ) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<StackType> output = new LinkedList<StackType>();
|
||||
|
||||
for ( IAEItemStack is : or.getAEEquivalents() )
|
||||
output.addAll( this.findFuzzyDamage( ( AEItemStack ) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return this.findFuzzyDamage( ais, fuzzy, false );
|
||||
for( StackType i : this )
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -25,24 +26,26 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemContainer;
|
||||
|
||||
|
||||
public class ItemModList implements IItemContainer<IAEItemStack>
|
||||
{
|
||||
|
||||
final IItemContainer<IAEItemStack> backingStore;
|
||||
final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().createItemList();
|
||||
|
||||
public ItemModList(IItemContainer<IAEItemStack> backend) {
|
||||
public ItemModList( IItemContainer<IAEItemStack> backend )
|
||||
{
|
||||
this.backingStore = backend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(IAEItemStack option)
|
||||
public void add( IAEItemStack option )
|
||||
{
|
||||
IAEItemStack over = this.overrides.findPrecise( option );
|
||||
if ( over == null )
|
||||
if( over == null )
|
||||
{
|
||||
over = this.backingStore.findPrecise( option );
|
||||
if ( over == null )
|
||||
if( over == null )
|
||||
this.overrides.add( option );
|
||||
else
|
||||
{
|
||||
@@ -55,16 +58,16 @@ public class ItemModList implements IItemContainer<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise(IAEItemStack i)
|
||||
public IAEItemStack findPrecise( IAEItemStack i )
|
||||
{
|
||||
IAEItemStack over = this.overrides.findPrecise( i );
|
||||
if ( over == null )
|
||||
if( over == null )
|
||||
return this.backingStore.findPrecise( i );
|
||||
return over;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(IAEItemStack input, FuzzyMode fuzzy)
|
||||
public Collection<IAEItemStack> findFuzzy( IAEItemStack input, FuzzyMode fuzzy )
|
||||
{
|
||||
return this.overrides.findFuzzy( input, fuzzy );
|
||||
}
|
||||
@@ -74,5 +77,4 @@ public class ItemModList implements IItemContainer<IAEItemStack>
|
||||
{
|
||||
return this.overrides.isEmpty() && this.backingStore.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,17 +18,19 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
|
||||
public class MeaningfulIterator<StackType extends IAEStack> implements Iterator<StackType>
|
||||
{
|
||||
|
||||
private final Iterator<StackType> parent;
|
||||
private StackType next;
|
||||
|
||||
public MeaningfulIterator(Iterator<StackType> iterator)
|
||||
public MeaningfulIterator( Iterator<StackType> iterator )
|
||||
{
|
||||
this.parent = iterator;
|
||||
}
|
||||
@@ -36,10 +38,10 @@ public class MeaningfulIterator<StackType extends IAEStack> implements Iterator<
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
while (this.parent.hasNext())
|
||||
while( this.parent.hasNext() )
|
||||
{
|
||||
this.next = this.parent.next();
|
||||
if ( this.next.isMeaningful() )
|
||||
if( this.next.isMeaningful() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -63,5 +65,4 @@ public class MeaningfulIterator<StackType extends IAEStack> implements Iterator<
|
||||
{
|
||||
this.parent.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,14 +45,14 @@ public class OreHelper
|
||||
/**
|
||||
* A local cache to speed up OreDictionary lookups.
|
||||
*/
|
||||
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder
|
||||
.newBuilder().build( new CacheLoader<String, List<ItemStack>>(){
|
||||
@Override
|
||||
public List<ItemStack> load( String oreName )
|
||||
{
|
||||
return OreDictionary.getOres( oreName );
|
||||
}
|
||||
} );
|
||||
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder.newBuilder().build( new CacheLoader<String, List<ItemStack>>()
|
||||
{
|
||||
@Override
|
||||
public List<ItemStack> load( String oreName )
|
||||
{
|
||||
return OreDictionary.getOres( oreName );
|
||||
}
|
||||
} );
|
||||
|
||||
private final Map<ItemRef, OreReference> references = new HashMap<ItemRef, OreReference>();
|
||||
|
||||
@@ -60,13 +60,14 @@ public class OreHelper
|
||||
* Test if the passed {@link ItemStack} is an ore.
|
||||
*
|
||||
* @param ItemStack the itemstack to test
|
||||
*
|
||||
* @return true if an ore entry exists, false otherwise
|
||||
*/
|
||||
public OreReference isOre( ItemStack ItemStack )
|
||||
{
|
||||
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();
|
||||
@@ -74,17 +75,17 @@ public class OreHelper
|
||||
|
||||
Set<String> toAdd = new HashSet<String>();
|
||||
|
||||
for ( String ore : OreDictionary.getOreNames() )
|
||||
for( 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 ( ItemStack oreItem : this.oreDictCache.getUnchecked( ore ) )
|
||||
for( ItemStack oreItem : this.oreDictCache.getUnchecked( ore ) )
|
||||
{
|
||||
if ( OreDictionary.itemMatches( oreItem, ItemStack, false ) )
|
||||
if( OreDictionary.itemMatches( oreItem, ItemStack, false ) )
|
||||
{
|
||||
toAdd.add( ore );
|
||||
break;
|
||||
@@ -92,13 +93,13 @@ public class OreHelper
|
||||
}
|
||||
}
|
||||
|
||||
for ( String ore : toAdd )
|
||||
for( String ore : toAdd )
|
||||
{
|
||||
set.add( ore );
|
||||
ores.add( OreDictionary.getOreID( ore ) );
|
||||
}
|
||||
|
||||
if ( !set.isEmpty() )
|
||||
if( !set.isEmpty() )
|
||||
this.references.put( ir, ref );
|
||||
else
|
||||
this.references.put( ir, null );
|
||||
@@ -117,16 +118,16 @@ public class OreHelper
|
||||
|
||||
public boolean sameOre( OreReference a, OreReference b )
|
||||
{
|
||||
if ( a == null || b == null )
|
||||
if( a == null || b == null )
|
||||
return false;
|
||||
|
||||
if ( a == b )
|
||||
if( a == b )
|
||||
return true;
|
||||
|
||||
Collection<Integer> bOres = b.getOres();
|
||||
for ( Integer ore : a.getOres() )
|
||||
for( Integer ore : a.getOres() )
|
||||
{
|
||||
if ( bOres.contains( ore ) )
|
||||
if( bOres.contains( ore ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -136,14 +137,14 @@ public class OreHelper
|
||||
public boolean sameOre( AEItemStack aeItemStack, ItemStack o )
|
||||
{
|
||||
OreReference a = aeItemStack.def.isOre;
|
||||
if ( a == null )
|
||||
if( a == null )
|
||||
return false;
|
||||
|
||||
for ( String oreName : a.getEquivalents() )
|
||||
for( String oreName : a.getEquivalents() )
|
||||
{
|
||||
for ( ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) )
|
||||
for( ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) )
|
||||
{
|
||||
if ( OreDictionary.itemMatches( oreItem, o, false ) )
|
||||
if( OreDictionary.itemMatches( oreItem, o, false ) )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -159,11 +160,15 @@ public class OreHelper
|
||||
private static class ItemRef
|
||||
{
|
||||
|
||||
private final Item ref;
|
||||
private final int damage;
|
||||
private final int hash;
|
||||
|
||||
ItemRef( ItemStack stack )
|
||||
{
|
||||
this.ref = stack.getItem();
|
||||
|
||||
if ( stack.getItem().isDamageable() )
|
||||
if( stack.getItem().isDamageable() )
|
||||
this.damage = 0; // IGNORED
|
||||
else
|
||||
this.damage = stack.getItemDamage(); // might be important...
|
||||
@@ -171,32 +176,27 @@ public class OreHelper
|
||||
this.hash = this.ref.hashCode() ^ this.damage;
|
||||
}
|
||||
|
||||
private final Item ref;
|
||||
private final int damage;
|
||||
private final int hash;
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( obj == null )
|
||||
return false;
|
||||
if ( this.getClass() != obj.getClass() )
|
||||
return false;
|
||||
ItemRef other = ( ItemRef ) obj;
|
||||
return this.damage == other.damage && this.ref == other.ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if( obj == null )
|
||||
return false;
|
||||
if( this.getClass() != obj.getClass() )
|
||||
return false;
|
||||
ItemRef other = (ItemRef) obj;
|
||||
return this.damage == other.damage && this.ref == other.ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "ItemRef [ref=" + this.ref.getUnlocalizedName() + ", damage=" + this.damage + ", hash=" + this.hash + ']';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,8 @@ public class OreReference
|
||||
{
|
||||
|
||||
private final List<String> otherOptions = new LinkedList<String>();
|
||||
private List<IAEItemStack> aeOtherOptions = null;
|
||||
private final Set<Integer> ores = new HashSet<Integer>();
|
||||
private List<IAEItemStack> aeOtherOptions = null;
|
||||
|
||||
public Collection<String> getEquivalents()
|
||||
{
|
||||
@@ -45,20 +45,19 @@ public class OreReference
|
||||
|
||||
public List<IAEItemStack> getAEEquivalents()
|
||||
{
|
||||
if ( this.aeOtherOptions == null )
|
||||
if( this.aeOtherOptions == null )
|
||||
{
|
||||
this.aeOtherOptions = new ArrayList<IAEItemStack>( this.otherOptions.size() );
|
||||
|
||||
// SUMMON AE STACKS!
|
||||
for ( String oreName : this.otherOptions )
|
||||
for( String oreName : this.otherOptions )
|
||||
{
|
||||
for ( ItemStack is : OreHelper.INSTANCE.getCachedOres( oreName ) )
|
||||
for( ItemStack is : OreHelper.INSTANCE.getCachedOres( oreName ) )
|
||||
{
|
||||
if ( is.getItem() != null )
|
||||
if( is.getItem() != null )
|
||||
{
|
||||
this.aeOtherOptions.add( AEItemStack.create( is ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,5 +69,4 @@ public class OreReference
|
||||
{
|
||||
return this.ores;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,44 +18,46 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class SharedSearchObject
|
||||
{
|
||||
|
||||
final int def;
|
||||
final int hash;
|
||||
NBTTagCompound compound;
|
||||
public AESharedNBT shared;
|
||||
NBTTagCompound compound;
|
||||
|
||||
public SharedSearchObject(Item itemID, int damageValue, NBTTagCompound tagCompound) {
|
||||
this.def = (damageValue << Platform.DEF_OFFSET) | Item.itemRegistry.getIDForObject( itemID );
|
||||
public SharedSearchObject( Item itemID, int damageValue, NBTTagCompound tagCompound )
|
||||
{
|
||||
this.def = ( damageValue << Platform.DEF_OFFSET ) | Item.itemRegistry.getIDForObject( itemID );
|
||||
this.hash = Platform.NBTOrderlessHash( tagCompound );
|
||||
this.compound = tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if ( obj == null )
|
||||
return false;
|
||||
if ( this.getClass() != obj.getClass() )
|
||||
return false;
|
||||
SharedSearchObject other = (SharedSearchObject) obj;
|
||||
if ( this.def == other.def && this.hash == other.hash )
|
||||
{
|
||||
return Platform.NBTEqualityTest( this.compound, other.compound );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.def ^ this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if( obj == null )
|
||||
return false;
|
||||
if( this.getClass() != obj.getClass() )
|
||||
return false;
|
||||
SharedSearchObject other = (SharedSearchObject) obj;
|
||||
if( this.def == other.def && this.hash == other.hash )
|
||||
{
|
||||
return Platform.NBTEqualityTest( this.compound, other.compound );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,13 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
|
||||
|
||||
public class AEInvIterator implements Iterator<IAEItemStack>
|
||||
{
|
||||
|
||||
@@ -31,7 +33,8 @@ public class AEInvIterator implements Iterator<IAEItemStack>
|
||||
|
||||
int x = 0;
|
||||
|
||||
public AEInvIterator(AppEngInternalAEInventory i) {
|
||||
public AEInvIterator( AppEngInternalAEInventory i )
|
||||
{
|
||||
this.inv = i;
|
||||
this.size = this.inv.getSizeInventory();
|
||||
}
|
||||
@@ -55,5 +58,4 @@ public class AEInvIterator implements Iterator<IAEItemStack>
|
||||
{
|
||||
throw new RuntimeException( "no..." );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,15 +18,18 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class ChainedIterator<T> implements Iterator<T>
|
||||
{
|
||||
|
||||
int offset = 0;
|
||||
final T[] list;
|
||||
int offset = 0;
|
||||
|
||||
public ChainedIterator(T... list) {
|
||||
public ChainedIterator( T... list )
|
||||
{
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@@ -49,5 +52,4 @@ public class ChainedIterator<T> implements Iterator<T>
|
||||
{
|
||||
throw new RuntimeException( "Not implemented." );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,13 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class InvIterator implements Iterator<ItemStack>
|
||||
{
|
||||
|
||||
@@ -31,7 +33,8 @@ public class InvIterator implements Iterator<ItemStack>
|
||||
|
||||
int x = 0;
|
||||
|
||||
public InvIterator(IInventory i) {
|
||||
public InvIterator( IInventory i )
|
||||
{
|
||||
this.inv = i;
|
||||
this.size = this.inv.getSizeInventory();
|
||||
}
|
||||
@@ -55,5 +58,4 @@ public class InvIterator implements Iterator<ItemStack>
|
||||
{
|
||||
throw new RuntimeException( "no..." );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class NullIterator<T> implements Iterator<T>
|
||||
{
|
||||
|
||||
@@ -40,5 +42,4 @@ public class NullIterator<T> implements Iterator<T>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -25,12 +26,14 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
|
||||
|
||||
public class ProxyNodeIterator implements Iterator<IGridNode>
|
||||
{
|
||||
|
||||
final Iterator<IGridHost> hosts;
|
||||
|
||||
public ProxyNodeIterator(Iterator<IGridHost> hosts) {
|
||||
public ProxyNodeIterator( Iterator<IGridHost> hosts )
|
||||
{
|
||||
this.hosts = hosts;
|
||||
}
|
||||
|
||||
@@ -52,5 +55,4 @@ public class ProxyNodeIterator implements Iterator<IGridNode>
|
||||
{
|
||||
throw new RuntimeException( "Not implemented." );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,20 +18,23 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
|
||||
|
||||
public class StackToSlotIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
|
||||
int x = 0;
|
||||
final ItemSlot iss = new ItemSlot();
|
||||
final Iterator<ItemStack> is;
|
||||
int x = 0;
|
||||
|
||||
public StackToSlotIterator(Iterator<ItemStack> is) {
|
||||
public StackToSlotIterator( Iterator<ItemStack> is )
|
||||
{
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
@@ -55,5 +58,4 @@ public class StackToSlotIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
// uhh no.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,18 +18,20 @@
|
||||
|
||||
package appeng.util.prioitylist;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
|
||||
public class DefaultPriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
|
||||
final static List NULL_LIST = new ArrayList();
|
||||
|
||||
@Override
|
||||
public boolean isListed(T input)
|
||||
public boolean isListed( T input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -45,5 +47,4 @@ public class DefaultPriorityList<T extends IAEStack<T>> implements IPartitionLis
|
||||
{
|
||||
return NULL_LIST;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,25 +18,28 @@
|
||||
|
||||
package appeng.util.prioitylist;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class FuzzyPriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
|
||||
final IItemList<T> list;
|
||||
final FuzzyMode mode;
|
||||
|
||||
public FuzzyPriorityList(IItemList<T> in, FuzzyMode mode) {
|
||||
public FuzzyPriorityList( IItemList<T> in, FuzzyMode mode )
|
||||
{
|
||||
this.list = in;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListed(T input)
|
||||
public boolean isListed( T input )
|
||||
{
|
||||
Collection<T> out = this.list.findFuzzy( input, this.mode );
|
||||
return out != null && !out.isEmpty();
|
||||
@@ -53,5 +56,4 @@ public class FuzzyPriorityList<T extends IAEStack<T>> implements IPartitionList<
|
||||
{
|
||||
return this.list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,15 +18,16 @@
|
||||
|
||||
package appeng.util.prioitylist;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
|
||||
public interface IPartitionList<T extends IAEStack<T>>
|
||||
{
|
||||
|
||||
boolean isListed(T input);
|
||||
boolean isListed( T input );
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
Iterable<T> getItems();
|
||||
|
||||
}
|
||||
|
||||
@@ -18,36 +18,38 @@
|
||||
|
||||
package appeng.util.prioitylist;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
|
||||
public class MergedPriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
|
||||
final List<IPartitionList<T>> positive = new ArrayList<IPartitionList<T>>();
|
||||
final List<IPartitionList<T>> negative = new ArrayList<IPartitionList<T>>();
|
||||
|
||||
public void addNewList(IPartitionList<T> list, boolean isWhitelist)
|
||||
public void addNewList( IPartitionList<T> list, boolean isWhitelist )
|
||||
{
|
||||
if ( isWhitelist )
|
||||
if( isWhitelist )
|
||||
this.positive.add( list );
|
||||
else
|
||||
this.negative.add( list );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListed(T input)
|
||||
public boolean isListed( T input )
|
||||
{
|
||||
for (IPartitionList<T> l : this.negative)
|
||||
if ( l.isListed( input ) )
|
||||
for( IPartitionList<T> l : this.negative )
|
||||
if( l.isListed( input ) )
|
||||
return false;
|
||||
|
||||
if ( !this.positive.isEmpty() )
|
||||
if( !this.positive.isEmpty() )
|
||||
{
|
||||
for (IPartitionList<T> l : this.positive)
|
||||
if ( l.isListed( input ) )
|
||||
for( IPartitionList<T> l : this.positive )
|
||||
if( l.isListed( input ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -67,5 +69,4 @@ public class MergedPriorityList<T extends IAEStack<T>> implements IPartitionList
|
||||
{
|
||||
throw new RuntimeException( "Not Implemented" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,20 +18,23 @@
|
||||
|
||||
package appeng.util.prioitylist;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class PrecisePriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
|
||||
final IItemList<T> list;
|
||||
|
||||
public PrecisePriorityList(IItemList<T> in) {
|
||||
public PrecisePriorityList( IItemList<T> in )
|
||||
{
|
||||
this.list = in;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListed(T input)
|
||||
public boolean isListed( T input )
|
||||
{
|
||||
return this.list.findPrecise( input ) != null;
|
||||
}
|
||||
@@ -47,5 +50,4 @@ public class PrecisePriorityList<T extends IAEStack<T>> implements IPartitionLis
|
||||
{
|
||||
return this.list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user