Search in sources :

Example 1 with SignalSource

use of crazypants.enderio.base.conduit.redstone.signals.SignalSource 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 2 with SignalSource

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

the class RedstoneConduitNetwork method updateInputsFromConduit.

public void updateInputsFromConduit(@Nonnull IRedstoneConduit con, boolean delayUpdate) {
    BlockPos pos = con.getBundle().getLocation();
    // Make my neighbors update as if we have no signals
    updatingNetwork = true;
    notifyConduitNeighbours(con);
    updatingNetwork = false;
    // Then ask them what inputs they have now
    Set<EnumFacing> externalConnections = con.getExternalConnections();
    for (EnumFacing side : EnumFacing.values()) {
        if (externalConnections.contains(side)) {
            updateInputsForSource(con, new SignalSource(pos, side));
        } else {
            signals.removeAll(new SignalSource(pos, side));
        }
    }
    if (!delayUpdate) {
        // then tell the whole network about the change
        notifyNeigborsOfSignalUpdate();
    }
    if (ConduitConfig.showState.get()) {
        updateActiveState();
    }
}
Also used : SignalSource(crazypants.enderio.base.conduit.redstone.signals.SignalSource) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

SignalSource (crazypants.enderio.base.conduit.redstone.signals.SignalSource)2 BlockPos (net.minecraft.util.math.BlockPos)2 Signal (crazypants.enderio.base.conduit.redstone.signals.Signal)1 EnumFacing (net.minecraft.util.EnumFacing)1 World (net.minecraft.world.World)1