use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class ModuleItemSink method sinksItem.
@Override
public SinkReply sinksItem(ItemIdentifier item, int bestPriority, int bestCustomPriority, boolean allowDefault, boolean includeInTransit) {
if (_isDefaultRoute && !allowDefault) {
return null;
}
if (bestPriority > _sinkReply.fixedPriority.ordinal() || (bestPriority == _sinkReply.fixedPriority.ordinal() && bestCustomPriority >= _sinkReply.customPriority)) {
return null;
}
if (_filterInventory.containsUndamagedItem(item.getUndamaged())) {
if (_service.canUseEnergy(1)) {
return _sinkReply;
}
return null;
}
if (_service.getUpgradeManager(slot, positionInt).isFuzzyUpgrade()) {
for (Pair<ItemIdentifierStack, Integer> stack : _filterInventory) {
if (stack == null) {
continue;
}
if (stack.getValue1() == null) {
continue;
}
ItemIdentifier ident1 = item;
ItemIdentifier ident2 = stack.getValue1().getItem();
if (ignoreData.get(stack.getValue2())) {
ident1 = ident1.getIgnoringData();
ident2 = ident2.getIgnoringData();
}
if (ignoreNBT.get(stack.getValue2())) {
ident1 = ident1.getIgnoringNBT();
ident2 = ident2.getIgnoringNBT();
}
if (ident1.equals(ident2)) {
if (_service.canUseEnergy(5)) {
return _sinkReply;
}
return null;
}
}
}
if (_isDefaultRoute) {
if (bestPriority > _sinkReplyDefault.fixedPriority.ordinal() || (bestPriority == _sinkReplyDefault.fixedPriority.ordinal() && bestCustomPriority >= _sinkReplyDefault.customPriority)) {
return null;
}
if (_service.canUseEnergy(1)) {
return _sinkReplyDefault;
}
return null;
}
return null;
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class ModuleItemSink method importFromInventory.
public void importFromInventory() {
if (_service == null) {
return;
}
IInventoryUtil inv = _service.getPointedInventory(false);
if (inv == null) {
return;
}
int count = 0;
for (ItemIdentifier item : inv.getItems()) {
_filterInventory.setInventorySlotContents(count, item.makeStack(1));
count++;
if (count >= _filterInventory.getSizeInventory()) {
break;
}
}
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class PipeFluidProvider method getSpecificInterests.
@Override
public //work in progress, currently not active code.
Set<ItemIdentifier> getSpecificInterests() {
Set<ItemIdentifier> l1 = new TreeSet<>();
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
boolean fallback = true;
if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
if (handler instanceof ISpecialTankAccessHandler) {
fallback = false;
Map<FluidIdentifier, Long> map = ((ISpecialTankAccessHandler) handler).getAvailableLiquid(pair.getValue1());
l1.addAll(map.keySet().stream().map(FluidIdentifier::getItemIdentifier).collect(Collectors.toList()));
}
}
if (fallback) {
FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
if (tanks != null) {
for (FluidTankInfo tank : tanks) {
if (tank == null) {
continue;
}
FluidStack liquid;
if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
if (((IFluidHandler) pair.getValue1()).canDrain(pair.getValue2().getOpposite(), liquid.getFluid())) {
if (((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), 1, false) != null) {
FluidIdentifier ident = FluidIdentifier.get(liquid);
l1.add(ident.getItemIdentifier());
}
}
}
}
}
}
}
return l1;
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class PipeItemsFluidSupplier method throttledUpdateEntity.
@Override
public void throttledUpdateEntity() {
if (!isEnabled()) {
return;
}
if (MainProxy.isClient(getWorld())) {
return;
}
super.throttledUpdateEntity();
//@formatter:off
Iterator<IFluidHandler> iterator = new WorldCoordinatesWrapper(container).getConnectedAdjacentTileEntities().filter(adjacent -> adjacent.tileEntity instanceof IFluidHandler).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> (IFluidHandler) adjacent.tileEntity).iterator();
while (iterator.hasNext()) {
IFluidHandler next = iterator.next();
FluidTankInfo[] result = next.getTankInfo(ForgeDirection.UNKNOWN);
if (result == null || result.length == 0) {
continue;
}
//How much do I want?
Map<ItemIdentifier, Integer> wantContainers = dummyInventory.getItemsAndCount();
HashMap<FluidIdentifier, Integer> wantFluids = new HashMap<>();
for (Entry<ItemIdentifier, Integer> item : wantContainers.entrySet()) {
ItemStack wantItem = item.getKey().unsafeMakeNormalStack(1);
FluidStack liquidstack = FluidContainerRegistry.getFluidForFilledItem(wantItem);
if (liquidstack == null) {
continue;
}
wantFluids.put(FluidIdentifier.get(liquidstack), item.getValue() * liquidstack.amount);
}
//How much do I have?
HashMap<FluidIdentifier, Integer> haveFluids = new HashMap<>();
for (FluidTankInfo slot : result) {
if (slot == null || slot.fluid == null || slot.fluid.getFluidID() == 0 || !wantFluids.containsKey(FluidIdentifier.get(slot.fluid))) {
continue;
}
Integer liquidWant = haveFluids.get(FluidIdentifier.get(slot.fluid));
if (liquidWant == null) {
haveFluids.put(FluidIdentifier.get(slot.fluid), slot.fluid.amount);
} else {
haveFluids.put(FluidIdentifier.get(slot.fluid), liquidWant + slot.fluid.amount);
}
}
//Reduce what I have and what have been requested already
for (Entry<FluidIdentifier, Integer> liquidId : wantFluids.entrySet()) {
Integer haveCount = haveFluids.get(liquidId.getKey());
if (haveCount != null) {
liquidId.setValue(liquidId.getValue() - haveCount);
}
}
for (Entry<ItemIdentifier, Integer> requestedItem : _requestedItems.entrySet()) {
ItemStack wantItem = requestedItem.getKey().unsafeMakeNormalStack(1);
FluidStack requestedFluidId = FluidContainerRegistry.getFluidForFilledItem(wantItem);
if (requestedFluidId == null) {
continue;
}
FluidIdentifier requestedFluid = FluidIdentifier.get(requestedFluidId);
Integer want = wantFluids.get(requestedFluid);
if (want != null) {
wantFluids.put(requestedFluid, want - requestedItem.getValue() * requestedFluidId.amount);
}
}
((PipeItemsFluidSupplier) container.pipe).setRequestFailed(false);
for (ItemIdentifier need : wantContainers.keySet()) {
FluidStack requestedFluidId = FluidContainerRegistry.getFluidForFilledItem(need.unsafeMakeNormalStack(1));
if (requestedFluidId == null) {
continue;
}
if (!wantFluids.containsKey(FluidIdentifier.get(requestedFluidId))) {
continue;
}
int countToRequest = wantFluids.get(FluidIdentifier.get(requestedFluidId)) / requestedFluidId.amount;
if (countToRequest < 1) {
continue;
}
if (!useEnergy(11)) {
break;
}
boolean success = false;
if (_requestPartials) {
countToRequest = RequestTree.requestPartial(need.makeStack(countToRequest), (IRequestItems) container.pipe, null);
if (countToRequest > 0) {
success = true;
}
} else {
success = RequestTree.request(need.makeStack(countToRequest), (IRequestItems) container.pipe, null, null);
}
if (success) {
Integer currentRequest = _requestedItems.get(need);
if (currentRequest == null) {
_requestedItems.put(need, countToRequest);
} else {
_requestedItems.put(need, currentRequest + countToRequest);
}
} else {
((PipeItemsFluidSupplier) container.pipe).setRequestFailed(true);
}
}
}
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class PipeItemsInvSysConnector method getExpectedItems.
public Set<ItemIdentifierStack> getExpectedItems() {
// got to be a TreeMap, because a TreeSet doesn't have the ability to retrieve the key.
Set<ItemIdentifierStack> list = new TreeSet<>();
for (Entry<ItemIdentifier, List<ItemRoutingInformation>> entry : itemsOnRoute.entrySet()) {
if (entry.getValue().isEmpty()) {
continue;
}
ItemIdentifierStack currentStack = new ItemIdentifierStack(entry.getKey(), 0);
for (ItemRoutingInformation e : entry.getValue()) {
currentStack.setStackSize(currentStack.getStackSize() + e.getItem().getStackSize());
}
list.add(currentStack);
}
return list;
}
Aggregations