use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class LogisticsManager method getCraftableItems.
/**
* @param validDestinations
* a List of ExitRoute of valid destinations.
* @return LinkedList with ItemIdentifier
*/
@Override
public LinkedList<ItemIdentifier> getCraftableItems(List<ExitRoute> validDestinations) {
LinkedList<ItemIdentifier> craftableItems = new LinkedList<>();
BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
outer: for (ExitRoute r : validDestinations) {
if (r == null) {
continue;
}
if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
continue;
}
if (used.get(r.destination.getSimpleID())) {
continue;
}
if (!(r.destination.getPipe() instanceof ICraftItems)) {
continue;
}
for (IFilter filter : r.filters) {
if (filter.blockCrafting()) {
continue outer;
}
}
ICraftItems crafter = (ICraftItems) r.destination.getPipe();
List<ItemIdentifierStack> craftedItems = crafter.getCraftedItems();
if (craftedItems != null) {
outer2: for (ItemIdentifierStack craftedItem : craftedItems) {
if (craftedItem != null && !craftableItems.contains(craftedItem.getItem())) {
for (IFilter filter : r.filters) {
if (filter.isBlocked() == filter.isFilteredItem(craftedItem.getItem())) {
continue outer2;
}
}
craftableItems.add(craftedItem.getItem());
}
}
}
used.set(r.destination.getSimpleID(), true);
}
return craftableItems;
}
use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class ItemModule method addInformation.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean flag) {
if (itemStack.hasTagCompound()) {
NBTTagCompound nbt = itemStack.getTagCompound();
if (nbt.hasKey("informationList")) {
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
NBTTagList nbttaglist = nbt.getTagList("informationList", 8);
for (int i = 0; i < nbttaglist.tagCount(); i++) {
Object nbttag = nbttaglist.tagList.get(i);
String data = ((NBTTagString) nbttag).func_150285_a_();
if (data.equals("<inventory>") && i + 1 < nbttaglist.tagCount()) {
nbttag = nbttaglist.tagList.get(i + 1);
data = ((NBTTagString) nbttag).func_150285_a_();
if (data.startsWith("<that>")) {
String prefix = data.substring(6);
NBTTagCompound module = nbt.getCompoundTag("moduleInformation");
int size = module.getTagList(prefix + "items", module.getId()).tagCount();
if (module.hasKey(prefix + "itemsCount")) {
size = module.getInteger(prefix + "itemsCount");
}
ItemIdentifierInventory inv = new ItemIdentifierInventory(size, "InformationTempInventory", Integer.MAX_VALUE);
inv.readFromNBT(module, prefix);
for (int pos = 0; pos < inv.getSizeInventory(); pos++) {
ItemIdentifierStack stack = inv.getIDStackInSlot(pos);
if (stack != null) {
if (stack.getStackSize() > 1) {
list.add(" " + stack.getStackSize() + "x " + stack.getFriendlyName());
} else {
list.add(" " + stack.getFriendlyName());
}
}
}
}
i++;
} else {
list.add(data);
}
}
} else {
list.add(StringUtils.translate(StringUtils.KEY_HOLDSHIFT));
}
} else {
StringUtils.addShiftAddition(itemStack, list);
}
} else {
StringUtils.addShiftAddition(itemStack, list);
}
}
use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class ModuleItemSink method getSpecificInterests.
@Override
public List<ItemIdentifier> getSpecificInterests() {
if (_isDefaultRoute) {
return null;
}
Map<ItemIdentifier, Integer> mapIC = _filterInventory.getItemsAndCount();
List<ItemIdentifier> li = new ArrayList<>(mapIC.size());
li.addAll(mapIC.keySet());
li.addAll(mapIC.keySet().stream().map(ItemIdentifier::getUndamaged).collect(Collectors.toList()));
if (_service.getUpgradeManager(slot, positionInt).isFuzzyUpgrade()) {
for (Pair<ItemIdentifierStack, Integer> stack : _filterInventory) {
if (stack.getValue1() == null) {
continue;
}
ItemIdentifier ident = stack.getValue1().getItem();
if (ignoreData.get(stack.getValue2())) {
li.add(ident.getIgnoringData());
}
if (ignoreNBT.get(stack.getValue2())) {
li.add(ident.getIgnoringNBT());
}
if (ignoreData.get(stack.getValue2()) && ignoreNBT.get(stack.getValue2())) {
li.add(ident.getIgnoringData().getIgnoringNBT());
}
}
}
return li;
}
use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class RequestAmountTaskSubGui method processPacket.
@Override
public void processPacket(EntityPlayer player) {
LogisticsStatisticsTileEntity tile = this.getTile(player.getEntityWorld(), LogisticsStatisticsTileEntity.class);
CoreRoutedPipe pipe = tile.getConnectedPipe();
if (pipe == null) {
return;
}
Map<ItemIdentifier, Integer> _availableItems = SimpleServiceLocator.logisticsManager.getAvailableItems(pipe.getRouter().getIRoutersByCost());
LinkedList<ItemIdentifier> _craftableItems = SimpleServiceLocator.logisticsManager.getCraftableItems(pipe.getRouter().getIRoutersByCost());
TreeSet<ItemIdentifierStack> _allItems = new TreeSet<>();
for (Entry<ItemIdentifier, Integer> item : _availableItems.entrySet()) {
ItemIdentifierStack newStack = item.getKey().makeStack(item.getValue());
_allItems.add(newStack);
}
for (ItemIdentifier item : _craftableItems) {
if (_availableItems.containsKey(item)) {
continue;
}
_allItems.add(item.makeStack(0));
}
MainProxy.sendPacketToPlayer(PacketHandler.getPacket(AmountTaskSubGui.class).setIdentSet(_allItems), player);
}
use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class PipeItemsProviderLogistics method sendStack.
private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
ItemIdentifier item = stack.getItem();
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
//@formatter:off
Iterator<Pair<IInventoryUtil, ForgeDirection>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>(getAdaptedInventoryUtil(adjacent), adjacent.direction)).iterator();
while (iterator.hasNext()) {
Pair<IInventoryUtil, ForgeDirection> next = iterator.next();
int available = next.getValue1().itemCount(item);
if (available == 0) {
continue;
}
int wanted = Math.min(available, stack.getStackSize());
wanted = Math.min(wanted, maxCount);
wanted = Math.min(wanted, item.getMaxStackSize());
IRouter dRtr = SimpleServiceLocator.routerManager.getRouterUnsafe(destination, false);
if (dRtr == null) {
_orderManager.sendFailed();
return 0;
}
SinkReply reply = LogisticsManager.canSink(dRtr, null, true, stack.getItem(), null, true, false);
boolean defersend = false;
if (reply != null) {
// some pipes are not aware of the space in the adjacent inventory, so they return null
if (reply.maxNumberOfItems < wanted) {
wanted = reply.maxNumberOfItems;
if (wanted <= 0) {
_orderManager.deferSend();
return 0;
}
defersend = true;
}
}
if (!canUseEnergy(wanted * neededEnergy())) {
return -1;
}
ItemStack removed = next.getValue1().getMultipleItems(item, wanted);
if (removed == null || removed.stackSize == 0) {
continue;
}
int sent = removed.stackSize;
useEnergy(sent * neededEnergy());
IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(removed);
routedItem.setDestination(destination);
routedItem.setTransportMode(TransportMode.Active);
routedItem.setAdditionalTargetInformation(info);
super.queueRoutedItem(routedItem, next.getValue2());
_orderManager.sendSuccessfull(sent, defersend, routedItem);
return sent;
}
_orderManager.sendFailed();
return 0;
}
Aggregations