Search in sources :

Example 1 with IFlowFluid

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;
}
Also used : IItemTransactor(buildcraft.api.inventory.IItemTransactor) PipeFlow(buildcraft.api.transport.pipe.PipeFlow) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IFlowFluid(buildcraft.api.transport.pipe.IFlowFluid) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IFlowFluid

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();
    }
}
Also used : IMjRedstoneReceiver(buildcraft.api.mj.IMjRedstoneReceiver) IFlowFluid(buildcraft.api.transport.pipe.IFlowFluid) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 3 with IFlowFluid

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;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IFlowFluid(buildcraft.api.transport.pipe.IFlowFluid) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 4 with IFlowFluid

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;
    }
}
Also used : FluidUtil(net.minecraftforge.fluids.FluidUtil) InvertedStackFilter(buildcraft.lib.inventory.filter.InvertedStackFilter) ItemHandlerSimple(buildcraft.lib.tile.item.ItemHandlerSimple) BCTransportGuis(buildcraft.transport.BCTransportGuis) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) IStackFilter(buildcraft.api.core.IStackFilter) Side(net.minecraftforge.fml.relauncher.Side) PipeMessageReceiver(buildcraft.api.transport.pipe.IPipeHolder.PipeMessageReceiver) StackFilter(buildcraft.lib.inventory.filter.StackFilter) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IItemPluggable(buildcraft.api.transport.IItemPluggable) DelegatingItemHandlerFilter(buildcraft.lib.inventory.filter.DelegatingItemHandlerFilter) EnumFacing(net.minecraft.util.EnumFacing) IOException(java.io.IOException) ActionResult(net.minecraft.util.ActionResult) IFlowFluid(buildcraft.api.transport.pipe.IFlowFluid) EntityUtil(buildcraft.lib.misc.EntityUtil) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) InvertedFluidFilter(buildcraft.lib.inventory.filter.InvertedFluidFilter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) StackUtil(buildcraft.lib.misc.StackUtil) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayFluidFilter(buildcraft.lib.inventory.filter.ArrayFluidFilter) PacketBuffer(net.minecraft.network.PacketBuffer) EnumPipePart(buildcraft.api.core.EnumPipePart) IPipe(buildcraft.api.transport.pipe.IPipe) InvertedFluidFilter(buildcraft.lib.inventory.filter.InvertedFluidFilter) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayFluidFilter(buildcraft.lib.inventory.filter.ArrayFluidFilter) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IFlowFluid (buildcraft.api.transport.pipe.IFlowFluid)4 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)4 ItemStack (net.minecraft.item.ItemStack)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 IStackFilter (buildcraft.api.core.IStackFilter)1 IItemTransactor (buildcraft.api.inventory.IItemTransactor)1 IMjRedstoneReceiver (buildcraft.api.mj.IMjRedstoneReceiver)1 IItemPluggable (buildcraft.api.transport.IItemPluggable)1 IPipe (buildcraft.api.transport.pipe.IPipe)1 PipeMessageReceiver (buildcraft.api.transport.pipe.IPipeHolder.PipeMessageReceiver)1 PipeFlow (buildcraft.api.transport.pipe.PipeFlow)1 ArrayFluidFilter (buildcraft.lib.inventory.filter.ArrayFluidFilter)1 DelegatingItemHandlerFilter (buildcraft.lib.inventory.filter.DelegatingItemHandlerFilter)1 InvertedFluidFilter (buildcraft.lib.inventory.filter.InvertedFluidFilter)1 InvertedStackFilter (buildcraft.lib.inventory.filter.InvertedStackFilter)1 StackFilter (buildcraft.lib.inventory.filter.StackFilter)1 EntityUtil (buildcraft.lib.misc.EntityUtil)1 StackUtil (buildcraft.lib.misc.StackUtil)1 ItemHandlerSimple (buildcraft.lib.tile.item.ItemHandlerSimple)1