use of mcjty.rftools.api.storage.IStorageScanner in project XNet by McJty.
the class RFToolsSupport method tickStorageScanner.
public static void tickStorageScanner(IControllerContext context, ItemConnectorSettings settings, TileEntity te, ItemChannelSettings channelSettings) {
IStorageScanner scanner = (IStorageScanner) te;
Predicate<ItemStack> extractMatcher = settings.getMatcher();
Integer count = settings.getCount();
int amount = 0;
if (count != null) {
amount = scanner.countItems(extractMatcher, true, count);
if (amount < count) {
return;
}
}
ItemStack stack = scanner.requestItem(extractMatcher, true, settings.getStackMode() == ItemConnectorSettings.StackMode.STACK ? 64 : 1, true);
if (!stack.isEmpty()) {
// Now that we have a stack we first reduce the amount of the stack if we want to keep a certain
// number of items
int toextract = stack.getCount();
if (count != null) {
int canextract = amount - count;
if (canextract <= 0) {
return;
}
if (canextract < toextract) {
toextract = canextract;
if (toextract <= 0) {
stack.setCount(0);
} else {
stack.setCount(toextract);
}
}
}
List<Pair<SidedConsumer, ItemConnectorSettings>> inserted = new ArrayList<>();
int remaining = channelSettings.insertStackSimulate(inserted, context, stack);
if (!inserted.isEmpty()) {
if (context.checkAndConsumeRF(GeneralConfiguration.controllerOperationRFT)) {
channelSettings.insertStackReal(context, inserted, scanner.requestItem(extractMatcher, false, toextract - remaining, true));
}
}
}
}
use of mcjty.rftools.api.storage.IStorageScanner in project RFToolsControl by McJty.
the class ProcessorTileEntity method getStorageScanner.
private IStorageScanner getStorageScanner() {
int card = getStorageCard();
if (card == -1) {
throw new ProgException(EXCEPT_MISSINGSTORAGECARD);
}
ItemStack storageStack = getStackInSlot(card);
if (!storageStack.hasTagCompound()) {
throw new ProgException(EXCEPT_MISSINGSTORAGECARD);
}
NBTTagCompound tagCompound = storageStack.getTagCompound();
BlockPos c = new BlockPos(tagCompound.getInteger("monitorx"), tagCompound.getInteger("monitory"), tagCompound.getInteger("monitorz"));
int dim = tagCompound.getInteger("monitordim");
World world = DimensionManager.getWorld(dim);
if (world == null) {
throw new ProgException(EXCEPT_MISSINGSTORAGE);
}
if (!WorldTools.chunkLoaded(world, c)) {
throw new ProgException(EXCEPT_MISSINGSTORAGE);
}
TileEntity te = world.getTileEntity(c);
if (te == null) {
throw new ProgException(EXCEPT_MISSINGSTORAGE);
}
if (!(te instanceof IStorageScanner)) {
throw new ProgException(EXCEPT_MISSINGSTORAGE);
}
return (IStorageScanner) te;
}
use of mcjty.rftools.api.storage.IStorageScanner in project RFToolsControl by McJty.
the class ProcessorTileEntity method getIngredientsSmart.
public int getIngredientsSmart(IProgram program, Inventory inv, @Nonnull Inventory cardInv, ItemStack item, int slot1, int slot2, @Nonnull Inventory destInv) {
IStorageScanner scanner = getScannerForInv(inv);
IItemHandler handler = getHandlerForInv(inv);
if (item.isEmpty()) {
item = getCraftResult(program);
}
if (item.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
}
IItemHandler destHandler = getHandlerForInv(destInv);
if (destHandler == null) {
throw new ProgException(EXCEPT_INVALIDINVENTORY);
}
IItemHandler cardHandler = getItemHandlerAt(cardInv);
ItemStack card = findCraftingCard(cardHandler, item);
if (card.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
}
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
List<ItemStack> ingredients;
if (CraftingCardItem.fitsGrid(card) && (slot2 - slot1 >= 8)) {
// We have something that fits a crafting grid and we have enough room for a 3x3 grid
ingredients = CraftingCardItem.getIngredientsGrid(card);
} else {
ingredients = CraftingCardItem.getIngredients(card);
}
boolean strictnbt = CraftingCardItem.isStrictNBT(card);
List<ItemStack> needed = combineIngredients(ingredients);
int requested = checkAvailableItemsAndRequestMissing(destInv, scanner, handler, needed);
if (requested != 0) {
return requested;
}
// We got everything;
IItemHandler itemHandler = getItemHandler();
int slot = slot1;
for (ItemStack ingredient : ingredients) {
int realSlot = info.getRealSlot(slot);
if (!ingredient.isEmpty()) {
ItemStack stack = InventoryTools.extractItem(handler, scanner, ingredient.getCount(), true, false, strictnbt, ingredient, null);
if (!stack.isEmpty()) {
itemHandler.insertItem(realSlot, stack, false);
}
}
slot++;
}
return 0;
}
use of mcjty.rftools.api.storage.IStorageScanner in project RFToolsControl by McJty.
the class ProcessorTileEntity method pushItemsMulti.
public int pushItemsMulti(IProgram program, @Nullable Inventory inv, int slot1, int slot2, @Nullable Integer extSlot) {
IItemHandler handler = getHandlerForInv(inv);
IStorageScanner scanner = getScannerForInv(inv);
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
IItemHandler itemHandler = getItemHandler();
int e = 0;
if (extSlot != null) {
e = extSlot;
}
int failed = 0;
for (int slot = slot1; slot <= slot2; slot++) {
int realSlot = info.getRealSlot(slot);
ItemStack stack = itemHandler.getStackInSlot(realSlot);
if (!stack.isEmpty()) {
ItemStack remaining = InventoryTools.insertItem(handler, scanner, stack, extSlot == null ? null : e);
if (!remaining.isEmpty()) {
failed++;
}
inventoryHelper.setStackInSlot(realSlot, remaining);
}
e++;
}
return failed;
}
use of mcjty.rftools.api.storage.IStorageScanner in project RFToolsControl by McJty.
the class ProcessorTileEntity method getIngredients.
public int getIngredients(IProgram program, Inventory inv, Inventory cardInv, ItemStack item, int slot1, int slot2) {
IStorageScanner scanner = getScannerForInv(inv);
IItemHandler handler = getHandlerForInv(inv);
if (item.isEmpty()) {
item = getCraftResult(program);
}
if (item.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
}
IItemHandler cardHandler = getItemHandlerAt(cardInv);
ItemStack card = findCraftingCard(cardHandler, item);
if (card.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
}
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
IItemHandler itemHandler = getItemHandler();
int slot = slot1;
List<ItemStack> ingredients;
if (CraftingCardItem.fitsGrid(card) && (slot2 - slot1 >= 8)) {
// We have something that fits a crafting grid and we have enough room for a 3x3 grid
ingredients = CraftingCardItem.getIngredientsGrid(card);
} else {
ingredients = CraftingCardItem.getIngredients(card);
}
boolean strictnbt = CraftingCardItem.isStrictNBT(card);
int failed = 0;
for (ItemStack ingredient : ingredients) {
int realSlot = info.getRealSlot(slot);
if (!ingredient.isEmpty()) {
ItemStack stack = InventoryTools.extractItem(handler, scanner, ingredient.getCount(), true, false, strictnbt, ingredient, null);
if (!stack.isEmpty()) {
ItemStack remainder = itemHandler.insertItem(realSlot, stack, false);
if (!remainder.isEmpty()) {
InventoryTools.insertItem(handler, scanner, remainder, null);
}
} else {
failed++;
}
}
slot++;
}
return failed;
}
Aggregations