Inventory Util Upgrades.
This commit is contained in:
parent
d7337aeb6b
commit
978745238f
3 changed files with 57 additions and 2 deletions
|
@ -13,6 +13,7 @@ import appeng.util.Platform;
|
|||
public class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
|
||||
{
|
||||
|
||||
private boolean cached = false;
|
||||
private int FuzzyUpgrades = 0;
|
||||
private int SpeedUpgrades = 0;
|
||||
private int RedstoneUpgrades = 0;
|
||||
|
@ -32,6 +33,12 @@ public class UpgradeInventory extends AppEngInternalInventory implements IAEAppE
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack newItemStack)
|
||||
{
|
||||
super.setInventorySlotContents( slot, newItemStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
|
@ -51,6 +58,7 @@ public class UpgradeInventory extends AppEngInternalInventory implements IAEAppE
|
|||
|
||||
private void updateUpgradeInfo()
|
||||
{
|
||||
cached = true;
|
||||
CapacityUpgrades = RedstoneUpgrades = SpeedUpgrades = FuzzyUpgrades = 0;
|
||||
|
||||
for (ItemStack is : this)
|
||||
|
@ -86,6 +94,9 @@ public class UpgradeInventory extends AppEngInternalInventory implements IAEAppE
|
|||
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
{
|
||||
if ( !cached )
|
||||
updateUpgradeInfo();
|
||||
|
||||
switch (u)
|
||||
{
|
||||
case CAPACITY:
|
||||
|
@ -104,8 +115,7 @@ public class UpgradeInventory extends AppEngInternalInventory implements IAEAppE
|
|||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
updateUpgradeInfo();
|
||||
|
||||
cached = false;
|
||||
if ( parent != null && Platform.isServer() )
|
||||
parent.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import appeng.api.AEApi;
|
|||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import appeng.util.iterators.AEInvIterator;
|
||||
import appeng.util.iterators.InvIterator;
|
||||
|
||||
public class AppEngInternalAEInventory implements IInventory, Iterable<ItemStack>
|
||||
|
@ -237,4 +238,9 @@ public class AppEngInternalAEInventory implements IInventory, Iterable<ItemStack
|
|||
{
|
||||
return new InvIterator( this );
|
||||
}
|
||||
|
||||
public Iterator<IAEItemStack> aeiterator()
|
||||
{
|
||||
return new AEInvIterator( this );
|
||||
}
|
||||
}
|
||||
|
|
39
util/iterators/AEInvIterator.java
Normal file
39
util/iterators/AEInvIterator.java
Normal file
|
@ -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..." );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue