use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class CoreRoutedPipe method updateEntity.
@Override
public final void updateEntity() {
debug.tick();
spawnParticleTick();
if (stillNeedReplace) {
stillNeedReplace = false;
// IBlockState state = getWorld().getBlockState(getPos());
// getWorld().notifyNeighborsOfStateChange(getPos(), state == null ? null : state.getBlock(), true);
/* TravelingItems are just held by a pipe, they don't need to know their world
* for(Triplet<IRoutedItem, EnumFacing, ItemSendMode> item : _sendQueue) {
//assign world to any entityitem we created in readfromnbt
item.getValue1().getTravelingItem().setWorld(getWorld());
}*/
// first tick just create a router and do nothing.
firstInitialiseTick();
return;
}
if (repeatFor > 0) {
if (delayTo < System.currentTimeMillis()) {
delayTo = System.currentTimeMillis() + 200;
repeatFor--;
getWorld().notifyNeighborsOfStateChange(getPos(), getWorld().getBlockState(getPos()).getBlock(), true);
}
}
// remove old items _inTransit -- these should have arrived, but have probably been lost instead. In either case, it will allow a re-send so that another attempt to re-fill the inventory can be made.
while (_inTransitToMe.peek() != null && _inTransitToMe.peek().getTickToTimeOut() <= 0) {
final ItemRoutingInformation polledInfo = _inTransitToMe.poll();
if (polledInfo != null) {
if (LogisticsPipes.isDEBUG()) {
LogisticsPipes.log.info("Timed Out: " + polledInfo.getItem().getFriendlyName() + " (" + polledInfo.hashCode() + ")");
}
debug.log("Timed Out: " + polledInfo.getItem().getFriendlyName() + " (" + polledInfo.hashCode() + ")");
}
}
// update router before ticking logic/transport
final boolean doFullRefresh = getWorld().getTotalWorldTime() % Configs.LOGISTICS_DETECTION_FREQUENCY == _delayOffset || _initialInit || recheckConnections;
if (doFullRefresh) {
// update adjacent cache first, so interests can be gathered correctly
// in getRouter().update(…) below
updateAdjacentCache();
}
getRouter().update(doFullRefresh, this);
recheckConnections = false;
getOriginalUpgradeManager().securityTick();
super.updateEntity();
if (isNthTick(200)) {
getCacheHolder().trigger(null);
}
// from BaseRoutingLogic
if (--throttleTimeLeft <= 0) {
throttledUpdateEntity();
throttleTimeLeft = throttleTime;
}
ignoreDisableUpdateEntity();
_initialInit = false;
if (!_sendQueue.isEmpty()) {
if (getItemSendMode() == ItemSendMode.Normal) {
Triplet<IRoutedItem, EnumFacing, ItemSendMode> itemToSend = _sendQueue.getFirst();
sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
_sendQueue.removeFirst();
for (int i = 0; i < 16 && !_sendQueue.isEmpty() && _sendQueue.getFirst().getValue3() == ItemSendMode.Fast; i++) {
if (!_sendQueue.isEmpty()) {
itemToSend = _sendQueue.getFirst();
sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
_sendQueue.removeFirst();
}
}
sendQueueChanged(false);
} else if (getItemSendMode() == ItemSendMode.Fast) {
for (int i = 0; i < 16; i++) {
if (!_sendQueue.isEmpty()) {
Triplet<IRoutedItem, EnumFacing, ItemSendMode> itemToSend = _sendQueue.getFirst();
sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
_sendQueue.removeFirst();
}
}
sendQueueChanged(false);
} else if (getItemSendMode() == null) {
throw new UnsupportedOperationException("getItemSendMode() can't return null. " + this.getClass().getName());
} else {
throw new UnsupportedOperationException("getItemSendMode() returned unhandled value. " + getItemSendMode().name() + " in " + this.getClass().getName());
}
}
if (MainProxy.isClient(getWorld())) {
return;
}
checkTexturePowered();
if (!isEnabled()) {
return;
}
enabledUpdateEntity();
if (getLogisticsModule() == null) {
return;
}
getLogisticsModule().tick();
}
use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class PipeItemsInvSysConnector method handleItemEnterInv.
public void handleItemEnterInv(ItemRoutingInformation info, TileEntity tile) {
if (info.getItem().getStackSize() == 0) {
// system.throw("why you try to insert empty stack?");
return;
}
if (info.destinationint < 0) {
// The item does not have a destination anymore, maybe the target pipe has been removed... We cannot do anything anymore so just let it be.
return;
}
if (isInventoryConnected(tile)) {
if (hasRemoteConnection()) {
List<CoreRoutedPipe> connectedPipes = SimpleServiceLocator.connectionManager.getConnectedPipes(getRouter());
Optional<CoreRoutedPipe> bestConnection = connectedPipes.stream().map(con -> new Triplet<>(con, con.getRouter().getExitFor(info.destinationint, info._transportMode == IRoutedItem.TransportMode.Active, info.getItem().getItem()), con.getRouter().getExitFor(getRouterId(), info._transportMode == IRoutedItem.TransportMode.Active, info.getItem().getItem()))).filter(triplet -> triplet.getValue2() != null && triplet.getValue3() != null).filter(triplet -> triplet.getValue2().exitOrientation != triplet.getValue3().exitOrientation).min(Comparator.comparing(trip -> trip.getValue2().blockDistance)).map(Pair::getValue1);
if (!bestConnection.isPresent()) {
bestConnection = connectedPipes.stream().map(con -> new Pair<>(con, con.getRouter().getExitFor(info.destinationint, info._transportMode == IRoutedItem.TransportMode.Active, info.getItem().getItem()))).filter(triplet -> triplet.getValue2() != null).min(Comparator.comparing(trip -> trip.getValue2().blockDistance)).map(Pair::getValue1);
}
if (bestConnection.isPresent() && bestConnection.get() instanceof IChannelRoutingConnection) {
IChannelRoutingConnection pipe = (IChannelRoutingConnection) bestConnection.get();
pipe.addItem(info);
spawnParticle(Particles.OrangeParticle, 4);
}
}
}
}
use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class PipeItemsInvSysConnector method addItem.
@Override
public void addItem(ItemRoutingInformation info) {
if (info.getItem() != null && info.getItem().getStackSize() > 0 && info.destinationint >= 0) {
ItemIdentifier insertedType = info.getItem().getItem();
List<ItemRoutingInformation> entry = itemsOnRoute.computeIfAbsent(insertedType, k -> new LinkedList<>());
// linked list as this is almost always very small, but experiences random removal
entry.add(info);
updateContentListener();
}
}
use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class BCEventHandler method eventHandler.
public void eventHandler(PipeEventItem.DropItem event) {
ItemRoutingInformation info = null;
if (event.item instanceof LPRoutedBCTravelingItem) {
info = ((LPRoutedBCTravelingItem) event.item).getRoutingInformation();
} else {
info = LPRoutedBCTravelingItem.restoreFromExtraNBTData(event.item);
}
if (info != null) {
LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
lpItem.setContainer(event.pipe.container);
lpItem.itemWasLost();
}
}
use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class LPRoutedBCTravelingItem method restoreFromExtraNBTData.
public static ItemRoutingInformation restoreFromExtraNBTData(TravelingItem item) {
if (!item.hasExtraData()) {
return null;
}
NBTTagCompound nbt = item.getExtraData();
if (nbt.hasKey("LPRoutingInformation")) {
ItemRoutingInformation routingInformation = new ItemRoutingInformation();
routingInformation.readFromNBT(nbt.getCompoundTag("LPRoutingInformation"));
return routingInformation;
}
return null;
}
Aggregations