use of buildcraft.api.transport.pipe.IPipe.ConnectedType in project BuildCraft by BuildCraft.
the class PipeFlowItems method onItemReachEnd.
private void onItemReachEnd(TravellingItem item) {
IPipeHolder holder = pipe.getHolder();
PipeEventItem.ReachEnd reachEnd = new PipeEventItem.ReachEnd(holder, this, item.colour, item.stack, item.side);
holder.fireEvent(reachEnd);
item.colour = reachEnd.colour;
item.stack = reachEnd.getStack();
ItemStack excess = item.stack;
if (excess.isEmpty()) {
return;
}
if (pipe.isConnected(item.side)) {
ConnectedType type = pipe.getConnectedType(item.side);
EnumFacing oppositeSide = item.side.getOpposite();
switch(type) {
case PIPE:
{
IPipe oPipe = pipe.getConnectedPipe(item.side);
if (oPipe == null) {
break;
}
PipeFlow flow = oPipe.getFlow();
if (flow instanceof IFlowItems) {
IFlowItems oFlow = (IFlowItems) flow;
ItemStack before = excess;
excess = oFlow.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
if (!excess.isEmpty()) {
before.shrink(excess.getCount());
}
excess = fireEventEjectIntoPipe(oFlow, item.side, before, excess);
}
break;
}
case TILE:
{
TileEntity tile = pipe.getConnectedTile(item.side);
IInjectable injectable = ItemTransactorHelper.getInjectable(tile, oppositeSide);
ItemStack before = excess;
excess = injectable.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
if (!excess.isEmpty()) {
IItemTransactor transactor = ItemTransactorHelper.getTransactor(tile, oppositeSide);
excess = transactor.insert(excess, false, false);
}
excess = fireEventEjectIntoTile(tile, item.side, before, excess);
break;
}
}
}
if (excess.isEmpty()) {
return;
}
item.tried.add(item.side);
item.toCenter = true;
item.stack = excess;
item.genTimings(holder.getPipeWorld().getTotalWorldTime(), getPipeLength(item.side));
items.add(item.timeToDest, item);
sendItemDataToClient(item);
}
Aggregations