Search in sources :

Example 1 with IItemStorageChannel

use of appeng.api.storage.channels.IItemStorageChannel in project LogisticsPipes by RS485.

the class LPActionSource method add.

@Override
@Nonnull
public ItemStack add(@Nonnull ItemStack stack, EnumFacing from, boolean doAdd) {
    ItemStack st = stack.copy();
    IItemStorageChannel channel = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
    IAEItemStack tst = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(stack);
    IStorageMonitorable tmp = acc.getInventory(source);
    if (tmp == null || tmp.getInventory(channel) == null) {
        return st;
    }
    IAEItemStack overflow = tmp.getInventory(channel).injectItems(tst, Actionable.MODULATE, source);
    if (overflow != null) {
        st.setCount((int) (st.getCount() - overflow.getStackSize()));
    }
    return st;
}
Also used : IAEItemStack(appeng.api.storage.data.IAEItemStack) IItemStorageChannel(appeng.api.storage.channels.IItemStorageChannel) ItemStack(net.minecraft.item.ItemStack) IAEItemStack(appeng.api.storage.data.IAEItemStack) IStorageMonitorable(appeng.api.storage.IStorageMonitorable) Nonnull(javax.annotation.Nonnull)

Example 2 with IItemStorageChannel

use of appeng.api.storage.channels.IItemStorageChannel in project LogisticsPipes by RS485.

the class LPActionSource method roomForItem.

@Override
public int roomForItem(@Nonnull ItemStack itemStack) {
    IItemStorageChannel channel = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
    IStorageMonitorable tmp = acc.getInventory(source);
    if (tmp == null || tmp.getInventory(channel) == null) {
        return 0;
    }
    IAEItemStack stack = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(itemStack);
    if (stack == null)
        return 0;
    while (stack.getStackSize() > 0) {
        if (tmp.getInventory(channel).canAccept(stack)) {
            return stack.getStackSize() > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) stack.getStackSize();
        }
        stack.decStackSize(1);
    }
    return 0;
}
Also used : IAEItemStack(appeng.api.storage.data.IAEItemStack) IItemStorageChannel(appeng.api.storage.channels.IItemStorageChannel) IStorageMonitorable(appeng.api.storage.IStorageMonitorable)

Example 3 with IItemStorageChannel

use of appeng.api.storage.channels.IItemStorageChannel in project LogisticsPipes by RS485.

the class LPActionSource method getMultipleItems.

@Override
@Nonnull
public ItemStack getMultipleItems(@Nonnull ItemIdentifier itemIdent, int count) {
    if (itemCount(itemIdent) < count) {
        return ItemStack.EMPTY;
    }
    IItemStorageChannel channel = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
    IStorageMonitorable tmp = acc.getInventory(source);
    if (tmp == null || tmp.getInventory(channel) == null) {
        return ItemStack.EMPTY;
    }
    IAEItemStack stack = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(itemIdent.makeNormalStack(count));
    IAEItemStack extract = tmp.getInventory(channel).extractItems(stack, Actionable.MODULATE, source);
    if (extract == null) {
        return ItemStack.EMPTY;
    }
    return extract.createItemStack();
}
Also used : IAEItemStack(appeng.api.storage.data.IAEItemStack) IItemStorageChannel(appeng.api.storage.channels.IItemStorageChannel) IStorageMonitorable(appeng.api.storage.IStorageMonitorable) Nonnull(javax.annotation.Nonnull)

Example 4 with IItemStorageChannel

use of appeng.api.storage.channels.IItemStorageChannel in project LogisticsPipes by RS485.

the class LPActionSource method getSingleItem.

@Override
@Nonnull
public ItemStack getSingleItem(ItemIdentifier item) {
    IItemStorageChannel channel = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
    IStorageMonitorable tmp = acc.getInventory(source);
    if (tmp == null || tmp.getInventory(channel) == null) {
        return ItemStack.EMPTY;
    }
    IAEItemStack stack = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(item.makeNormalStack(1));
    IAEItemStack extract = tmp.getInventory(channel).extractItems(stack, Actionable.MODULATE, source);
    if (extract == null) {
        return ItemStack.EMPTY;
    }
    return extract.createItemStack();
}
Also used : IAEItemStack(appeng.api.storage.data.IAEItemStack) IItemStorageChannel(appeng.api.storage.channels.IItemStorageChannel) IStorageMonitorable(appeng.api.storage.IStorageMonitorable) Nonnull(javax.annotation.Nonnull)

Example 5 with IItemStorageChannel

use of appeng.api.storage.channels.IItemStorageChannel in project LogisticsPipes by RS485.

the class LPActionSource method containsUndamagedItem.

@Override
public boolean containsUndamagedItem(@Nonnull ItemIdentifier itemIdent) {
    IItemStorageChannel channel = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
    IStorageMonitorable tmp = acc.getInventory(source);
    if (tmp == null || tmp.getInventory(channel) == null || tmp.getInventory(channel).getStorageList() == null) {
        return false;
    }
    IItemList<IAEItemStack> items = tmp.getInventory(channel).getStorageList();
    for (IAEItemStack item : items) {
        ItemIdentifier ident = ItemIdentifier.get(item.createItemStack());
        if (ident.equals(itemIdent)) {
            return true;
        }
    }
    return false;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IAEItemStack(appeng.api.storage.data.IAEItemStack) IItemStorageChannel(appeng.api.storage.channels.IItemStorageChannel) IStorageMonitorable(appeng.api.storage.IStorageMonitorable)

Aggregations

IStorageMonitorable (appeng.api.storage.IStorageMonitorable)7 IItemStorageChannel (appeng.api.storage.channels.IItemStorageChannel)7 IAEItemStack (appeng.api.storage.data.IAEItemStack)7 Nonnull (javax.annotation.Nonnull)4 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)3 TreeSet (java.util.TreeSet)1 ItemStack (net.minecraft.item.ItemStack)1