Search in sources :

Example 6 with DyeColor

use of com.enderio.core.common.util.DyeColor in project EnderIO by SleepyTrousers.

the class BundledCombinedSignal method hashCode.

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    for (DyeColor color : DyeColor.values()) {
        result = prime * result + bundle.get(color).hashCode();
    }
    return result;
}
Also used : DyeColor(com.enderio.core.common.util.DyeColor)

Example 7 with DyeColor

use of com.enderio.core.common.util.DyeColor 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 8 with DyeColor

use of com.enderio.core.common.util.DyeColor 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 9 with DyeColor

use of com.enderio.core.common.util.DyeColor in project EnderIO by SleepyTrousers.

the class InsulatedRedstoneConduit method onBlockActivated.

@Override
public boolean onBlockActivated(@Nonnull EntityPlayer player, @Nonnull EnumHand hand, @Nonnull RaytraceResult res, @Nonnull List<RaytraceResult> all) {
    World world = getBundle().getEntity().getWorld();
    if (!world.isRemote) {
        DyeColor col = DyeColor.getColorFromDye(player.getHeldItem(hand));
        if (col != null && res.component != null) {
            setSignalColor(res.component.dir, col);
            return true;
        } else if (ToolUtil.isToolEquipped(player, hand)) {
            if (res != null && res.component != null) {
                EnumFacing connDir = res.component.dir;
                EnumFacing faceHit = res.movingObjectPosition.sideHit;
                boolean colorHit = false;
                if (all != null && containsExternalConnection(connDir)) {
                    for (RaytraceResult rtr : all) {
                        if (rtr != null && rtr.component != null && COLOR_CONTROLLER_ID.equals(rtr.component.data)) {
                            colorHit = true;
                        }
                    }
                }
                if (colorHit) {
                    setSignalColor(connDir, DyeColor.getNext(getSignalColor(connDir)));
                    return true;
                } else if (connDir == null || connDir == faceHit) {
                    BlockPos pos = getBundle().getLocation().offset(faceHit);
                    Block id = world.getBlockState(pos).getBlock();
                    if (id == ConduitRegistry.getConduitModObjectNN().getBlock()) {
                        IRedstoneConduit neighbour = ConduitUtil.getConduit(world, pos.getX(), pos.getY(), pos.getZ(), IRedstoneConduit.class);
                        if (neighbour != null && neighbour.getConnectionMode(faceHit.getOpposite()) == ConnectionMode.DISABLED) {
                            neighbour.setConnectionMode(faceHit.getOpposite(), ConnectionMode.NOT_SET);
                        }
                        setConnectionMode(faceHit, ConnectionMode.NOT_SET);
                        return ConduitUtil.connectConduits(this, faceHit);
                    }
                    forceConnectionMode(faceHit, ConnectionMode.IN_OUT);
                    return true;
                } else if (externalConnections.contains(connDir)) {
                    if (network != null) {
                        network.destroyNetwork();
                    }
                    externalConnectionRemoved(connDir);
                    forceConnectionMode(connDir, ConnectionMode.DISABLED);
                    return true;
                } else if (containsConduitConnection(connDir)) {
                    BlockPos pos = getBundle().getLocation().offset(connDir);
                    IRedstoneConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().getWorld(), pos.getX(), pos.getY(), pos.getZ(), IRedstoneConduit.class);
                    if (neighbour != null) {
                        if (network != null) {
                            network.destroyNetwork();
                        }
                        if (neighbour.getNetwork() != null) {
                            neighbour.getNetwork().destroyNetwork();
                        }
                        neighbour.conduitConnectionRemoved(connDir.getOpposite());
                        conduitConnectionRemoved(connDir);
                        neighbour.connectionsChanged();
                        connectionsChanged();
                        updateNetwork();
                        neighbour.updateNetwork();
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) DyeColor(com.enderio.core.common.util.DyeColor) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult)

Example 10 with DyeColor

use of com.enderio.core.common.util.DyeColor in project EnderIO by SleepyTrousers.

the class InsulatedRedstoneConduit method writeToNBT.

@Override
public void writeToNBT(@Nonnull NBTTagCompound nbtRoot) {
    super.writeToNBT(nbtRoot);
    if (forcedConnections.size() >= 0) {
        byte[] modes = new byte[6];
        int i = 0;
        for (EnumFacing dir : EnumFacing.VALUES) {
            ConnectionMode mode = forcedConnections.get(dir);
            if (mode != null) {
                modes[i] = (byte) mode.ordinal();
            } else {
                modes[i] = -1;
            }
            i++;
        }
        nbtRoot.setByteArray("forcedConnections", modes);
    }
    if (signalColors.size() >= 0) {
        byte[] modes = new byte[6];
        int i = 0;
        for (EnumFacing dir : EnumFacing.VALUES) {
            DyeColor col = signalColors.get(dir);
            if (col != null) {
                modes[i] = (byte) col.ordinal();
            } else {
                modes[i] = -1;
            }
            i++;
        }
        nbtRoot.setByteArray("signalColors", modes);
    }
    if (signalStrengths.size() >= 0) {
        byte[] modes = new byte[6];
        int i = 0;
        for (EnumFacing dir : EnumFacing.VALUES) {
            boolean isStrong = isOutputStrong(dir);
            if (isStrong) {
                modes[i] = 1;
            } else {
                modes[i] = 0;
            }
            i++;
        }
        nbtRoot.setByteArray("signalStrengths", modes);
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) ConnectionMode(crazypants.enderio.base.conduit.ConnectionMode) DyeColor(com.enderio.core.common.util.DyeColor)

Aggregations

DyeColor (com.enderio.core.common.util.DyeColor)10 EnumFacing (net.minecraft.util.EnumFacing)5 ConnectionMode (crazypants.enderio.base.conduit.ConnectionMode)2 Signal (crazypants.enderio.base.conduit.redstone.signals.Signal)2 HashSet (java.util.HashSet)2 Nonnull (javax.annotation.Nonnull)2 BlockPos (net.minecraft.util.math.BlockPos)2 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)1 Offset (crazypants.enderio.base.conduit.geom.Offset)1 IItemFilter (crazypants.enderio.base.filter.IItemFilter)1 RedstoneControlMode (crazypants.enderio.base.machine.modes.RedstoneControlMode)1 PacketExtractMode (crazypants.enderio.conduits.network.PacketExtractMode)1 PacketItemConduitFilter (crazypants.enderio.conduits.network.PacketItemConduitFilter)1 CapturedMob (crazypants.enderio.util.CapturedMob)1 HashMap (java.util.HashMap)1 Block (net.minecraft.block.Block)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 World (net.minecraft.world.World)1