use of buildcraft.api.transport.pipe.IFlowFluid 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.IFlowFluid in project BuildCraft by BuildCraft.
the class PluggablePulsar method onTick.
@Override
public void onTick() {
if (holder.getPipeWorld().isRemote) {
if (isPulsing) {
pulseStage++;
if (pulseStage == PULSE_STAGE) {
pulseStage = 0;
}
} else {
// pulseStage--;
// if (pulseStage < 0) {
pulseStage = 0;
// }
}
setModelVariables(1);
clientModelData.tick();
return;
}
boolean isOn = isPulsing();
if (isOn) {
pulseStage++;
} else {
// pulseStage--;
// if (pulseStage < 0) {
pulseStage = 0;
// }
}
if (gateEnabledTicks > 0) {
gateEnabledTicks--;
}
if (pulseStage == PULSE_STAGE) {
pulseStage = 0;
IMjRedstoneReceiver rsRec = (IMjRedstoneReceiver) holder.getPipe().getBehaviour();
if (gateSinglePulses > 0) {
long power = MjAPI.MJ;
if (holder.getPipe().getFlow() instanceof IFlowFluid) {
// Special extration logic for fluids:
// Always extract either 1 bucket, or nothing.
power = BCTransportConfig.mjPerMillibucket * 1000;
} else if (holder.getPipe().getFlow() instanceof IFlowItems) {
power = BCTransportConfig.mjPerItem;
} else {
power = MjAPI.MJ;
}
long excess = rsRec.receivePower(power, true);
if (excess == 0) {
rsRec.receivePower(power, false);
} else {
// Nothing was extracted, so lets extract in the future
gateSinglePulses++;
// ParticleUtil.spawnFailureParticles
}
} else {
rsRec.receivePower(MjAPI.MJ, false);
}
if (gateSinglePulses > 0) {
gateSinglePulses--;
}
}
if (isOn != lastPulsing) {
lastPulsing = isOn;
scheduleNetworkUpdate();
}
}
use of buildcraft.api.transport.pipe.IFlowFluid in project BuildCraft by BuildCraft.
the class PipeBehaviourWood method extract.
protected long extract(long power, boolean simulate) {
if (power > 0) {
if (pipe.getFlow() instanceof IFlowItems) {
IFlowItems flow = (IFlowItems) pipe.getFlow();
int maxItems = (int) (power / BCTransportConfig.mjPerItem);
if (maxItems > 0) {
int extracted = extractItems(flow, getCurrentDir(), maxItems, simulate);
if (extracted > 0) {
return power - extracted * BCTransportConfig.mjPerItem;
}
}
} else if (pipe.getFlow() instanceof IFlowFluid) {
IFlowFluid flow = (IFlowFluid) pipe.getFlow();
int maxMillibuckets = (int) (power / BCTransportConfig.mjPerMillibucket);
if (maxMillibuckets > 0) {
FluidStack extracted = extractFluid(flow, getCurrentDir(), maxMillibuckets, simulate);
if (extracted != null && extracted.amount > 0) {
return power - extracted.amount * BCTransportConfig.mjPerMillibucket;
}
}
}
}
return power;
}
use of buildcraft.api.transport.pipe.IFlowFluid in project BuildCraft by BuildCraft.
the class PipeBehaviourWoodDiamond method extractFluid.
@Override
protected FluidStack extractFluid(IFlowFluid flow, EnumFacing dir, int millibuckets, boolean simulate) {
if (filters.getStackInSlot(currentFilter).isEmpty()) {
advanceFilter();
}
switch(filterMode) {
default:
case WHITE_LIST:
if (filters.extract(s -> true, 1, 1, true).isEmpty()) {
return flow.tryExtractFluid(millibuckets, dir, null, simulate);
}
// Firstly try the advanced version - if that fails we will need to try the basic version
ActionResult<FluidStack> result = flow.tryExtractFluidAdv(millibuckets, dir, new ArrayFluidFilter(filters.stacks), simulate);
FluidStack extracted = result.getResult();
if (result.getType() != EnumActionResult.PASS) {
return extracted;
}
if (extracted == null || extracted.amount <= 0) {
for (int i = 0; i < filters.getSlots(); i++) {
ItemStack stack = filters.getStackInSlot(i);
if (stack.isEmpty()) {
continue;
}
extracted = flow.tryExtractFluid(millibuckets, dir, FluidUtil.getFluidContained(stack), simulate);
if (extracted != null && extracted.amount > 0) {
return extracted;
}
}
}
return null;
case BLACK_LIST:
// We cannot fallback to the basic version - only use the advanced version
InvertedFluidFilter filter = new InvertedFluidFilter(new ArrayFluidFilter(filters.stacks));
return flow.tryExtractFluidAdv(millibuckets, dir, filter, simulate).getResult();
case ROUND_ROBIN:
// We can't do this -- amounts might differ and its just ugly
return null;
}
}
Aggregations