Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package appeng.util;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockUpdate implements Callable
|
||||
{
|
||||
|
||||
final World w;
|
||||
final int x, y, z;
|
||||
|
||||
public BlockUpdate(World w, int x, int y, int z) {
|
||||
this.w = w;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call() throws Exception
|
||||
{
|
||||
if ( w.blockExists( x, y, z ) )
|
||||
w.notifyBlocksOfNeighborChange( x, y, z, Platform.air );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package appeng.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.core.AELog;
|
||||
|
||||
public class ConfigManager implements IConfigManager
|
||||
{
|
||||
|
||||
HashMap<Enum, Enum> Settings = new HashMap();
|
||||
IConfigManagerHost target;
|
||||
|
||||
public ConfigManager(IConfigManagerHost tile) {
|
||||
target = tile;
|
||||
}
|
||||
|
||||
/**
|
||||
* read all settings using config manager.
|
||||
*
|
||||
* @param tagCompound
|
||||
*/
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound)
|
||||
{
|
||||
for (Enum key : Settings.keySet())
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( tagCompound.hasKey( key.name() ) )
|
||||
{
|
||||
String value = tagCompound.getString( key.name() );
|
||||
|
||||
Enum oldValue = Settings.get( key );
|
||||
Enum newValue = Enum.valueOf( oldValue.getClass(), value );
|
||||
|
||||
putSetting( key, newValue );
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* save all settings using config manager.
|
||||
*
|
||||
* @param tagCompound
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tagCompound)
|
||||
{
|
||||
|
||||
for (Enum e : Settings.keySet())
|
||||
{
|
||||
tagCompound.setString( e.name(), Settings.get( e ).toString() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Enum> getSettings()
|
||||
{
|
||||
return Settings.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSetting(Enum settingName, Enum defaultValue)
|
||||
{
|
||||
Settings.put( settingName, defaultValue );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getSetting(Enum settingName)
|
||||
{
|
||||
Enum oldValue = Settings.get( settingName );
|
||||
|
||||
if ( oldValue != null )
|
||||
return oldValue;
|
||||
|
||||
throw new RuntimeException( "Invalid Config setting" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum putSetting(Enum settingName, Enum newValue)
|
||||
{
|
||||
Enum oldValue = getSetting( settingName );
|
||||
Settings.put( settingName, newValue );
|
||||
target.updateSetting( this, settingName, newValue );
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appeng.util;
|
||||
|
||||
import appeng.api.util.IConfigManager;
|
||||
|
||||
public interface IConfigManagerHost
|
||||
{
|
||||
|
||||
void updateSetting(IConfigManager manager, Enum settingName, Enum newValue);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package appeng.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAir;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InWorldToolOperationResult
|
||||
{
|
||||
|
||||
public ItemStack BlockItem;
|
||||
public List<ItemStack> Drops;
|
||||
|
||||
public static InWorldToolOperationResult getBlockOperationResult(ItemStack[] items)
|
||||
{
|
||||
List<ItemStack> temp = new ArrayList<ItemStack>();
|
||||
ItemStack b = null;
|
||||
|
||||
for (ItemStack l : items)
|
||||
{
|
||||
if ( b == null )
|
||||
{
|
||||
Block bl = Block.getBlockFromItem( l.getItem() );
|
||||
|
||||
if ( bl != null && !(bl instanceof BlockAir) )
|
||||
{
|
||||
b = l;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
temp.add( l );
|
||||
}
|
||||
|
||||
return new InWorldToolOperationResult( b, temp );
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult() {
|
||||
BlockItem = null;
|
||||
Drops = null;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult(ItemStack block, List<ItemStack> drops) {
|
||||
BlockItem = block;
|
||||
Drops = drops;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult(ItemStack block) {
|
||||
BlockItem = block;
|
||||
Drops = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package appeng.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBetterStorage;
|
||||
import appeng.util.inv.AdaptorIInventory;
|
||||
import appeng.util.inv.AdaptorISpecialInventory;
|
||||
import appeng.util.inv.AdaptorList;
|
||||
import appeng.util.inv.AdaptorPlayerInventory;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import appeng.util.inv.WrapperMCISidedInventory;
|
||||
import buildcraft.api.inventory.ISpecialInventory;
|
||||
|
||||
public abstract class InventoryAdaptor implements Iterable<ItemSlot>
|
||||
{
|
||||
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeItems(int how_many, ItemStack Filter, IInventoryDestination destination);
|
||||
|
||||
public abstract ItemStack simulateRemove(int how_many, 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 how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination);
|
||||
|
||||
// return what isn't used...
|
||||
public abstract ItemStack addItems(ItemStack A);
|
||||
|
||||
public abstract ItemStack simulateAdd(ItemStack A);
|
||||
|
||||
public abstract boolean containsItems();
|
||||
|
||||
// returns an appropriate adaptor, or null
|
||||
public static InventoryAdaptor getAdaptor(Object te, ForgeDirection d)
|
||||
{
|
||||
if ( te == null )
|
||||
return null;
|
||||
|
||||
IBetterStorage bs = (IBetterStorage) (AppEng.instance.isIntegrationEnabled( IntegrationType.BetterStorage ) ? AppEng.instance.getIntegration( IntegrationType.BetterStorage ) : null);
|
||||
|
||||
if ( te instanceof EntityPlayer )
|
||||
{
|
||||
return new AdaptorIInventory( new AdaptorPlayerInventory( ((EntityPlayer) te).inventory, false ) );
|
||||
}
|
||||
else if ( te instanceof ArrayList )
|
||||
{
|
||||
return new AdaptorList( (ArrayList) te );
|
||||
}
|
||||
else if ( bs != null && bs.isStorageCrate( te ) )
|
||||
{
|
||||
return bs.getAdaptor( te, d );
|
||||
}
|
||||
else if ( te instanceof TileEntityChest )
|
||||
{
|
||||
return new AdaptorIInventory( (IInventory) Platform.GetChestInv( te ) );
|
||||
}
|
||||
else if ( isSpecialInventory( te ) )
|
||||
{
|
||||
return new AdaptorISpecialInventory( (ISpecialInventory) te, d );
|
||||
}
|
||||
else if ( te instanceof ISidedInventory )
|
||||
{
|
||||
ISidedInventory si =(ISidedInventory)te;
|
||||
int[] slots = si.getAccessibleSlotsFromSide( d.ordinal() );
|
||||
if ( si.getSizeInventory() > 0 && slots != null && slots.length > 0 )
|
||||
return new AdaptorIInventory( new WrapperMCISidedInventory( si, d ) );
|
||||
}
|
||||
else if ( te instanceof IInventory )
|
||||
{
|
||||
IInventory i =(IInventory)te;
|
||||
if ( i.getSizeInventory() > 0 )
|
||||
return new AdaptorIInventory( i );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean canBeSpecial = true;
|
||||
|
||||
private static boolean isSpecialInventory(Object a)
|
||||
{
|
||||
if ( canBeSpecial )
|
||||
{
|
||||
try
|
||||
{
|
||||
return a instanceof ISpecialInventory;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
canBeSpecial = false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package appeng.util;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AppEng;
|
||||
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()
|
||||
{
|
||||
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 Comparator<IAEItemStack> ConfigBased_SortByName = new Comparator<IAEItemStack>() {
|
||||
|
||||
@Override
|
||||
public int compare(IAEItemStack o1, IAEItemStack o2)
|
||||
{
|
||||
if ( Direction == SortDir.ASCENDING )
|
||||
return Platform.getItemDisplayName( o1 ).compareToIgnoreCase( Platform.getItemDisplayName( o2 ) );
|
||||
return Platform.getItemDisplayName( o2 ).compareToIgnoreCase( Platform.getItemDisplayName( o1 ) );
|
||||
}
|
||||
};
|
||||
|
||||
public static Comparator<IAEItemStack> ConfigBased_SortByMod = new Comparator<IAEItemStack>() {
|
||||
|
||||
@Override
|
||||
public int compare(IAEItemStack o1, IAEItemStack o2)
|
||||
{
|
||||
AEItemStack op1 = (AEItemStack) o1;
|
||||
AEItemStack op2 = (AEItemStack) o2;
|
||||
|
||||
if ( Direction == SortDir.ASCENDING )
|
||||
return secondarySort( op2.getModID().compareToIgnoreCase( op1.getModID() ), o1, o2 );
|
||||
return secondarySort( op1.getModID().compareToIgnoreCase( op2.getModID() ), o2, o1 );
|
||||
}
|
||||
|
||||
private int secondarySort(int compareToIgnoreCase, IAEItemStack o1, IAEItemStack o2)
|
||||
{
|
||||
if ( compareToIgnoreCase == 0 )
|
||||
return Platform.getItemDisplayName( o2 ).compareToIgnoreCase( Platform.getItemDisplayName( o1 ) );
|
||||
|
||||
return compareToIgnoreCase;
|
||||
}
|
||||
};
|
||||
|
||||
public static Comparator<IAEItemStack> ConfigBased_SortBySize = new Comparator<IAEItemStack>() {
|
||||
|
||||
@Override
|
||||
public int compare(IAEItemStack o1, IAEItemStack o2)
|
||||
{
|
||||
if ( Direction == SortDir.ASCENDING )
|
||||
return compareLong( o2.getStackSize(), o1.getStackSize() );
|
||||
return compareLong( o1.getStackSize(), o2.getStackSize() );
|
||||
}
|
||||
};
|
||||
|
||||
public static Comparator<IAEItemStack> ConfigBased_SortByInvTweaks = new Comparator<IAEItemStack>() {
|
||||
|
||||
@Override
|
||||
public int compare(IAEItemStack o1, IAEItemStack o2)
|
||||
{
|
||||
if ( api == null )
|
||||
return ConfigBased_SortByName.compare( o1, o2 );
|
||||
|
||||
int cmp = api.compareItems( o1.getItemStack(), o2.getItemStack() );
|
||||
|
||||
if ( Direction == SortDir.ASCENDING )
|
||||
return cmp;
|
||||
return -cmp;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,41 @@
|
||||
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) {
|
||||
c = in;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterator()
|
||||
{
|
||||
return c.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return c.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return c.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object node)
|
||||
{
|
||||
return c.contains( node );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appeng.util;
|
||||
|
||||
public enum SettingsFrom
|
||||
{
|
||||
// moved the item, and replaced it.
|
||||
DISMANTLE_ITEM,
|
||||
|
||||
// used memory card?
|
||||
MEMORY_CARD
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
package appeng.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class SortedList<T> implements Iterable<T>, List<T>, Cloneable {
|
||||
|
||||
private boolean sorted = true;
|
||||
private final Comparator<T> comp;
|
||||
private final LinkedList<T> storage = new LinkedList<T>();
|
||||
|
||||
private void makeSorted() {
|
||||
if (!sorted) {
|
||||
sorted = true;
|
||||
Collections.sort(storage, comp);
|
||||
}
|
||||
}
|
||||
|
||||
public SortedList(Comparator<T> comp) {
|
||||
this.comp = comp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(T input) {
|
||||
sorted = false;
|
||||
return storage.add(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends T> input) {
|
||||
if (!input.isEmpty())
|
||||
sorted = false;
|
||||
return storage.addAll(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
sorted = true;
|
||||
storage.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object input) {
|
||||
return storage.contains(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> input) {
|
||||
return storage.containsAll(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
makeSorted();
|
||||
return storage.iterator();
|
||||
}
|
||||
|
||||
public Iterator<T> reverseIterator() {
|
||||
makeSorted();
|
||||
final ListIterator<T> listIterator = listIterator(size());
|
||||
|
||||
return new Iterator<T>() {
|
||||
|
||||
public boolean hasNext() {
|
||||
return listIterator.hasPrevious();
|
||||
}
|
||||
|
||||
public T next() {
|
||||
return listIterator.previous();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
listIterator.remove();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object input) {
|
||||
return storage.remove(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> input) {
|
||||
return storage.removeAll(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> input) {
|
||||
return storage.retainAll(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return storage.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return storage.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> X[] toArray(X[] input) {
|
||||
return storage.toArray(input);
|
||||
}
|
||||
|
||||
public Comparator<? super T> comparator() {
|
||||
return comp;
|
||||
}
|
||||
|
||||
public T first() {
|
||||
makeSorted();
|
||||
return storage.peekFirst();
|
||||
}
|
||||
|
||||
public T last() {
|
||||
makeSorted();
|
||||
return storage.peekLast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, T element) {
|
||||
makeSorted();
|
||||
sorted = false;
|
||||
add(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends T> c) {
|
||||
sorted = false;
|
||||
return addAll(index, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int index) {
|
||||
makeSorted();
|
||||
return get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
makeSorted();
|
||||
return indexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
makeSorted();
|
||||
return lastIndexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<T> listIterator() {
|
||||
makeSorted();
|
||||
return listIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<T> listIterator(int index) {
|
||||
makeSorted();
|
||||
return listIterator(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int index) {
|
||||
makeSorted();
|
||||
return remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T set(int index, T element) {
|
||||
makeSorted();
|
||||
sorted = false;
|
||||
return set(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> subList(int fromIndex, int toIndex) {
|
||||
makeSorted();
|
||||
return storage.subList(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.iterators.NullIterator;
|
||||
|
||||
public class AdaptorBCPipe extends InventoryAdaptor
|
||||
{
|
||||
|
||||
final private IBC bc;
|
||||
final private TileEntity i;
|
||||
final private ForgeDirection d;
|
||||
|
||||
public AdaptorBCPipe(TileEntity s, ForgeDirection dd) {
|
||||
bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
||||
if ( bc != null )
|
||||
{
|
||||
if ( bc.isPipe( s, dd ) )
|
||||
{
|
||||
i = s;
|
||||
d = dd;
|
||||
return;
|
||||
}
|
||||
}
|
||||
i = null;
|
||||
d = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
if ( i == null )
|
||||
return A;
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
if ( bc.addItemsToPipe( i, A, d ) )
|
||||
return null;
|
||||
return A;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
if ( i == null )
|
||||
return A;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new NullIterator();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class AdaptorIInventory extends InventoryAdaptor
|
||||
{
|
||||
|
||||
private IInventory i;
|
||||
private boolean wrapperEnabled;
|
||||
|
||||
public AdaptorIInventory(IInventory s) {
|
||||
i = s;
|
||||
wrapperEnabled = s instanceof IInventoryWrapper;
|
||||
}
|
||||
|
||||
boolean canRemoveStackFromSlot(int x, ItemStack is)
|
||||
{
|
||||
if ( wrapperEnabled )
|
||||
return ((IInventoryWrapper) i).canRemoveItemFromSlot( x, is );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
if ( i.getStackInSlot( x ) != null )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is != null && canRemoveStackFromSlot( x, is ) && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
{
|
||||
int lhow_many = how_many;
|
||||
if ( lhow_many > is.stackSize )
|
||||
lhow_many = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
lhow_many = 0;
|
||||
|
||||
ItemStack rv = null;
|
||||
if ( lhow_many > 0 )
|
||||
{
|
||||
rv = is.copy();
|
||||
rv.stackSize = lhow_many;
|
||||
|
||||
if ( is.stackSize == rv.stackSize )
|
||||
{
|
||||
i.setInventorySlotContents( x, null );
|
||||
i.markDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack po = is.copy();
|
||||
po.stackSize -= rv.stackSize;
|
||||
i.setInventorySlotContents( x, po );
|
||||
i.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
if ( rv != null )
|
||||
{
|
||||
// i.markDirty();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
|
||||
if ( is != null && canRemoveStackFromSlot( x, is ) && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
{
|
||||
int lhow_many = how_many;
|
||||
if ( lhow_many > is.stackSize )
|
||||
lhow_many = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
lhow_many = 0;
|
||||
|
||||
if ( lhow_many > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = lhow_many;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
ItemStack rv = null;
|
||||
|
||||
for (int x = 0; x < s && how_many > 0; x++)
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is != null && canRemoveStackFromSlot( x, is ) && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
{
|
||||
int lhow_many = how_many;
|
||||
if ( lhow_many > is.stackSize )
|
||||
lhow_many = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
lhow_many = 0;
|
||||
|
||||
if ( lhow_many > 0 )
|
||||
{
|
||||
if ( rv == null )
|
||||
{
|
||||
rv = is.copy();
|
||||
filter = rv;
|
||||
rv.stackSize = lhow_many;
|
||||
how_many -= lhow_many;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv.stackSize += lhow_many;
|
||||
how_many -= lhow_many;
|
||||
}
|
||||
|
||||
if ( is.stackSize == lhow_many )
|
||||
{
|
||||
i.setInventorySlotContents( x, null );
|
||||
i.markDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack po = is.copy();
|
||||
po.stackSize -= lhow_many;
|
||||
i.setInventorySlotContents( x, po );
|
||||
i.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if ( rv != null )
|
||||
// i.markDirty();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
ItemStack rv = null;
|
||||
|
||||
for (int x = 0; x < s && how_many > 0; x++)
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is != null && canRemoveStackFromSlot( x, is ) && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
{
|
||||
int lhow_many = how_many;
|
||||
if ( lhow_many > is.stackSize )
|
||||
lhow_many = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
lhow_many = 0;
|
||||
|
||||
if ( lhow_many > 0 )
|
||||
{
|
||||
if ( rv == null )
|
||||
{
|
||||
rv = is.copy();
|
||||
rv.stackSize = lhow_many;
|
||||
how_many -= lhow_many;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv.stackSize += lhow_many;
|
||||
how_many -= lhow_many;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
ItemStack left = A.copy();
|
||||
|
||||
int stack_limit = A.getMaxStackSize();
|
||||
if ( stack_limit > i.getInventoryStackLimit() )
|
||||
stack_limit = i.getInventoryStackLimit();
|
||||
|
||||
int s = i.getSizeInventory();
|
||||
for (int pass = 0; pass < 2; pass++)
|
||||
{
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
if ( i.isItemValidForSlot( x, A ) )
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is == null && pass != 0 )
|
||||
{
|
||||
ItemStack thisSlot = left.copy();
|
||||
if ( thisSlot.stackSize > stack_limit )
|
||||
thisSlot.stackSize = stack_limit;
|
||||
left.stackSize -= thisSlot.stackSize;
|
||||
|
||||
i.setInventorySlotContents( x, thisSlot );
|
||||
|
||||
if ( left.stackSize <= 0 )
|
||||
{
|
||||
// i.markDirty();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if ( is != null )
|
||||
{
|
||||
if ( Platform.isSameItemPrecise( is, left ) )
|
||||
{
|
||||
if ( is.stackSize < stack_limit )
|
||||
{
|
||||
int room = stack_limit - is.stackSize;
|
||||
int used = left.stackSize;
|
||||
if ( used > room )
|
||||
used = room;
|
||||
|
||||
is.stackSize += used;
|
||||
i.setInventorySlotContents( x, is );
|
||||
i.markDirty();
|
||||
|
||||
left.stackSize -= used;
|
||||
if ( left.stackSize <= 0 )
|
||||
{
|
||||
// i.markDirty();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if ( left.stackSize != A.stackSize )
|
||||
// i.markDirty();
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
if ( A == null )
|
||||
return A;
|
||||
ItemStack left = A.copy();
|
||||
|
||||
int stack_limit = A.getMaxStackSize();
|
||||
if ( stack_limit > i.getInventoryStackLimit() )
|
||||
stack_limit = i.getInventoryStackLimit();
|
||||
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
if ( i.isItemValidForSlot( x, A ) )
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is == null )
|
||||
{
|
||||
ItemStack thisSlot = left.copy();
|
||||
if ( thisSlot.stackSize > stack_limit )
|
||||
thisSlot.stackSize = stack_limit;
|
||||
left.stackSize -= thisSlot.stackSize;
|
||||
|
||||
if ( left.stackSize <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( Platform.isSameItemPrecise( is, left ) )
|
||||
{
|
||||
if ( is.stackSize < stack_limit )
|
||||
{
|
||||
int room = stack_limit - is.stackSize;
|
||||
int used = left.stackSize;
|
||||
if ( used > room )
|
||||
used = room;
|
||||
|
||||
left.stackSize -= used;
|
||||
if ( left.stackSize <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
class InvIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
|
||||
final ItemSlot is = new ItemSlot();
|
||||
int x = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return x < i.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
ItemStack iss = i.getStackInSlot( x );
|
||||
|
||||
is.isExtractable = canRemoveStackFromSlot( x, iss );
|
||||
is.setItemStack( iss );
|
||||
|
||||
is.slot = x++;
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
// nothing!
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new InvIterator();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import buildcraft.api.inventory.ISpecialInventory;
|
||||
|
||||
public class AdaptorISpecialInventory extends InventoryAdaptor
|
||||
{
|
||||
|
||||
private AdaptorIInventory remover;
|
||||
|
||||
private ISpecialInventory i;
|
||||
private ForgeDirection d;
|
||||
|
||||
public AdaptorISpecialInventory(ISpecialInventory s, ForgeDirection dd) {
|
||||
i = s;
|
||||
d = dd;
|
||||
|
||||
if ( s instanceof ISidedInventory )
|
||||
remover = new AdaptorIInventory( new WrapperMCISidedInventory( (ISidedInventory) s, d ) );
|
||||
else
|
||||
remover = new AdaptorIInventory( s );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
return remover.removeSimilarItems( how_many, filter, fuzzyMode, destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
return remover.simulateSimilarRemove( how_many, filter, fuzzyMode, destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
return remover.removeItems( how_many, filter, destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
return remover.simulateRemove( how_many, filter, destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
int used = i.addItem( A, true, d );
|
||||
ItemStack out = A.copy();
|
||||
out.stackSize -= used;
|
||||
if ( out.stackSize > 0 )
|
||||
return out;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
int used = i.addItem( A, false, d );
|
||||
ItemStack out = A.copy();
|
||||
out.stackSize -= used;
|
||||
if ( out.stackSize > 0 )
|
||||
return out;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
if ( i instanceof ISidedInventory )
|
||||
{
|
||||
ISidedInventory sided = (ISidedInventory) i;
|
||||
int slots[] = sided.getAccessibleSlotsFromSide( d.ordinal() );
|
||||
|
||||
if ( slots == null )
|
||||
return false;
|
||||
|
||||
int s = slots.length;
|
||||
for (int x = 0; x < s; x++)
|
||||
if ( i.getStackInSlot( slots[x] ) != null )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
if ( i.getStackInSlot( x ) != null )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return remover.iterator();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.StackToSlotIterator;
|
||||
|
||||
public class AdaptorList extends InventoryAdaptor
|
||||
{
|
||||
|
||||
private List<ItemStack> i;
|
||||
|
||||
public AdaptorList(List<ItemStack> s) {
|
||||
i = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
|
||||
{
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
{
|
||||
if ( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if ( dest != null && !dest.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 )
|
||||
i.remove( x );
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
|
||||
{
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
{
|
||||
if ( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if ( dest != null && !dest.canInsert( is ) )
|
||||
how_many = 0;
|
||||
|
||||
if ( how_many > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = how_many;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination dest)
|
||||
{
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
{
|
||||
if ( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if ( dest != null && !dest.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 )
|
||||
i.remove( x );
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination dest)
|
||||
{
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
{
|
||||
if ( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if ( dest != null && !dest.canInsert( is ) )
|
||||
how_many = 0;
|
||||
|
||||
if ( how_many > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = how_many;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
ItemStack left = A.copy();
|
||||
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( Platform.isSameItem( is, left ) )
|
||||
{
|
||||
is.stackSize += left.stackSize;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
i.add( left );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new StackToSlotIterator( i.iterator() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.NullIterator;
|
||||
|
||||
/*
|
||||
* Lets you do simply tests with the players cursor, without messing with the specifics.
|
||||
*/
|
||||
public class AdaptorPlayerHand extends InventoryAdaptor
|
||||
{
|
||||
|
||||
private EntityPlayer p;
|
||||
|
||||
public AdaptorPlayerHand(EntityPlayer _p) {
|
||||
p = _p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
|
||||
{
|
||||
ItemStack hand = 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 )
|
||||
p.inventory.setItemStack( null );
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
|
||||
{
|
||||
|
||||
ItemStack hand = 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;
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack Filter, IInventoryDestination dest)
|
||||
{
|
||||
ItemStack hand = p.inventory.getItemStack();
|
||||
if ( hand == null )
|
||||
return null;
|
||||
|
||||
if ( Filter == null || Platform.isSameItemPrecise( Filter, hand ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
|
||||
hand.stackSize -= how_many;
|
||||
if ( hand.stackSize <= 0 )
|
||||
p.inventory.setItemStack( null );
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack Filter, IInventoryDestination dest)
|
||||
{
|
||||
|
||||
ItemStack hand = p.inventory.getItemStack();
|
||||
if ( hand == null )
|
||||
return null;
|
||||
|
||||
if ( Filter == null || Platform.isSameItemPrecise( Filter, hand ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
if ( p == null )
|
||||
return A;
|
||||
if ( p.inventory == null )
|
||||
return A;
|
||||
|
||||
ItemStack hand = p.inventory.getItemStack();
|
||||
|
||||
if ( hand != null && !Platform.isSameItem( A, hand ) )
|
||||
return A;
|
||||
|
||||
int original = 0;
|
||||
ItemStack newHand = null;
|
||||
if ( hand == null )
|
||||
newHand = A.copy();
|
||||
else
|
||||
{
|
||||
newHand = hand;
|
||||
original = hand.stackSize;
|
||||
newHand.stackSize += A.stackSize;
|
||||
}
|
||||
|
||||
if ( newHand.stackSize > newHand.getMaxStackSize() )
|
||||
{
|
||||
newHand.stackSize = newHand.getMaxStackSize();
|
||||
ItemStack B = A.copy();
|
||||
B.stackSize -= newHand.stackSize - original;
|
||||
p.inventory.setItemStack( newHand );
|
||||
return B;
|
||||
}
|
||||
|
||||
p.inventory.setItemStack( newHand );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
ItemStack hand = p.inventory.getItemStack();
|
||||
if ( A == null )
|
||||
return null;
|
||||
|
||||
if ( hand != null && !Platform.isSameItem( A, hand ) )
|
||||
return A;
|
||||
|
||||
int original = 0;
|
||||
ItemStack newHand = null;
|
||||
if ( hand == null )
|
||||
newHand = A.copy();
|
||||
else
|
||||
{
|
||||
newHand = hand.copy();
|
||||
original = hand.stackSize;
|
||||
newHand.stackSize += A.stackSize;
|
||||
}
|
||||
|
||||
if ( newHand.stackSize > newHand.getMaxStackSize() )
|
||||
{
|
||||
newHand.stackSize = newHand.getMaxStackSize();
|
||||
ItemStack B = A.copy();
|
||||
B.stackSize -= newHand.stackSize - original;
|
||||
return B;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return p.inventory.getItemStack() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new NullIterator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
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;
|
||||
|
||||
public AdaptorPlayerInventory(IInventory playerInv, boolean swap)
|
||||
{
|
||||
|
||||
if ( swap )
|
||||
src = new WrapperChainedInventory( new WrapperInventoryRange( playerInv, 9, size-9, false ), new WrapperInventoryRange( playerInv, 0, 9, false ) );
|
||||
else
|
||||
src = playerInv;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1)
|
||||
{
|
||||
return src.getStackInSlot( var1 + min );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2)
|
||||
{
|
||||
return src.decrStackSize( min + var1, var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1)
|
||||
{
|
||||
return src.getStackInSlotOnClosing( min + var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int var1, ItemStack var2)
|
||||
{
|
||||
src.setInventorySlotContents( var1 + min, var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return src.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return src.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
src.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
{
|
||||
return src.isUseableByPlayer( var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
src.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
src.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IInventoryDestination
|
||||
{
|
||||
|
||||
public boolean canInsert(ItemStack stack);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IInventoryWrapper
|
||||
{
|
||||
|
||||
boolean canRemoveItemFromSlot(int x, ItemStack is);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class IMEAdaptor extends InventoryAdaptor
|
||||
{
|
||||
|
||||
IMEInventory<IAEItemStack> target;
|
||||
BaseActionSource src;
|
||||
int maxSlots = 0;
|
||||
|
||||
public IMEAdaptor(IMEInventory<IAEItemStack> input, BaseActionSource src) {
|
||||
target = input;
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
IItemList<IAEItemStack> getList()
|
||||
{
|
||||
return target.getAvailableItems( AEApi.instance().storage().createItemList() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new IMEAdaptorIterator( this, getList() );
|
||||
}
|
||||
|
||||
public ItemStack doRemoveItemsFuzzy(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type, FuzzyMode fuzzyMode)
|
||||
{
|
||||
IAEItemStack reqFilter = AEItemStack.create( Filter );
|
||||
if ( reqFilter == null )
|
||||
return null;
|
||||
|
||||
IAEItemStack out = null;
|
||||
|
||||
for (IAEItemStack req : ImmutableList.copyOf( getList().findFuzzy( reqFilter, fuzzyMode ) ))
|
||||
{
|
||||
if ( req != null )
|
||||
{
|
||||
req.setStackSize( how_many );
|
||||
out = target.extractItems( req, type, src );
|
||||
if ( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack doRemoveItems(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type)
|
||||
{
|
||||
IAEItemStack req = null;
|
||||
|
||||
if ( Filter == null )
|
||||
{
|
||||
IItemList<IAEItemStack> list = getList();
|
||||
if ( !list.isEmpty() )
|
||||
req = list.getFirstItem();
|
||||
}
|
||||
else
|
||||
req = AEItemStack.create( Filter );
|
||||
|
||||
IAEItemStack out = null;
|
||||
|
||||
if ( req != null )
|
||||
{
|
||||
req.setStackSize( how_many );
|
||||
out = target.extractItems( req, type, src );
|
||||
}
|
||||
|
||||
if ( out != null )
|
||||
return out.getItemStack();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack Filter, IInventoryDestination destination)
|
||||
{
|
||||
return doRemoveItems( how_many, Filter, destination, Actionable.MODULATE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack Filter, IInventoryDestination destination)
|
||||
{
|
||||
return doRemoveItems( how_many, Filter, destination, Actionable.SIMULATE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
if ( filter == null )
|
||||
return doRemoveItems( how_many, null, destination, Actionable.MODULATE );
|
||||
return doRemoveItemsFuzzy( how_many, filter, destination, Actionable.MODULATE, fuzzyMode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
if ( filter == null )
|
||||
return doRemoveItems( how_many, null, destination, Actionable.SIMULATE );
|
||||
return doRemoveItemsFuzzy( how_many, filter, destination, Actionable.SIMULATE, fuzzyMode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
IAEItemStack in = AEItemStack.create( A );
|
||||
if ( in != null )
|
||||
{
|
||||
IAEItemStack out = target.injectItems( in, Actionable.MODULATE, src );
|
||||
if ( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
IAEItemStack in = AEItemStack.create( A );
|
||||
if ( in != null )
|
||||
{
|
||||
IAEItemStack out = target.injectItems( in, Actionable.SIMULATE, src );
|
||||
if ( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return !getList().isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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>
|
||||
{
|
||||
|
||||
Iterator<IAEItemStack> stack;
|
||||
ItemSlot slot = new ItemSlot();
|
||||
int offset = 0;
|
||||
boolean hasNext;
|
||||
|
||||
final IMEAdaptor parent;
|
||||
final int containerSize;
|
||||
|
||||
public IMEAdaptorIterator(IMEAdaptor parent, IItemList<IAEItemStack> availableItems) {
|
||||
stack = availableItems.iterator();
|
||||
containerSize = parent.maxSlots;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
hasNext = stack.hasNext();
|
||||
return offset < containerSize || hasNext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
slot.slot = offset++;
|
||||
slot.isExtractable=true;
|
||||
|
||||
if ( parent.maxSlots < offset )
|
||||
parent.maxSlots = offset;
|
||||
|
||||
if ( hasNext )
|
||||
{
|
||||
IAEItemStack item = stack.next();
|
||||
slot.setAEItemStack( item );
|
||||
return slot;
|
||||
}
|
||||
|
||||
slot.setItemStack( null );
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new RuntimeException( "Not Implemented!" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class IMEInventoryDestination implements IInventoryDestination
|
||||
{
|
||||
|
||||
IMEInventory<IAEItemStack> me;
|
||||
|
||||
public IMEInventoryDestination(IMEInventory<IAEItemStack> o) {
|
||||
me = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack)
|
||||
{
|
||||
|
||||
if ( stack == null )
|
||||
return false;
|
||||
|
||||
IAEItemStack failed = me.injectItems( AEItemStack.create( stack ), Actionable.SIMULATE, null );
|
||||
|
||||
if ( failed == null )
|
||||
return true;
|
||||
return failed.getStackSize() != stack.stackSize;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
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) {
|
||||
target = cla;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(T option)
|
||||
{
|
||||
if ( option != null && option.isCraftable() )
|
||||
{
|
||||
option = (T) option.copy();
|
||||
option.setCraftable( false );
|
||||
}
|
||||
|
||||
target.add( option );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting(T option)
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findPrecise(T i)
|
||||
{
|
||||
return target.findPrecise( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> findFuzzy(T input, FuzzyMode fuzzy)
|
||||
{
|
||||
return target.findFuzzy( input, fuzzy );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return target.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage(T option)
|
||||
{
|
||||
target.addStorage( option );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable(T option)
|
||||
{
|
||||
target.addRequestable( option );
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFirstItem()
|
||||
{
|
||||
return target.getFirstItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return target.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
return target.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
target.resetStatus();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
|
||||
// one or the other..
|
||||
private IAEItemStack aeitemstack;
|
||||
private ItemStack itemStack;
|
||||
|
||||
public boolean isExtractable;
|
||||
|
||||
public void setItemStack(ItemStack is)
|
||||
{
|
||||
aeitemstack = null;
|
||||
itemStack = is;
|
||||
}
|
||||
|
||||
public void setAEItemStack(IAEItemStack is)
|
||||
{
|
||||
aeitemstack = is;
|
||||
itemStack = null;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return itemStack == null ? (aeitemstack == null ? null : (itemStack = aeitemstack.getItemStack())) : itemStack;
|
||||
}
|
||||
|
||||
public IAEItemStack getAEItemStack()
|
||||
{
|
||||
return aeitemstack == null ? (itemStack == null ? null : (aeitemstack = AEItemStack.create( itemStack ))) : aeitemstack;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
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;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
|
||||
public class WrapperBCPipe implements IInventory
|
||||
{
|
||||
|
||||
final private IBC bc;
|
||||
final private TileEntity ad;
|
||||
final private ForgeDirection dir;
|
||||
|
||||
public WrapperBCPipe(TileEntity te, ForgeDirection d) {
|
||||
bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
||||
ad = te;
|
||||
dir = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
bc.addItemsToPipe( ad, itemstack, dir );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return "BC Pipe Wrapper";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return bc.canAddItemsToPipe( ad, itemstack, dir );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
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;
|
||||
|
||||
public class WrapperChainedInventory implements IInventory
|
||||
{
|
||||
|
||||
class InvOffset
|
||||
{
|
||||
|
||||
int offset;
|
||||
int size;
|
||||
IInventory i;
|
||||
};
|
||||
|
||||
int fullSize = 0;
|
||||
|
||||
private List<IInventory> l;
|
||||
private HashMap<Integer, InvOffset> offsets;
|
||||
|
||||
public WrapperChainedInventory(IInventory... ilist) {
|
||||
setInventory( ilist );
|
||||
}
|
||||
|
||||
public WrapperChainedInventory(List<IInventory> ilist) {
|
||||
setInventory( ilist );
|
||||
}
|
||||
|
||||
public void cycleOrder()
|
||||
{
|
||||
if ( l.size() > 1 )
|
||||
{
|
||||
List<IInventory> newOrder = new ArrayList( l.size() );
|
||||
newOrder.add( l.get( l.size() - 1 ) );
|
||||
for (int x = 0; x < l.size() - 1; x++)
|
||||
newOrder.add( l.get( x ) );
|
||||
setInventory( newOrder );
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateSizes()
|
||||
{
|
||||
offsets = new HashMap<Integer, WrapperChainedInventory.InvOffset>();
|
||||
|
||||
int offset = 0;
|
||||
for (IInventory in : l)
|
||||
{
|
||||
InvOffset io = new InvOffset();
|
||||
io.offset = offset;
|
||||
io.size = in.getSizeInventory();
|
||||
io.i = in;
|
||||
|
||||
for (int y = 0; y < io.size; y++)
|
||||
{
|
||||
offsets.put( y + io.offset, io );
|
||||
}
|
||||
|
||||
offset += io.size;
|
||||
}
|
||||
|
||||
fullSize = offset;
|
||||
}
|
||||
|
||||
public void setInventory(IInventory... a)
|
||||
{
|
||||
l = ImmutableList.copyOf( a );
|
||||
calculateSizes();
|
||||
}
|
||||
|
||||
public void setInventory(List<IInventory> a)
|
||||
{
|
||||
l = a;
|
||||
calculateSizes();
|
||||
}
|
||||
|
||||
public IInventory getInv(int idx)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getInvSlot(int idx)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return idx - io.offset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return fullSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int idx)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i.getStackInSlot( idx - io.offset );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int idx, int var2)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i.decrStackSize( idx - io.offset, var2 );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int idx)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i.getStackInSlotOnClosing( idx - io.offset );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int idx, ItemStack var2)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
io.i.setInventorySlotContents( idx - io.offset, var2 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return "ChainedInv";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
int smallest = 64;
|
||||
|
||||
for (IInventory i : l)
|
||||
smallest = Math.min( smallest, i.getInventoryStackLimit() );
|
||||
|
||||
return smallest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
for (IInventory i : l)
|
||||
{
|
||||
i.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int idx, ItemStack itemstack)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i.isItemValidForSlot( idx - io.offset, itemstack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class WrapperInvSlot
|
||||
{
|
||||
|
||||
class InternalInterfaceWrapper implements IInventory
|
||||
{
|
||||
|
||||
private final IInventory inv;
|
||||
private final int slot;
|
||||
|
||||
public InternalInterfaceWrapper(IInventory target, int slot) {
|
||||
this.inv = target;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return inv.getStackInSlot( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int num)
|
||||
{
|
||||
return inv.decrStackSize( slot, num );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return inv.getStackInSlotOnClosing( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
inv.setInventorySlotContents( slot, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return inv.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return inv.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
inv.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return inv.isUseableByPlayer( entityplayer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
inv.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
inv.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return isItemValid( itemstack ) && inv.isItemValidForSlot( slot, itemstack );
|
||||
}
|
||||
};
|
||||
|
||||
private IInventory inv;
|
||||
|
||||
public WrapperInvSlot(IInventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public IInventory getWrapper(int slot)
|
||||
{
|
||||
InternalInterfaceWrapper wrapper = new InternalInterfaceWrapper( inv, slot );
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
protected boolean isItemValid(ItemStack itemstack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
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 IInventory src;
|
||||
int[] slots;
|
||||
protected boolean ignoreValidItems = false;
|
||||
|
||||
public static String concatLines(int[] s, String separator)
|
||||
{
|
||||
if ( s.length > 0 )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < s.length; i++)
|
||||
{
|
||||
if ( sb.length() > 0 )
|
||||
sb.append( separator );
|
||||
sb.append( s[i] );
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public WrapperInventoryRange(IInventory a, int[] s, boolean ignoreValid) {
|
||||
src = a;
|
||||
slots = s;
|
||||
|
||||
if ( slots == null )
|
||||
slots = new int[0];
|
||||
|
||||
ignoreValidItems = ignoreValid;
|
||||
}
|
||||
|
||||
public WrapperInventoryRange(IInventory a, int _min, int _size, boolean ignoreValid) {
|
||||
src = a;
|
||||
slots = new int[_size];
|
||||
for (int x = 0; x < _size; x++)
|
||||
slots[x] = _min + x;
|
||||
ignoreValidItems = ignoreValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return slots.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1)
|
||||
{
|
||||
return src.getStackInSlot( slots[var1] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2)
|
||||
{
|
||||
return src.decrStackSize( slots[var1], var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1)
|
||||
{
|
||||
return src.getStackInSlotOnClosing( slots[var1] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int var1, ItemStack var2)
|
||||
{
|
||||
src.setInventorySlotContents( slots[var1], var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return src.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return src.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
src.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
{
|
||||
return src.isUseableByPlayer( var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
src.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
src.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
if ( ignoreValidItems )
|
||||
return true;
|
||||
|
||||
return src.isItemValidForSlot( slots[i], itemstack );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class WrapperMCISidedInventory extends WrapperInventoryRange implements IInventory, IInventoryWrapper
|
||||
{
|
||||
|
||||
private ForgeDirection dir;
|
||||
ISidedInventory side;
|
||||
|
||||
public WrapperMCISidedInventory(ISidedInventory a, ForgeDirection d) {
|
||||
super( a, a.getAccessibleSlotsFromSide( d.ordinal() ), false );
|
||||
side = a;
|
||||
dir = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
|
||||
if ( ignoreValidItems )
|
||||
return true;
|
||||
|
||||
if ( side.isItemValidForSlot( slots[i], itemstack ) )
|
||||
return side.canInsertItem( slots[i], itemstack, dir.ordinal() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveItemFromSlot(int i, ItemStack is)
|
||||
{
|
||||
if ( is == null )
|
||||
return false;
|
||||
|
||||
return side.canExtractItem( slots[i], is, dir.ordinal() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2)
|
||||
{
|
||||
if ( canRemoveItemFromSlot( var1, getStackInSlot( var1 ) ) )
|
||||
return super.decrStackSize( var1, var2 );
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
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
|
||||
{
|
||||
|
||||
TileEntity ad;
|
||||
ForgeDirection dir;
|
||||
|
||||
public WrapperTEPipe(TileEntity te, ForgeDirection d) {
|
||||
ad = te;
|
||||
dir = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
// ITE.addItemsToPipe( ad, itemstack, dir );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
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>
|
||||
{
|
||||
|
||||
public int myHash;
|
||||
Fluid fluid;
|
||||
protected IAETagCompound tagCompound;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getFluidStack().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAETagCompound getTagCompound()
|
||||
{
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(IAEFluidStack option)
|
||||
{
|
||||
if ( option == null )
|
||||
return;
|
||||
|
||||
// if ( priority < ((AEFluidStack) option).priority )
|
||||
// priority = ((AEFluidStack) option).priority;
|
||||
|
||||
incStackSize( option.getStackSize() );
|
||||
setCountRequestable( getCountRequestable() + option.getCountRequestable() );
|
||||
setCraftable( isCraftable() || option.isCraftable() );
|
||||
}
|
||||
|
||||
private AEFluidStack(AEFluidStack is) {
|
||||
|
||||
fluid = is.fluid;
|
||||
stackSize = is.stackSize;
|
||||
|
||||
// priority = is.priority;
|
||||
setCraftable( is.isCraftable() );
|
||||
setCountRequestable( is.getCountRequestable() );
|
||||
|
||||
this.myHash = is.myHash;
|
||||
}
|
||||
|
||||
protected AEFluidStack(FluidStack is) {
|
||||
if ( is == null )
|
||||
throw new RuntimeException( "Invalid Itemstack." );
|
||||
|
||||
fluid = is.getFluid();
|
||||
|
||||
if ( fluid == null )
|
||||
throw new RuntimeException( "Fluid is null." );
|
||||
|
||||
stackSize = is.amount;
|
||||
setCraftable( false );
|
||||
setCountRequestable( 0 );
|
||||
|
||||
myHash = fluid.hashCode() ^ (tagCompound == null ? 0 : System.identityHashCode( tagCompound ));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if ( ia instanceof AEFluidStack )
|
||||
{
|
||||
return ((AEFluidStack) ia).fluid == fluid && tagCompound == ((AEFluidStack) ia).tagCompound;
|
||||
}
|
||||
else if ( ia instanceof FluidStack )
|
||||
{
|
||||
FluidStack is = (FluidStack) ia;
|
||||
|
||||
if ( is.fluidID == this.fluid.getID() )
|
||||
{
|
||||
NBTTagCompound ta = (NBTTagCompound) 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 FluidStack getFluidStack()
|
||||
{
|
||||
FluidStack is = new FluidStack( fluid, (int) Math.min( Integer.MAX_VALUE, stackSize ) );
|
||||
if ( tagCompound != null )
|
||||
is.tag = tagCompound.getNBTTagCompoundCopy();
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack copy()
|
||||
{
|
||||
return new AEFluidStack( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound i)
|
||||
{
|
||||
/*
|
||||
* Mojang Fucked this over ; GC Optimization - Ugly Yes, but it saves a lot in the memory department.
|
||||
*/
|
||||
|
||||
/*
|
||||
* NBTBase FluidName = i.getTag( "FluidName" ); NBTBase Count = i.getTag( "Count" ); NBTBase Cnt = i.getTag(
|
||||
* "Cnt" ); NBTBase Req = i.getTag( "Req" ); NBTBase Craft = i.getTag( "Craft" );
|
||||
*/
|
||||
|
||||
/*
|
||||
* if ( FluidName != null && FluidName instanceof NBTTagString ) ((NBTTagString) FluidName).data = (String)
|
||||
* this.fluid.getName(); else
|
||||
*/
|
||||
i.setString( "FluidName", (String) this.fluid.getName() );
|
||||
|
||||
/*
|
||||
* if ( Count != null && Count instanceof NBTTagByte ) ((NBTTagByte) Count).data = (byte) 0; else
|
||||
*/
|
||||
i.setByte( "Count", (byte) 0 );
|
||||
|
||||
/*
|
||||
* if ( Cnt != null && Cnt instanceof NBTTagLong ) ((NBTTagLong) Cnt).data = this.stackSize; else
|
||||
*/
|
||||
i.setLong( "Cnt", this.stackSize );
|
||||
|
||||
/*
|
||||
* if ( Req != null && Req instanceof NBTTagLong ) ((NBTTagLong) Req).data = this.stackSize; else
|
||||
*/
|
||||
i.setLong( "Req", this.getCountRequestable() );
|
||||
|
||||
/*
|
||||
* if ( Craft != null && Craft instanceof NBTTagByte ) ((NBTTagByte) Craft).data = (byte) (this.isCraftable() ?
|
||||
* 1 : 0); else
|
||||
*/i.setBoolean( "Craft", this.isCraftable() );
|
||||
|
||||
if ( tagCompound != null )
|
||||
i.setTag( "tag", (NBTTagCompound) tagCompound );
|
||||
else
|
||||
i.removeTag( "tag" );
|
||||
|
||||
}
|
||||
|
||||
public static IAEFluidStack loadFluidStackFromNBT(NBTTagCompound i)
|
||||
{
|
||||
ItemStack itemstack = ItemStack.loadItemStackFromNBT( i );
|
||||
if ( itemstack == null )
|
||||
return null;
|
||||
AEFluidStack aeis = AEFluidStack.create( itemstack );
|
||||
// aeis.priority = i.getInteger( "Priority" );
|
||||
aeis.stackSize = i.getLong( "Cnt" );
|
||||
aeis.setCountRequestable( i.getLong( "Req" ) );
|
||||
aeis.setCraftable( i.getBoolean( "Craft" ) );
|
||||
return aeis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return tagCompound != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return myHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AEFluidStack b)
|
||||
{
|
||||
int diff = hashCode() - b.hashCode();
|
||||
return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeIdentity(ByteBuf i) throws IOException
|
||||
{
|
||||
byte[] name = fluid.getName().getBytes( "UTF-8" );
|
||||
i.writeByte( (byte) name.length );
|
||||
i.writeBytes( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
void readNBT(ByteBuf i) throws IOException
|
||||
{
|
||||
if ( hasTagCompound() )
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
CompressedStreamTools.write( (NBTTagCompound) getTagCompound(), 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 ) );
|
||||
}
|
||||
|
||||
// long priority = getPacketValue( PriorityType, data );
|
||||
long stackSize = getPacketValue( StackType, data );
|
||||
long countRequestable = getPacketValue( CountReqType, data );
|
||||
|
||||
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( d );
|
||||
if ( fluidStack == null )
|
||||
return null;
|
||||
|
||||
AEFluidStack aeis = AEFluidStack.create( fluidStack );
|
||||
// aeis.priority = (int) priority;
|
||||
aeis.stackSize = stackSize;
|
||||
aeis.setCountRequestable( countRequestable );
|
||||
aeis.setCraftable( isCraftable );
|
||||
return aeis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fluid getFluid()
|
||||
{
|
||||
return fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack empty()
|
||||
{
|
||||
IAEFluidStack dup = copy();
|
||||
dup.reset();
|
||||
return dup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fuzzyComparison(Object st, FuzzyMode mode)
|
||||
{
|
||||
if ( st instanceof FluidStack )
|
||||
{
|
||||
return ((FluidStack) st).getFluid() == getFluid();
|
||||
}
|
||||
|
||||
if ( st instanceof IAEFluidStack )
|
||||
{
|
||||
return ((IAEFluidStack) st).getFluid() == getFluid();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItem()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluid()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.FLUIDS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class AEItemDef
|
||||
{
|
||||
|
||||
public int myHash;
|
||||
|
||||
public int def;
|
||||
|
||||
private int itemID;
|
||||
public Item item;
|
||||
public int damageValue;
|
||||
|
||||
public int dspDamage;
|
||||
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 AESharedNBT lowTag = new AESharedNBT( Integer.MIN_VALUE );
|
||||
static AESharedNBT highTag = new AESharedNBT( Integer.MAX_VALUE );
|
||||
|
||||
public AEItemDef(Item it) {
|
||||
item = it;
|
||||
itemID = System.identityHashCode( item );
|
||||
}
|
||||
|
||||
public AEItemDef copy()
|
||||
{
|
||||
AEItemDef t = new AEItemDef( item );
|
||||
t.def = def;
|
||||
t.damageValue = damageValue;
|
||||
t.dspDamage = dspDamage;
|
||||
t.maxDamage = maxDamage;
|
||||
t.tagCompound = tagCompound;
|
||||
t.isOre = isOre;
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
AEItemDef def = (AEItemDef) obj;
|
||||
return def.damageValue == damageValue && def.item == item && tagCompound == def.tagCompound;
|
||||
}
|
||||
|
||||
public int getDamageValueHack(ItemStack is)
|
||||
{
|
||||
return Items.blaze_rod.getDamage( is );
|
||||
}
|
||||
|
||||
public boolean isItem(ItemStack otherStack)
|
||||
{
|
||||
// hackery!
|
||||
int dmg = getDamageValueHack( otherStack );
|
||||
|
||||
if ( item == otherStack.getItem() && dmg == damageValue )
|
||||
{
|
||||
if ( (tagCompound != null) == otherStack.hasTagCompound() )
|
||||
return true;
|
||||
|
||||
if ( tagCompound != null && otherStack.hasTagCompound() )
|
||||
return Platform.NBTEqualityTest( (NBTBase) tagCompound, otherStack.getTagCompound() );
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void reHash()
|
||||
{
|
||||
def = itemID << Platform.DEF_OFFSET | damageValue;
|
||||
myHash = def ^ (tagCompound == null ? 0 : System.identityHashCode( tagCompound ));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,630 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAETagCompound;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack, Comparable<AEItemStack>
|
||||
{
|
||||
|
||||
AEItemDef def;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getItemStack().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(IAEItemStack option)
|
||||
{
|
||||
if ( option == null )
|
||||
return;
|
||||
|
||||
// if ( priority < ((AEItemStack) option).priority )
|
||||
// priority = ((AEItemStack) option).priority;
|
||||
|
||||
incStackSize( option.getStackSize() );
|
||||
setCountRequestable( getCountRequestable() + option.getCountRequestable() );
|
||||
setCraftable( isCraftable() || option.isCraftable() );
|
||||
}
|
||||
|
||||
private AEItemStack(AEItemStack is) {
|
||||
def = is.def;
|
||||
stackSize = is.stackSize;
|
||||
setCraftable( is.isCraftable() );
|
||||
setCountRequestable( is.getCountRequestable() );
|
||||
}
|
||||
|
||||
protected AEItemStack(ItemStack is) {
|
||||
if ( is == null )
|
||||
throw new RuntimeException( "Invalid Itemstack." );
|
||||
|
||||
def = new AEItemDef( is.getItem() );
|
||||
|
||||
if ( def.item == null )
|
||||
throw new RuntimeException( "This ItemStack is bad, it has a null item." );
|
||||
|
||||
/*
|
||||
* Prevent an Item from changing the damage value on me... Either, this or a core mod.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Super Hacky.
|
||||
*
|
||||
* is.itemID = appeng.api.Materials.matQuartz.itemID; damageValue = is.getItemDamage(); is.itemID = itemID;
|
||||
*/
|
||||
|
||||
/*
|
||||
* Kinda Hacky
|
||||
*/
|
||||
def.damageValue = def.getDamageValueHack( is );
|
||||
def.dspDamage = is.getItemDamageForDisplay();
|
||||
def.maxDamage = is.getMaxDamage();
|
||||
|
||||
NBTTagCompound tagCompound = is.getTagCompound();
|
||||
if ( tagCompound != null )
|
||||
def.tagCompound = (AESharedNBT) AESharedNBT.getSharedTagCompound( tagCompound, is );
|
||||
|
||||
stackSize = is.stackSize;
|
||||
setCraftable( false );
|
||||
setCountRequestable( 0 );
|
||||
|
||||
def.reHash();
|
||||
def.isOre = OreHelper.instance.isOre( is );
|
||||
}
|
||||
|
||||
public static AEItemStack create(Object a)
|
||||
{
|
||||
if ( a instanceof ItemStack )
|
||||
return new AEItemStack( (ItemStack) a );
|
||||
if ( a instanceof IAEItemStack )
|
||||
((IAEItemStack) a).copy();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItem()
|
||||
{
|
||||
return def.item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object ia)
|
||||
{
|
||||
if ( ia instanceof AEItemStack )
|
||||
{
|
||||
return ((AEItemStack) ia).def.equals( def );// && def.tagCompound == ((AEItemStack) ia).def.tagCompound;
|
||||
}
|
||||
else if ( ia instanceof ItemStack )
|
||||
{
|
||||
ItemStack is = (ItemStack) ia;
|
||||
|
||||
if ( is.getItem() == def.item && is.getItemDamage() == this.def.damageValue )
|
||||
{
|
||||
NBTTagCompound ta = (NBTTagCompound) 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 ItemStack getItemStack()
|
||||
{
|
||||
ItemStack is = new ItemStack( def.item, (int) Math.min( Integer.MAX_VALUE, stackSize ), def.damageValue );
|
||||
if ( def.tagCompound != null )
|
||||
is.setTagCompound( def.tagCompound.getNBTTagCompoundCopy() );
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack copy()
|
||||
{
|
||||
return new AEItemStack( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound i)
|
||||
{
|
||||
/*
|
||||
* Mojang Fucked this over ; GC Optimization - Ugly Yes, but it saves a lot in the memory department.
|
||||
*/
|
||||
|
||||
/*
|
||||
* NBTBase id = i.getTag( "id" ); NBTBase Count = i.getTag( "Count" ); NBTBase Cnt = i.getTag( "Cnt" ); NBTBase
|
||||
* Req = i.getTag( "Req" ); NBTBase Craft = i.getTag( "Craft" ); NBTBase Damage = i.getTag( "Damage" );
|
||||
*/
|
||||
|
||||
/*
|
||||
* if ( id != null && id instanceof NBTTagShort ) ((NBTTagShort) id).data = (short) this.def.item.itemID; else
|
||||
*/
|
||||
i.setShort( "id", (short) Item.itemRegistry.getIDForObject( this.def.item ) );
|
||||
|
||||
/*
|
||||
* if ( Count != null && Count instanceof NBTTagByte ) ((NBTTagByte) Count).data = (byte) 0; else
|
||||
*/
|
||||
i.setByte( "Count", (byte) 0 );
|
||||
|
||||
/*
|
||||
* if ( Cnt != null && Cnt instanceof NBTTagLong ) ((NBTTagLong) Cnt).data = this.stackSize; else
|
||||
*/
|
||||
i.setLong( "Cnt", this.stackSize );
|
||||
|
||||
/*
|
||||
* if ( Req != null && Req instanceof NBTTagLong ) ((NBTTagLong) Req).data = this.stackSize; else
|
||||
*/
|
||||
i.setLong( "Req", this.getCountRequestable() );
|
||||
|
||||
/*
|
||||
* if ( Craft != null && Craft instanceof NBTTagByte ) ((NBTTagByte) Craft).data = (byte) (this.isCraftable() ?
|
||||
* 1 : 0); else
|
||||
*/
|
||||
i.setBoolean( "Craft", this.isCraftable() );
|
||||
|
||||
/*
|
||||
* if ( Damage != null && Damage instanceof NBTTagShort ) ((NBTTagShort) Damage).data = (short)
|
||||
* this.def.damageValue; else
|
||||
*/
|
||||
i.setShort( "Damage", (short) this.def.damageValue );
|
||||
|
||||
if ( def.tagCompound != null )
|
||||
i.setTag( "tag", (NBTTagCompound) def.tagCompound );
|
||||
else
|
||||
i.removeTag( "tag" );
|
||||
|
||||
}
|
||||
|
||||
public static IAEItemStack loadItemStackFromNBT(NBTTagCompound i)
|
||||
{
|
||||
if ( i == null )
|
||||
return null;
|
||||
|
||||
ItemStack itemstack = ItemStack.loadItemStackFromNBT( i );
|
||||
if ( itemstack == null )
|
||||
return null;
|
||||
|
||||
AEItemStack aeis = AEItemStack.create( itemstack );
|
||||
// aeis.priority = i.getInteger( "Priority" );
|
||||
aeis.stackSize = i.getLong( "Cnt" );
|
||||
aeis.setCountRequestable( i.getLong( "Req" ) );
|
||||
aeis.setCraftable( i.getBoolean( "Craft" ) );
|
||||
return aeis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return def.tagCompound != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return def.myHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AEItemStack b)
|
||||
{
|
||||
int id = compare( def.item.hashCode(), b.def.item.hashCode() );
|
||||
int dv = compare( def.damageValue, b.def.damageValue );
|
||||
int dspv = compare( def.dspDamage, b.def.dspDamage );
|
||||
// AELog.info( "NBT: " + nbt );
|
||||
return id == 0 ? (dv == 0 ? (dspv == 0 ? compareNBT( b.def ) : dspv) : dv) : id;
|
||||
}
|
||||
|
||||
private int compareNBT(AEItemDef b)
|
||||
{
|
||||
int nbt = compare( (def.tagCompound == null ? 0 : def.tagCompound.getHash()), (b.tagCompound == null ? 0 : b.tagCompound.getHash()) );
|
||||
if ( nbt == 0 )
|
||||
return compare( System.identityHashCode( def.tagCompound ), System.identityHashCode( b.tagCompound ) );
|
||||
return nbt;
|
||||
}
|
||||
|
||||
private int compare(int l, long m)
|
||||
{
|
||||
return l < m ? -1 : (l > m ? 1 : 0);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List getToolTip()
|
||||
{
|
||||
if ( def.tooltip != null )
|
||||
return def.tooltip;
|
||||
|
||||
return def.tooltip = Platform.getTooltip( getItemStack() );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getDisplayName()
|
||||
{
|
||||
if ( def.displayName != null )
|
||||
return def.displayName;
|
||||
|
||||
return def.displayName = Platform.getItemDisplayName( getItemStack() );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getModID()
|
||||
{
|
||||
if ( def.uniqueID != null )
|
||||
return getModName( def.uniqueID );
|
||||
|
||||
return getModName( def.uniqueID = GameRegistry.findUniqueIdentifierFor( def.item ) );
|
||||
}
|
||||
|
||||
private String getModName(UniqueIdentifier uniqueIdentifier)
|
||||
{
|
||||
if ( uniqueIdentifier == null )
|
||||
return "** Null";
|
||||
|
||||
return uniqueIdentifier.modId == null ? "** Null" : uniqueIdentifier.modId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack empty()
|
||||
{
|
||||
IAEItemStack dup = copy();
|
||||
dup.reset();
|
||||
return dup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemDamage()
|
||||
{
|
||||
return def.damageValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeIdentity(ByteBuf i) throws IOException
|
||||
{
|
||||
i.writeShort( Item.itemRegistry.getIDForObject( def.item ) );
|
||||
i.writeShort( getItemDamage() );
|
||||
}
|
||||
|
||||
@Override
|
||||
void readNBT(ByteBuf i) throws IOException
|
||||
{
|
||||
if ( hasTagCompound() )
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
CompressedStreamTools.write( (NBTTagCompound) getTagCompound(), data );
|
||||
|
||||
byte[] tagBytes = bytes.toByteArray();
|
||||
int size = tagBytes.length;
|
||||
|
||||
i.writeInt( size );
|
||||
i.writeBytes( tagBytes );
|
||||
}
|
||||
}
|
||||
|
||||
public static IAEItemStack loadItemStackFromPacket(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();
|
||||
|
||||
d.setShort( "id", data.readShort() );
|
||||
d.setShort( "Damage", data.readShort() );
|
||||
d.setByte( "Count", (byte) 0 );
|
||||
|
||||
if ( hasTagCompound )
|
||||
{
|
||||
int len = data.readInt();
|
||||
|
||||
byte[] bd = new byte[len];
|
||||
data.readBytes( bd );
|
||||
|
||||
ByteArrayInputStream di = new ByteArrayInputStream( bd );
|
||||
d.setTag( "tag", CompressedStreamTools.read( new DataInputStream( di ) ) );
|
||||
}
|
||||
|
||||
// long priority = getPacketValue( PriorityType, data );
|
||||
long stackSize = getPacketValue( StackType, data );
|
||||
long countRequestable = getPacketValue( CountReqType, data );
|
||||
|
||||
ItemStack itemstack = ItemStack.loadItemStackFromNBT( d );
|
||||
if ( itemstack == null )
|
||||
return null;
|
||||
|
||||
AEItemStack aeis = AEItemStack.create( itemstack );
|
||||
// aeis.priority = (int) priority;
|
||||
aeis.stackSize = stackSize;
|
||||
aeis.setCountRequestable( countRequestable );
|
||||
aeis.setCraftable( isCraftable );
|
||||
return aeis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameOre(IAEItemStack is)
|
||||
{
|
||||
return OreHelper.instance.sameOre( this, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fuzzyComparison(Object st, FuzzyMode Mode)
|
||||
{
|
||||
if ( st instanceof IAEItemStack )
|
||||
{
|
||||
IAEItemStack o = (IAEItemStack) st;
|
||||
|
||||
if ( sameOre( o ) )
|
||||
return true;
|
||||
|
||||
if ( o.getItem() == getItem() )
|
||||
{
|
||||
if ( def.item.isDamageable() )
|
||||
{
|
||||
ItemStack a = getItemStack();
|
||||
ItemStack b = o.getItemStack();
|
||||
|
||||
try
|
||||
{
|
||||
if ( Mode == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( Mode == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
return (a.getItemDamageForDisplay() > 1) == (b.getItemDamageForDisplay() > 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
float APercentDamaged = 1.0f - (float) a.getItemDamageForDisplay() / (float) a.getMaxDamage();
|
||||
float BPercentDamaged = 1.0f - (float) b.getItemDamageForDisplay() / (float) b.getMaxDamage();
|
||||
|
||||
return (APercentDamaged > Mode.breakPoint) == (BPercentDamaged > Mode.breakPoint);
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
if ( Mode == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( Mode == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
return (a.getItemDamage() > 1) == (b.getItemDamage() > 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
float APercentDamaged = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
||||
float BPercentDamaged = (float) b.getItemDamage() / (float) b.getMaxDamage();
|
||||
|
||||
return (APercentDamaged > Mode.breakPoint) == (BPercentDamaged > Mode.breakPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.getItemDamage() == o.getItemDamage();
|
||||
}
|
||||
}
|
||||
|
||||
if ( st instanceof ItemStack )
|
||||
{
|
||||
ItemStack o = (ItemStack) st;
|
||||
|
||||
OreHelper.instance.sameOre( this, o );
|
||||
|
||||
if ( o.getItem() == getItem() )
|
||||
{
|
||||
if ( def.item.isDamageable() )
|
||||
{
|
||||
ItemStack a = getItemStack();
|
||||
ItemStack b = o;
|
||||
|
||||
try
|
||||
{
|
||||
if ( Mode == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( Mode == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
return (a.getItemDamageForDisplay() > 1) == (b.getItemDamageForDisplay() > 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
float APercentDamaged = 1.0f - (float) a.getItemDamageForDisplay() / (float) a.getMaxDamage();
|
||||
float BPercentDamaged = 1.0f - (float) b.getItemDamageForDisplay() / (float) b.getMaxDamage();
|
||||
|
||||
return (APercentDamaged > Mode.breakPoint) == (BPercentDamaged > Mode.breakPoint);
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
if ( Mode == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( Mode == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
return (a.getItemDamage() > 1) == (b.getItemDamage() > 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
float APercentDamaged = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
||||
float BPercentDamaged = (float) b.getItemDamage() / (float) b.getMaxDamage();
|
||||
|
||||
return (APercentDamaged > Mode.breakPoint) == (BPercentDamaged > Mode.breakPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.getItemDamage() == o.getItemDamage();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public IAEItemStack getLow(FuzzyMode fuzzy, boolean ignoreMeta)
|
||||
{
|
||||
AEItemStack bottom = new AEItemStack( this );
|
||||
AEItemDef newDef = bottom.def = bottom.def.copy();
|
||||
|
||||
if ( ignoreMeta )
|
||||
{
|
||||
newDef.dspDamage = newDef.damageValue = 0;
|
||||
newDef.reHash();
|
||||
return bottom;
|
||||
}
|
||||
|
||||
if ( newDef.item.isDamageable() )
|
||||
{
|
||||
if ( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
newDef.dspDamage = 0;
|
||||
}
|
||||
else if ( fuzzy == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
if ( def.damageValue == 0 )
|
||||
newDef.dspDamage = 0;
|
||||
else
|
||||
newDef.dspDamage = 1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
int breakpoint = fuzzy.calculateBreakPoint( def.maxDamage );
|
||||
newDef.dspDamage = breakpoint <= def.dspDamage ? breakpoint : 0;
|
||||
}
|
||||
|
||||
newDef.damageValue = newDef.dspDamage;
|
||||
}
|
||||
|
||||
newDef.tagCompound = AEItemDef.lowTag;
|
||||
newDef.reHash();
|
||||
return bottom;
|
||||
}
|
||||
|
||||
public IAEItemStack getHigh(FuzzyMode fuzzy, boolean ignoreMeta)
|
||||
{
|
||||
AEItemStack top = new AEItemStack( this );
|
||||
AEItemDef newDef = top.def = top.def.copy();
|
||||
|
||||
if ( ignoreMeta )
|
||||
{
|
||||
newDef.dspDamage = newDef.damageValue = Integer.MAX_VALUE;
|
||||
newDef.reHash();
|
||||
return top;
|
||||
}
|
||||
|
||||
if ( newDef.item.isDamageable() )
|
||||
{
|
||||
if ( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
newDef.dspDamage = def.maxDamage + 1;
|
||||
}
|
||||
else if ( fuzzy == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
if ( def.damageValue == 0 )
|
||||
newDef.dspDamage = 0;
|
||||
else
|
||||
newDef.dspDamage = def.maxDamage + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int breakpoint = fuzzy.calculateBreakPoint( def.maxDamage );
|
||||
newDef.dspDamage = def.dspDamage < breakpoint ? breakpoint - 1 : def.maxDamage + 1;
|
||||
}
|
||||
|
||||
newDef.damageValue = newDef.dspDamage;
|
||||
}
|
||||
|
||||
newDef.tagCompound = AEItemDef.highTag;
|
||||
newDef.reHash();
|
||||
return top;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAETagCompound getTagCompound()
|
||||
{
|
||||
return def.tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(IAEItemStack otherStack)
|
||||
{
|
||||
if ( otherStack == null )
|
||||
return false;
|
||||
|
||||
return def.equals( ((AEItemStack) otherStack).def );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(ItemStack otherStack)
|
||||
{
|
||||
if ( otherStack == null )
|
||||
return false;
|
||||
|
||||
return def.isItem( otherStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItem()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
public boolean isOre()
|
||||
{
|
||||
return def.isOre != null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Iterator;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.AEApi;
|
||||
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
|
||||
{
|
||||
|
||||
private Item item;
|
||||
private int meta, hash;
|
||||
public SharedSearchObject sso;
|
||||
private IItemComparison comp;
|
||||
|
||||
public int getHash()
|
||||
{
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemComparison getSpecialComparison()
|
||||
{
|
||||
return comp;
|
||||
}
|
||||
|
||||
private AESharedNBT(Item itemID, int damageValue) {
|
||||
super();
|
||||
item = itemID;
|
||||
meta = damageValue;
|
||||
}
|
||||
|
||||
public AESharedNBT(int fakeValue) {
|
||||
super();
|
||||
item = null;
|
||||
meta = 0;
|
||||
hash = fakeValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTTagCompoundCopy()
|
||||
{
|
||||
return (NBTTagCompound) copy();
|
||||
}
|
||||
|
||||
public static AESharedNBT createFromCompound(Item itemID, int damageValue, NBTTagCompound c)
|
||||
{
|
||||
AESharedNBT x = new AESharedNBT( itemID, damageValue );
|
||||
|
||||
// c.getTags()
|
||||
Iterator var2 = c.func_150296_c().iterator();
|
||||
|
||||
while (var2.hasNext())
|
||||
{
|
||||
String name = (String) var2.next();
|
||||
x.setTag( name, c.getTag( name ).copy() );
|
||||
}
|
||||
|
||||
x.hash = Platform.NBTOrderlessHash( c );
|
||||
|
||||
ItemStack isc = new ItemStack( itemID, 1, damageValue );
|
||||
isc.setTagCompound( c );
|
||||
x.comp = AEApi.instance().registries().specialComparison().getSpecialComparison( isc );
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object par1Obj)
|
||||
{
|
||||
if ( par1Obj instanceof AESharedNBT )
|
||||
return this == par1Obj;
|
||||
return super.equals( par1Obj );
|
||||
}
|
||||
|
||||
public boolean matches(Item itemid2, int meta2, int orderlessHash)
|
||||
{
|
||||
return itemid2 == item && meta == meta2 && hash == orderlessHash;
|
||||
}
|
||||
|
||||
public boolean comparePreciseWithRegistry(AESharedNBT tagCompound)
|
||||
{
|
||||
if ( this == tagCompound )
|
||||
return true;
|
||||
|
||||
if ( comp != null && tagCompound.comp != null )
|
||||
{
|
||||
return comp.sameAsPrecise( tagCompound.comp );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean compareFuzzyWithRegistry(AESharedNBT tagCompound)
|
||||
{
|
||||
if ( this == tagCompound )
|
||||
return true;
|
||||
if ( tagCompound == null )
|
||||
return false;
|
||||
|
||||
if ( comp == tagCompound.comp )
|
||||
return true;
|
||||
|
||||
if ( comp != null )
|
||||
{
|
||||
return comp.sameAsFuzzy( tagCompound.comp );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Shared Tag Compound Cache.
|
||||
*/
|
||||
private static WeakHashMap<SharedSearchObject, WeakReference<SharedSearchObject>> sharedTagCompounds = new WeakHashMap();
|
||||
|
||||
/*
|
||||
* Debug purposes.
|
||||
*/
|
||||
public static int sharedTagLoad()
|
||||
{
|
||||
return sharedTagCompounds.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 itemid = 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( itemid, meta, tagCompound );
|
||||
|
||||
WeakReference<SharedSearchObject> c = sharedTagCompounds.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( itemid, meta, tagCompound );
|
||||
sso.compound = (NBTTagCompound) sso.compound.copy(); // prevent
|
||||
// modification
|
||||
// of data based
|
||||
// on original
|
||||
// item.
|
||||
sso.shared = clone;
|
||||
clone.sso = sso;
|
||||
|
||||
sharedTagCompounds.put( sso, new WeakReference<SharedSearchObject>( sso ) );
|
||||
return clone;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public abstract class AEStack<StackType extends IAEStack> implements IAEStack<StackType>
|
||||
{
|
||||
|
||||
protected boolean isCraftable;
|
||||
protected long stackSize;
|
||||
protected long countRequestable;
|
||||
|
||||
@Override
|
||||
public boolean isMeaningful()
|
||||
{
|
||||
return stackSize != 0 || getCountRequestable() > 0 || isCraftable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType reset()
|
||||
{
|
||||
stackSize = 0;
|
||||
// priority = Integer.MIN_VALUE;
|
||||
setCountRequestable( 0 );
|
||||
setCraftable( false );
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStackSize()
|
||||
{
|
||||
return stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setStackSize(long ss)
|
||||
{
|
||||
stackSize = ss;
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCountRequestable()
|
||||
{
|
||||
return countRequestable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setCountRequestable(long countRequestable)
|
||||
{
|
||||
this.countRequestable = countRequestable;
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftable()
|
||||
{
|
||||
return isCraftable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setCraftable(boolean isCraftable)
|
||||
{
|
||||
this.isCraftable = isCraftable;
|
||||
return (StackType) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decStackSize(long i)
|
||||
{
|
||||
stackSize -= i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incStackSize(long i)
|
||||
{
|
||||
stackSize += i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decCountRequestable(long i)
|
||||
{
|
||||
countRequestable -= i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incCountRequestable(long i)
|
||||
{
|
||||
countRequestable += i;
|
||||
}
|
||||
|
||||
void putPacketValue(ByteBuf tag, long num) throws IOException
|
||||
{
|
||||
if ( num <= 255 )
|
||||
tag.writeByte( (byte) (num + (long) Byte.MIN_VALUE) );
|
||||
else if ( num <= 65535 )
|
||||
tag.writeShort( (short) (num + (long) Short.MIN_VALUE) );
|
||||
else if ( num <= 4294967295L )
|
||||
tag.writeInt( (int) (num + (long) Integer.MIN_VALUE) );
|
||||
else
|
||||
tag.writeLong( num );
|
||||
}
|
||||
|
||||
static long getPacketValue(byte type, ByteBuf tag) throws IOException
|
||||
{
|
||||
if ( type == 0 )
|
||||
{
|
||||
long l = tag.readByte();
|
||||
l -= (long) Byte.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if ( type == 1 )
|
||||
{
|
||||
long l = tag.readShort();
|
||||
l -= (long) Short.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if ( type == 2 )
|
||||
{
|
||||
long l = tag.readInt();
|
||||
l -= (long) 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) (getType( 0 ) | (getType( stackSize ) << 2) | (getType( getCountRequestable() ) << 4) | ((byte) (isCraftable ? 1 : 0) << 6) | (hasTagCompound() ? 1
|
||||
: 0) << 7);
|
||||
|
||||
i.writeByte( mask );
|
||||
writeIdentity( i );
|
||||
|
||||
readNBT( i );
|
||||
|
||||
// putPacketValue( i, priority );
|
||||
putPacketValue( i, stackSize );
|
||||
putPacketValue( i, getCountRequestable() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public final class ItemList<StackType extends IAEStack> implements IItemList<StackType>
|
||||
{
|
||||
|
||||
private final TreeMap<StackType, StackType> records = new TreeMap();
|
||||
private final Class<? extends IAEStack> clz;
|
||||
|
||||
// private int currentPriority = Integer.MIN_VALUE;
|
||||
|
||||
int iteration = Integer.MIN_VALUE;
|
||||
public Throwable stacktrace;
|
||||
|
||||
public ItemList(Class<? extends IAEStack> cla) {
|
||||
clz = cla;
|
||||
}
|
||||
|
||||
private boolean checkStackType(StackType st)
|
||||
{
|
||||
if ( st == null )
|
||||
return true;
|
||||
|
||||
if ( !clz.isInstance( st ) )
|
||||
throw new RuntimeException( "WRONG TYPE - got " + st.getClass().getName() + " expected " + clz.getName() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void add(StackType option)
|
||||
{
|
||||
if ( checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
st.add( option );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
records.put( opt, opt );
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void addStorage(StackType option) // adds a stack as
|
||||
// stored.
|
||||
{
|
||||
if ( checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
st.incStackSize( option.getStackSize() );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
records.put( opt, opt );
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void addCrafting(StackType option) // adds a stack as
|
||||
// craftable.
|
||||
{
|
||||
if ( checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
st.setCraftable( true );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( true );
|
||||
|
||||
records.put( opt, opt );
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void addRequestable(StackType option) // adds a stack
|
||||
// as
|
||||
// requestable.
|
||||
{
|
||||
if ( checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
((IAEItemStack) st).setCountRequestable( ((IAEItemStack) st).getCountRequestable() + ((IAEItemStack) option).getCountRequestable() );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( false );
|
||||
opt.setCountRequestable( opt.getCountRequestable() );
|
||||
|
||||
records.put( opt, opt );
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public StackType getFirstItem()
|
||||
{
|
||||
Iterator<StackType> i = this.iterator();
|
||||
while (i.hasNext())
|
||||
return i.next();
|
||||
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 iterator()
|
||||
{
|
||||
return new MeaningfulIterator( records.values().iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public StackType findPrecise(StackType i)
|
||||
{
|
||||
if ( checkStackType( i ) )
|
||||
return null;
|
||||
|
||||
StackType is = records.get( i );
|
||||
if ( is != null )
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public int size()
|
||||
{
|
||||
return records.values().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !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 records.subMap( low, true, high, true ).descendingMap().values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StackType> findFuzzy(StackType filter, FuzzyMode fuzzy)
|
||||
{
|
||||
if ( checkStackType( filter ) )
|
||||
return new ArrayList();
|
||||
|
||||
if ( filter instanceof IAEFluidStack )
|
||||
return filter.equals( this ) ? (List<StackType>) Arrays.asList( new IAEFluidStack[] { (IAEFluidStack) filter } ) : (List<StackType>) Arrays
|
||||
.asList( new IAEFluidStack[] {} );
|
||||
|
||||
AEItemStack ais = (AEItemStack) filter;
|
||||
if ( ais.isOre() )
|
||||
{
|
||||
OreReference or = ais.def.isOre;
|
||||
if ( or.getAEEquivalents().size() == 1 )
|
||||
{
|
||||
IAEItemStack is = or.getAEEquivalents().get( 0 );
|
||||
return findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<StackType> output = new LinkedList();
|
||||
|
||||
for (IAEItemStack is : or.getAEEquivalents())
|
||||
output.addAll( findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return findFuzzyDamage( ais, fuzzy, false );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
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) {
|
||||
backingStore = backend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(IAEItemStack option)
|
||||
{
|
||||
IAEItemStack over = overrides.findPrecise( option );
|
||||
if ( over == null )
|
||||
{
|
||||
over = backingStore.findPrecise( option );
|
||||
if ( over == null )
|
||||
overrides.add( option );
|
||||
else
|
||||
{
|
||||
option.add( over );
|
||||
overrides.add( option );
|
||||
}
|
||||
}
|
||||
else
|
||||
overrides.add( option );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise(IAEItemStack i)
|
||||
{
|
||||
IAEItemStack over = overrides.findPrecise( i );
|
||||
if ( over == null )
|
||||
return backingStore.findPrecise( i );
|
||||
return over;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(IAEItemStack input, FuzzyMode fuzzy)
|
||||
{
|
||||
return overrides.findFuzzy( input, fuzzy );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return overrides.isEmpty() && backingStore.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public class MeaningfulIterator<StackType extends IAEStack> implements Iterator
|
||||
{
|
||||
|
||||
final Iterator<StackType> parent;
|
||||
private StackType next;
|
||||
|
||||
public MeaningfulIterator(Iterator<StackType> iterator) {
|
||||
parent = iterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
while (parent.hasNext())
|
||||
{
|
||||
next = parent.next();
|
||||
if ( next.isMeaningful() )
|
||||
return true;
|
||||
else
|
||||
parent.remove(); // self cleaning :3
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object next()
|
||||
{
|
||||
return next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
parent.remove();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public class OreHelper
|
||||
{
|
||||
|
||||
public static OreHelper instance = new OreHelper();
|
||||
|
||||
class ItemRef
|
||||
{
|
||||
|
||||
ItemRef(ItemStack stack) {
|
||||
ref = stack.getItem();
|
||||
|
||||
if ( stack.getItem().isDamageable() )
|
||||
damage = 0; // IGNORED
|
||||
else
|
||||
damage = stack.getItemDamage(); // might be important...
|
||||
|
||||
hash = ref.hashCode() ^ damage;
|
||||
}
|
||||
|
||||
Item ref;
|
||||
int damage;
|
||||
int hash;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
ItemRef obj = (ItemRef) o;
|
||||
return damage == obj.damage && ref == obj.ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return hash;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class OreResult
|
||||
{
|
||||
|
||||
public OreReference oreValue = null;
|
||||
|
||||
};
|
||||
|
||||
HashMap<ItemRef, OreResult> references = new HashMap();
|
||||
|
||||
public OreReference isOre(ItemStack ItemStack)
|
||||
{
|
||||
ItemRef ir = new ItemRef( ItemStack );
|
||||
OreResult or = references.get( ir );
|
||||
|
||||
if ( or == null )
|
||||
{
|
||||
or = new OreResult();
|
||||
references.put( ir, or );
|
||||
|
||||
OreReference ref = new OreReference();
|
||||
Collection<Integer> ores = ref.getOres();
|
||||
Collection<ItemStack> set = ref.getEquivalents();
|
||||
|
||||
for (String ore : OreDictionary.getOreNames())
|
||||
{
|
||||
boolean add = false;
|
||||
|
||||
for (ItemStack oreItem : OreDictionary.getOres( ore ))
|
||||
{
|
||||
if ( OreDictionary.itemMatches( oreItem, ItemStack, false ) )
|
||||
{
|
||||
add = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( add )
|
||||
{
|
||||
for (ItemStack oreItem : OreDictionary.getOres( ore ))
|
||||
set.add( oreItem.copy() );
|
||||
|
||||
ores.add( OreDictionary.getOreID( ore ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !set.isEmpty() )
|
||||
or.oreValue = ref;
|
||||
}
|
||||
|
||||
return or.oreValue;
|
||||
}
|
||||
|
||||
public boolean sameOre(AEItemStack aeItemStack, IAEItemStack is)
|
||||
{
|
||||
OreReference a = aeItemStack.def.isOre;
|
||||
OreReference b = ((AEItemStack) aeItemStack).def.isOre;
|
||||
|
||||
if ( a == b )
|
||||
return true;
|
||||
|
||||
if ( a == null || b == null )
|
||||
return false;
|
||||
|
||||
Collection<Integer> bOres = b.getOres();
|
||||
for (Integer ore : a.getOres())
|
||||
{
|
||||
if ( bOres.contains( ore ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean sameOre(OreReference a, OreReference b)
|
||||
{
|
||||
if ( a == null || b == null )
|
||||
return false;
|
||||
|
||||
if ( a == b )
|
||||
return true;
|
||||
|
||||
Collection<Integer> bOres = b.getOres();
|
||||
for (Integer ore : a.getOres())
|
||||
{
|
||||
if ( bOres.contains( ore ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean sameOre(AEItemStack aeItemStack, ItemStack o)
|
||||
{
|
||||
OreReference a = aeItemStack.def.isOre;
|
||||
if ( a == null )
|
||||
return false;
|
||||
|
||||
for (ItemStack oreItem : a.getEquivalents())
|
||||
{
|
||||
if ( OreDictionary.itemMatches( oreItem, o, false ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public class OreReference
|
||||
{
|
||||
|
||||
private LinkedList<ItemStack> otherOptions = new LinkedList();
|
||||
private ArrayList aeotherOptions = null;
|
||||
private HashSet<Integer> ores = new HashSet<Integer>();
|
||||
|
||||
public Collection<ItemStack> getEquivalents()
|
||||
{
|
||||
return otherOptions;
|
||||
}
|
||||
|
||||
public List<IAEItemStack> getAEEquivalents()
|
||||
{
|
||||
if ( aeotherOptions == null )
|
||||
{
|
||||
aeotherOptions = new ArrayList( otherOptions.size() );
|
||||
|
||||
// SUMMON AE STACKS!
|
||||
for (ItemStack is : otherOptions)
|
||||
if ( is.getItem() != null )
|
||||
aeotherOptions.add( AEItemStack.create( is ) );
|
||||
}
|
||||
|
||||
return aeotherOptions;
|
||||
}
|
||||
|
||||
public Collection<Integer> getOres()
|
||||
{
|
||||
return ores;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package appeng.util.item;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class SharedSearchObject
|
||||
{
|
||||
|
||||
int def;
|
||||
int hash;
|
||||
NBTTagCompound compound;
|
||||
public AESharedNBT shared;
|
||||
|
||||
public SharedSearchObject(Item itemID, int damageValue, NBTTagCompound tagCompound) {
|
||||
def = (damageValue << Platform.DEF_OFFSET) | Item.itemRegistry.getIDForObject( itemID );
|
||||
hash = Platform.NBTOrderlessHash( tagCompound );
|
||||
compound = tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if ( obj == null )
|
||||
return false;
|
||||
SharedSearchObject b = (SharedSearchObject) obj;
|
||||
if ( def == b.def && hash == b.hash )
|
||||
{
|
||||
return Platform.NBTEqualityTest( compound, b.compound );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return def ^ hash;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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>
|
||||
{
|
||||
|
||||
final AppEngInternalAEInventory inv;
|
||||
final int size;
|
||||
|
||||
int x = 0;
|
||||
|
||||
public AEInvIterator(AppEngInternalAEInventory i) {
|
||||
inv = i;
|
||||
size = inv.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return x < size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack next()
|
||||
{
|
||||
return inv.getAEStackInSlot( x++ );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new RuntimeException( "no..." );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package appeng.util.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ChainedIterator<T> implements Iterator<T>
|
||||
{
|
||||
|
||||
int offset = 0;
|
||||
T[] list;
|
||||
|
||||
public ChainedIterator(T... list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return offset < list.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next()
|
||||
{
|
||||
return list[offset++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new RuntimeException( "Not implemented." );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package appeng.util.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InvIterator implements Iterator<ItemStack>
|
||||
{
|
||||
|
||||
final IInventory inv;
|
||||
final int size;
|
||||
|
||||
int x = 0;
|
||||
|
||||
public InvIterator(IInventory i) {
|
||||
inv = i;
|
||||
size = inv.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return x < size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack next()
|
||||
{
|
||||
return inv.getStackInSlot( x++ );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new RuntimeException( "no..." );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package appeng.util.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class NullIterator<T> implements Iterator<T>
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package appeng.util.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
|
||||
public class ProxyNodeIterator implements Iterator<IGridNode>
|
||||
{
|
||||
|
||||
Iterator<IGridHost> hosts;
|
||||
|
||||
public ProxyNodeIterator(Iterator<IGridHost> hosts) {
|
||||
this.hosts = hosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return hosts.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode next()
|
||||
{
|
||||
IGridHost host = hosts.next();
|
||||
return host.getGridNode( ForgeDirection.UNKNOWN );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new RuntimeException( "Not implemented." );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
|
||||
public StackToSlotIterator(Iterator<ItemStack> is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return is.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
iss.slot = x++;
|
||||
iss.setItemStack( is.next() );
|
||||
return iss;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
// uhh no.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
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 nullList = new ArrayList();
|
||||
|
||||
public boolean isListed(T input)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
return (Iterable<T>) nullList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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) {
|
||||
list = in;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public boolean isListed(T input)
|
||||
{
|
||||
Collection<T> out = list.findFuzzy( input, mode );
|
||||
return out != null && !out.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return list.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package appeng.util.prioitylist;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public interface IPartitionList<T extends IAEStack<T>>
|
||||
{
|
||||
|
||||
boolean isListed(T input);
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
Iterable<T> getItems();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
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();
|
||||
final List<IPartitionList<T>> negative = new ArrayList();
|
||||
|
||||
public void addNewList(IPartitionList<T> list, boolean isWhitelist)
|
||||
{
|
||||
if ( isWhitelist )
|
||||
positive.add( list );
|
||||
else
|
||||
negative.add( list );
|
||||
}
|
||||
|
||||
public boolean isListed(T input)
|
||||
{
|
||||
for (IPartitionList<T> l : negative)
|
||||
if ( l.isListed( input ) )
|
||||
return false;
|
||||
|
||||
if ( !positive.isEmpty() )
|
||||
{
|
||||
for (IPartitionList<T> l : positive)
|
||||
if ( l.isListed( input ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return positive.isEmpty() && negative.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
throw new RuntimeException( "Not Implemented" );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
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) {
|
||||
list = in;
|
||||
}
|
||||
|
||||
public boolean isListed(T input)
|
||||
{
|
||||
return list.findPrecise( input ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return list.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user