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