Search in sources :

Example 1 with Signal

use of crazypants.enderio.base.conduit.redstone.signals.Signal in project EnderIO by SleepyTrousers.

the class InsulatedRedstoneConduit method isProvidingWeakPower.

@Override
public int isProvidingWeakPower(@Nonnull EnumFacing toDirection) {
    toDirection = toDirection.getOpposite();
    if (getConnectionMode(toDirection) != ConnectionMode.IN_OUT) {
        return 0;
    }
    if (network == null || !network.isNetworkEnabled()) {
        return 0;
    }
    int result = 0;
    for (Signal signal : getNetworkOutputs(toDirection)) {
        // don't return signals back to where they came from
        if (!signal.getSource().equals(getPos().offset(toDirection))) {
            result = Math.max(result, signal.getStrength());
        }
    }
    return result;
}
Also used : Signal(crazypants.enderio.base.conduit.redstone.signals.Signal)

Example 2 with Signal

use of crazypants.enderio.base.conduit.redstone.signals.Signal in project EnderIO by SleepyTrousers.

the class InsulatedRedstoneConduit method getNetworkOutputs.

@Override
@Nonnull
public Collection<Signal> getNetworkOutputs(@Nonnull EnumFacing side) {
    if (side == null) {
        if (network == null) {
            return Collections.emptySet();
        }
        return network.getSignals().values();
    }
    ConnectionMode mode = getConnectionMode(side);
    if (network == null || mode != ConnectionMode.IN_OUT) {
        return Collections.emptySet();
    }
    Collection<Signal> allSigs = network.getSignals().values();
    if (allSigs.isEmpty()) {
        return allSigs;
    }
    DyeColor col = getSignalColor(side);
    Set<Signal> result = new HashSet<Signal>();
    for (Signal signal : allSigs) {
        if (signal.getColor() == col) {
            result.add(signal);
        }
    }
    return result;
}
Also used : Signal(crazypants.enderio.base.conduit.redstone.signals.Signal) ConnectionMode(crazypants.enderio.base.conduit.ConnectionMode) DyeColor(com.enderio.core.common.util.DyeColor) HashSet(java.util.HashSet) Nonnull(javax.annotation.Nonnull)

Example 3 with Signal

use of crazypants.enderio.base.conduit.redstone.signals.Signal in project EnderIO by SleepyTrousers.

the class InsulatedRedstoneConduit method getNetworkInputs.

@Override
@Nonnull
public Set<Signal> getNetworkInputs(@Nonnull EnumFacing side) {
    if (network != null) {
        network.setNetworkEnabled(false);
    }
    HashSet<Signal> signals = new HashSet<Signal>();
    if (acceptSignalsForDir(side)) {
        int input = getExternalPowerLevel(side);
        if (input > 1) {
            // need to degrade external signals by one as they
            // enter
            BlockPos pos = getBundle().getLocation().offset(side);
            Signal signal = new Signal(pos, side, input - 1, getSignalColor(side));
            signals.add(signal);
        }
    }
    if (network != null) {
        network.setNetworkEnabled(true);
    }
    Map<DyeColor, Signal> res = new HashMap<DyeColor, Signal>();
    for (Signal signal : signals) {
        if (signal != null && (!res.containsKey(signal.getColor()) || signal.getStrength() > res.get(signal.getColor()).getStrength())) {
            res.put(signal.getColor(), signal);
        }
    }
    return new HashSet<Signal>(res.values());
}
Also used : Signal(crazypants.enderio.base.conduit.redstone.signals.Signal) HashMap(java.util.HashMap) BlockPos(net.minecraft.util.math.BlockPos) DyeColor(com.enderio.core.common.util.DyeColor) HashSet(java.util.HashSet) Nonnull(javax.annotation.Nonnull)

Example 4 with Signal

use of crazypants.enderio.base.conduit.redstone.signals.Signal in project EnderIO by SleepyTrousers.

the class RedstoneConduitNetwork method afterChunkUnload.

/**
 * This is a bit of a hack...avoids the network searching for inputs from unloaded chunks by only filtering out the invalid signals from the unloaded chunk.
 *
 * @param conduits
 * @param oldSignals
 */
public void afterChunkUnload(@Nonnull List<IRedstoneConduit> conduits, @Nonnull Multimap<SignalSource, Signal> oldSignals) {
    World world = null;
    for (IRedstoneConduit c : conduits) {
        if (world == null) {
            world = c.getBundle().getBundleworld();
        }
        BlockPos pos = c.getBundle().getLocation();
        if (world.isBlockLoaded(pos)) {
            this.getConduits().add(c);
            c.setNetwork(this);
        }
    }
    signals.clear();
    boolean signalsChanged = false;
    for (Entry<SignalSource, Signal> s : oldSignals.entries()) {
        if (world != null && world.isBlockLoaded(s.getKey().getSource())) {
            signals.put(s.getKey(), s.getValue());
        } else {
            signalsChanged = true;
        }
    }
    if (signalsChanged) {
        // broadcast out a change
        notifyNeigborsOfSignalUpdate();
    }
}
Also used : SignalSource(crazypants.enderio.base.conduit.redstone.signals.SignalSource) Signal(crazypants.enderio.base.conduit.redstone.signals.Signal) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 5 with Signal

use of crazypants.enderio.base.conduit.redstone.signals.Signal in project EnderIO by SleepyTrousers.

the class RedstoneConduitNetwork method signalsString.

String signalsString() {
    StringBuilder sb = new StringBuilder();
    for (Signal s : signals.values()) {
        sb.append("<");
        sb.append(s);
        sb.append(">");
    }
    return sb.toString();
}
Also used : Signal(crazypants.enderio.base.conduit.redstone.signals.Signal)

Aggregations

Signal (crazypants.enderio.base.conduit.redstone.signals.Signal)5 DyeColor (com.enderio.core.common.util.DyeColor)2 HashSet (java.util.HashSet)2 Nonnull (javax.annotation.Nonnull)2 BlockPos (net.minecraft.util.math.BlockPos)2 ConnectionMode (crazypants.enderio.base.conduit.ConnectionMode)1 SignalSource (crazypants.enderio.base.conduit.redstone.signals.SignalSource)1 HashMap (java.util.HashMap)1 World (net.minecraft.world.World)1