use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.
the class PartWireBundled method propagate.
private void propagate(int color, byte[][] nValues) {
int maxSignal = 0;
int[] neighborLevel = new int[7];
boolean[] isWire = new boolean[7];
PartWireBase.PROPAGATING = true;
if (internalConnections > 0) {
for (WireFace location : WireFace.VALUES) {
if (connectsInternal(location)) {
isWire[location.ordinal()] = true;
neighborLevel[location.ordinal()] = WireUtils.getBundledWireLevel(getContainer(), location, color);
}
}
}
for (EnumFacing facing : EnumFacing.VALUES) {
if (connectsExternal(facing)) {
if (nValues[facing.ordinal()] != null) {
int v = nValues[facing.ordinal()][color] << 8;
if (v != 0) {
neighborLevel[facing.ordinal()] = v | 0xFF;
}
} else {
IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), getPos().offset(facing));
if (container != null) {
isWire[facing.ordinal()] = true;
neighborLevel[facing.ordinal()] = WireUtils.getBundledWireLevel(container, location, color);
}
}
} else if (connectsCorner(facing)) {
BlockPos cornerPos = getPos().offset(facing).offset(location.facing);
IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), cornerPos);
if (container != null) {
isWire[facing.ordinal()] = true;
neighborLevel[facing.ordinal()] = WireUtils.getBundledWireLevel(container, WireFace.get(facing.getOpposite()), color);
}
}
}
PartWireBase.PROPAGATING = false;
int newSignal = 0;
for (int j = 0; j < 7; j++) {
if (neighborLevel[j] > maxSignal) {
maxSignal = neighborLevel[j];
}
if (!isWire[j] && neighborLevel[j] > newSignal) {
newSignal = neighborLevel[j];
}
}
if (DEBUG) {
System.out.println("[" + color + "] Levels: " + Arrays.toString(neighborLevel));
}
if (maxSignal > signalLevel[color] && maxSignal > 1) {
newSignal = maxSignal - 1;
if ((newSignal & 0xFF) == 0 || (newSignal & 0xFF) == 0xFF) {
newSignal = 0;
}
}
if (newSignal == signalLevel[color]) {
return;
}
signalLevel[color] = newSignal;
signalValue[color] = (byte) (newSignal >> 8);
if (newSignal == 0) {
for (WireFace nLoc : WireFace.VALUES) {
if (connectsInternal(nLoc)) {
if (neighborLevel[nLoc.ordinal()] > 0) {
WireUtils.getWire(getContainer(), nLoc).onSignalChanged(color);
}
} else if (nLoc != WireFace.CENTER) {
EnumFacing facing = nLoc.facing;
if (connectsExternal(facing)) {
IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), getPos().offset(facing));
if (container == null || WireUtils.getWire(container, location) == null || neighborLevel[facing.ordinal()] > 0) {
propagateNotify(facing, color);
}
} else if (connectsCorner(facing)) {
if (neighborLevel[facing.ordinal()] > 0) {
propagateNotifyCorner(location.facing, facing, color);
}
}
}
}
} else {
for (WireFace nLoc : WireFace.VALUES) {
if (neighborLevel[nLoc.ordinal()] < newSignal - 1 || neighborLevel[nLoc.ordinal()] > (newSignal + 1)) {
if (connectsInternal(nLoc)) {
WireUtils.getWire(getContainer(), nLoc).onSignalChanged(color);
} else if (nLoc != WireFace.CENTER) {
EnumFacing facing = nLoc.facing;
if (connectsExternal(facing)) {
propagateNotify(facing, color);
} else if (connectsCorner(facing)) {
propagateNotifyCorner(location.facing, facing, color);
}
}
}
}
}
finishPropagation();
}
Aggregations