use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class PipeItemsInvSysConnector method checkOneConnectedInv.
private boolean checkOneConnectedInv(IInventoryUtil inv, ForgeDirection dir) {
boolean contentchanged = false;
if (!itemsOnRoute.isEmpty()) {
// don't check the inventory if you don't want anything
List<ItemIdentifier> items = new ArrayList<>(itemsOnRoute.keySet());
items.retainAll(inv.getItems());
Map<ItemIdentifier, Integer> amounts = null;
if (!items.isEmpty()) {
amounts = inv.getItemsAndCount();
}
for (ItemIdentifier ident : items) {
if (!amounts.containsKey(ident)) {
continue;
}
int itemAmount = amounts.get(ident);
List<ItemRoutingInformation> needs = itemsOnRoute.get(ident);
for (Iterator<ItemRoutingInformation> iterator = needs.iterator(); iterator.hasNext(); ) {
ItemRoutingInformation need = iterator.next();
if (need.getItem().getStackSize() <= itemAmount) {
if (!useEnergy(6)) {
return contentchanged;
}
ItemStack toSend = inv.getMultipleItems(ident, need.getItem().getStackSize());
if (toSend == null) {
return contentchanged;
}
if (toSend.stackSize != need.getItem().getStackSize()) {
if (inv instanceof ITransactor) {
((ITransactor) inv).add(toSend, dir.getOpposite(), true);
} else {
container.getWorldObj().spawnEntityInWorld(ItemIdentifierStack.getFromStack(toSend).makeEntityItem(getWorld(), container.xCoord, container.yCoord, container.zCoord));
}
new UnsupportedOperationException("The extracted amount didn't match the requested one. (" + inv + ")").printStackTrace();
return contentchanged;
}
sendStack(need, dir);
// finished with this need, we sent part of a stack, lets see if anyone where needs the current item type.
iterator.remove();
contentchanged = true;
if (needs.isEmpty()) {
itemsOnRoute.remove(ident);
}
//Refresh Available Items
amounts = inv.getItemsAndCount();
if (amounts.containsKey(ident)) {
itemAmount = amounts.get(ident);
} else {
itemAmount = 0;
break;
}
}
}
}
}
return contentchanged;
}
use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class PipeTransportLogistics method resolveRoutedDestination.
public RoutingResult resolveRoutedDestination(LPTravelingItemServer data) {
EnumFacing blocked = null;
if (data.getDestinationUUID() == null) {
ItemIdentifierStack stack = data.getItemIdentifierStack();
ItemRoutingInformation result = getRoutedPipe().getQueuedForItemStack(stack);
if (result != null) {
data.setInformation(result);
data.getInfo().setItem(stack);
blocked = data.input.getOpposite();
}
}
if (data.getItemIdentifierStack() != null) {
getRoutedPipe().relayedItem(data.getItemIdentifierStack().getStackSize());
}
if (data.getDestination() >= 0 && !getRoutedPipe().getRouter().hasRoute(data.getDestination(), data.getTransportMode() == TransportMode.Active, data.getItemIdentifierStack().getItem()) && data.getBufferCounter() < MAX_DESTINATION_UNREACHABLE_BUFFER) {
_itemBuffer.add(new Triplet<>(data.getItemIdentifierStack(), new Pair<>(_bufferTimeOut, data.getBufferCounter()), data));
return new RoutingResult(null, false);
}
EnumFacing value;
if (getRoutedPipe().stillNeedReplace() || getRoutedPipe().initialInit()) {
data.setDoNotBuffer(false);
value = null;
} else {
value = getRoutedPipe().getRouteLayer().getOrientationForItem(data, blocked);
}
if (value == null && MainProxy.isClient(getWorld())) {
return new RoutingResult(null, true);
}
if (value == null && !data.getDoNotBuffer() && data.getBufferCounter() < 5) {
_itemBuffer.add(new Triplet<>(data.getItemIdentifierStack(), new Pair<>(_bufferTimeOut, data.getBufferCounter()), null));
return new RoutingResult(null, false);
}
if (value != null && !getRoutedPipe().getRouter().isRoutedExit(value)) {
if (isItemUnwanted(data.getItemIdentifierStack())) {
return new RoutingResult(null, false);
}
}
data.resetDelay();
return new RoutingResult(value, true);
}
use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class PipeTransportLogistics method injectItem.
public int injectItem(LPTravelingItem item, EnumFacing inputOrientation) {
if (item.isCorrupted()) {
// stage, avoid adding it to the pipe to avoid further exceptions.
return 0;
}
getPipe().triggerDebug();
int originalCount = item.getItemIdentifierStack().getStackSize();
item.input = inputOrientation;
if (MainProxy.isServer(container.getWorld())) {
readjustSpeed((LPTravelingItemServer) item);
ItemRoutingInformation info1 = ((LPTravelingItemServer) item).getInfo().clone();
RoutingResult result = resolveDestination((LPTravelingItemServer) item);
item.output = result.getFace();
if (!result.hasRoute) {
return 0;
}
getPipe().debug.log("Injected Item: [" + item.input + ", " + item.output + "] (" + info1);
} else {
item.output = null;
}
if (item.getPosition() >= getPipeLength()) {
reachedEnd(item);
} else {
items.add(item);
if (MainProxy.isServer(container.getWorld()) && !getPipe().isOpaque() && item.getItemIdentifierStack().getStackSize() > 0) {
sendItemPacket((LPTravelingItemServer) item);
}
}
return originalCount - item.getItemIdentifierStack().getStackSize();
}
use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class BCPipeInformationProvider method acceptItem.
@Override
public boolean acceptItem(LPTravelingItem item, TileEntity from) {
if (pipe != null && pipe.getPipe() != null && pipe.getPipe().getDefinition().flowType == PipeApi.flowItems) {
if (!(item instanceof LPTravelingItemServer)) {
return true;
}
ItemRoutingInformation routingInformation = ((LPTravelingItemServer) item).getInfo();
NBTTagCompound routingData = new NBTTagCompound();
routingInformation.storeToNBT(routingData);
ItemStack transportStack = item.getItemIdentifierStack().makeNormalStack();
if (!transportStack.hasTagCompound()) {
transportStack.setTagCompound(new NBTTagCompound());
}
final NBTTagCompound tag = Objects.requireNonNull(transportStack.getTagCompound());
tag.setTag("logisticspipes:routingdata_buildcraft", routingData);
IFlowItems itemPipe = (IFlowItems) pipe.getPipe().getFlow();
itemPipe.insertItemsForce(transportStack, item.output.getOpposite(), null, item.getSpeed());
return true;
}
return false;
}
use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class BuildCraftProxy method initProxy.
@Override
public void initProxy() {
LogisticsTileGenericPipe.pipeInventoryConnectionChecker.addSupportedClassType(TileBC_Neptune.class);
ItemInsertionHandler.ACCEPTORS.add((pipe, from, stack) -> {
if (!stack.isEmpty() && stack.hasTagCompound() && stack.getTagCompound().hasKey("logisticspipes:routingdata_buildcraft")) {
NBTTagCompound routingData = stack.getTagCompound().getCompoundTag("logisticspipes:routingdata_buildcraft");
ItemRoutingInformation info = ItemRoutingInformation.restoreFromNBT(routingData);
LPTravelingItem item = new LPTravelingItem.LPTravelingItemServer(info);
item.output = from.getOpposite();
return pipe.acceptItem(item, null);
}
return false;
});
}
Aggregations