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;
}
}
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();
}
}
Aggregations