Search in sources :

Example 1 with IMjRedstoneReceiver

use of buildcraft.api.mj.IMjRedstoneReceiver in project BuildCraft by BuildCraft.

the class ItemPluggablePulsar method onPlace.

@Override
public PipePluggable onPlace(@Nonnull ItemStack stack, IPipeHolder holder, EnumFacing side, EntityPlayer player, EnumHand hand) {
    IPipe pipe = holder.getPipe();
    if (pipe == null) {
        return null;
    }
    PipeBehaviour behaviour = pipe.getBehaviour();
    if (behaviour instanceof IMjRedstoneReceiver) {
        SoundUtil.playBlockPlace(holder.getPipeWorld(), holder.getPipePos());
        return new PluggablePulsar(BCTransportPlugs.pulsar, holder, side);
    } else {
        return null;
    }
}
Also used : PluggablePulsar(buildcraft.transport.plug.PluggablePulsar) IMjRedstoneReceiver(buildcraft.api.mj.IMjRedstoneReceiver) IPipe(buildcraft.api.transport.pipe.IPipe) PipeBehaviour(buildcraft.api.transport.pipe.PipeBehaviour)

Example 2 with IMjRedstoneReceiver

use of buildcraft.api.mj.IMjRedstoneReceiver 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)

Aggregations

IMjRedstoneReceiver (buildcraft.api.mj.IMjRedstoneReceiver)2 IFlowFluid (buildcraft.api.transport.pipe.IFlowFluid)1 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)1 IPipe (buildcraft.api.transport.pipe.IPipe)1 PipeBehaviour (buildcraft.api.transport.pipe.PipeBehaviour)1 PluggablePulsar (buildcraft.transport.plug.PluggablePulsar)1