use of buildcraft.api.transport.pipe.PipeFlow in project BuildCraft by BuildCraft.
the class PipeBehaviourObsidian method trySuckEntity.
/**
* @return The left over power
*/
protected long trySuckEntity(Entity entity, EnumFacing faceFrom, long power, boolean simulate) {
if (entity.isDead || entity instanceof EntityLivingBase) {
return power;
}
Long tickPickupObj = entityDropTime.get(entity);
if (tickPickupObj != null) {
long tickPickup = tickPickupObj;
long tickNow = pipe.getHolder().getPipeWorld().getTotalWorldTime();
if (tickNow < tickPickup) {
return power;
} else {
entityDropTime.remove(entity);
}
}
PipeFlow flow = pipe.getFlow();
IFlowItems flowItem = flow instanceof IFlowItems ? (IFlowItems) flow : null;
IFlowFluid flowFluid = flow instanceof IFlowFluid ? (IFlowFluid) flow : null;
IItemTransactor transactor = ItemTransactorHelper.getTransactorForEntity(entity, faceFrom.getOpposite());
if (flowItem != null) {
double distance = Math.sqrt(entity.getDistanceSqToCenter(pipe.getHolder().getPipePos()));
long powerReqPerItem = (long) (distance * POWER_PER_METRE + POWER_PER_ITEM);
int max = power == 0 ? 1 : (int) (power / powerReqPerItem);
ItemStack extracted = transactor.extract(StackFilter.ALL, 1, max, simulate);
if (!extracted.isEmpty()) {
if (!simulate) {
flowItem.insertItemsForce(extracted, faceFrom, null, INSERT_SPEED);
}
return power - powerReqPerItem * extracted.getCount();
}
}
if (flowFluid != null) {
// TODO: Fluid extraction!
}
return power;
}
use of buildcraft.api.transport.pipe.PipeFlow 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