use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class ModuleCCBasedQuickSort method handle.
private boolean handle(IInventoryUtil invUtil, int slot, List<CCSinkResponder> list) {
if (list.isEmpty()) {
return false;
}
ItemIdentifier ident = list.get(0).getStack().getItem();
ItemStack stack = invUtil.getStackInSlot(slot);
if (stack == null || !ItemIdentifier.get(stack).equals(ident)) {
return false;
}
final IRouter source = _service.getRouter();
List<Triplet<Integer, Double, CCSinkResponder>> posibilities = new ArrayList<>();
for (CCSinkResponder sink : list) {
if (!sink.isDone()) {
continue;
}
if (sink.getCanSink() < 1) {
continue;
}
IRouter r = SimpleServiceLocator.routerManager.getRouter(sink.getRouterId());
if (r == null) {
continue;
}
List<ExitRoute> ways = source.getDistanceTo(r);
double minDistance = Double.MAX_VALUE;
outer: for (ExitRoute route : ways) {
for (IFilter filter : route.filters) {
if (filter.blockRouting() || filter.isFilteredItem(ident) == filter.isBlocked()) {
continue outer;
}
}
minDistance = Math.min(route.distanceToDestination, minDistance);
}
if (minDistance != Integer.MAX_VALUE) {
posibilities.add(new Triplet<>(sink.getPriority(), minDistance, sink));
}
}
if (posibilities.isEmpty()) {
return false;
}
Collections.sort(posibilities, (o1, o2) -> {
int c = o2.getValue1() - o1.getValue1();
if (c != 0) {
return c;
}
double e = o1.getValue2() - o2.getValue2();
return e < 0 ? -1 : 1;
});
boolean sended = false;
for (Triplet<Integer, Double, CCSinkResponder> triple : posibilities) {
CCSinkResponder sink = triple.getValue3();
if (sink.getCanSink() < 0) {
continue;
}
stack = invUtil.getStackInSlot(slot);
if (stack == null || stack.stackSize <= 0) {
continue;
}
int amount = Math.min(stack.stackSize, sink.getCanSink());
ItemStack extracted = invUtil.decrStackSize(slot, amount);
_service.sendStack(extracted, sink.getRouterId(), ItemSendMode.Fast, null);
sended = true;
}
return sended;
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class RequestUpdateNamesPacket method processPacket.
@Override
public void processPacket(EntityPlayer player) {
//XXX stubbed out. How do you enumerate every item now?
//Item[] itemList = Item.itemsList;
Item[] itemList = new Item[0];
List<ItemIdentifier> identList = new LinkedList<>();
for (Item item : itemList) {
if (item != null) {
for (CreativeTabs tab : item.getCreativeTabs()) {
List<ItemStack> list = new ArrayList<>();
item.getSubItems(item, tab, list);
if (list.size() > 0) {
identList.addAll(list.stream().map(ItemIdentifier::get).collect(Collectors.toList()));
} else {
identList.add(ItemIdentifier.get(item, 0, null));
}
}
}
}
SimpleServiceLocator.clientBufferHandler.setPause(true);
for (ItemIdentifier item : identList) {
MainProxy.sendPacketToServer(PacketHandler.getPacket(UpdateName.class).setIdent(item).setName(item.getFriendlyName()));
}
SimpleServiceLocator.clientBufferHandler.setPause(false);
FMLClientHandler.instance().getClient().thePlayer.sendChatMessage("Names in send Queue");
}
use of logisticspipes.utils.item.ItemIdentifier 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.ItemIdentifier in project LogisticsPipes by RS485.
the class PipeItemsProviderLogistics method getAllItems.
@Override
public void getAllItems(Map<ItemIdentifier, Integer> items, List<IFilter> filters) {
if (!isEnabled()) {
return;
}
HashMap<ItemIdentifier, Integer> addedItems = new HashMap<>();
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
//@formatter:off
Iterator<Map<ItemIdentifier, Integer>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> getAdaptedInventoryUtil(adjacent).getItemsAndCount()).iterator();
outer: while (iterator.hasNext()) {
Iterator<Entry<ItemIdentifier, Integer>> entryIterator = iterator.next().entrySet().stream().filter(currentItem -> !items.containsKey(currentItem.getKey())).filter(currentItem -> !hasFilter() || (!isExcludeFilter() || !itemIsFiltered(currentItem.getKey())) && (isExcludeFilter() || itemIsFiltered(currentItem.getKey()))).iterator();
while (entryIterator.hasNext()) {
Entry<ItemIdentifier, Integer> next = entryIterator.next();
for (IFilter filter : filters) {
if (filter.isBlocked() == filter.isFilteredItem(next.getKey().getUndamaged()) || filter.blockProvider()) {
continue outer;
}
}
Integer addedAmount = addedItems.get(next.getKey());
if (addedAmount == null) {
addedItems.put(next.getKey(), next.getValue());
} else {
addedItems.put(next.getKey(), addedAmount + next.getValue());
}
}
}
// reduce what has been reserved, add.
for (Entry<ItemIdentifier, Integer> item : addedItems.entrySet()) {
int remaining = item.getValue() - _orderManager.totalItemsCountInOrders(item.getKey());
if (remaining < 1) {
continue;
}
items.put(item.getKey(), remaining);
}
}
use of logisticspipes.utils.item.ItemIdentifier 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