use of powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet in project MineFactoryReloaded by powercrystals.
the class TileEntityRedNetCable method getConnectionState.
public RedNetConnectionType getConnectionState(ForgeDirection side) {
BlockPosition bp = new BlockPosition(this);
bp.orientation = side;
bp.moveForwards(1);
int blockId = worldObj.getBlockId(bp.x, bp.y, bp.z);
Block b = Block.blocksList[blockId];
if (// block doesn't exist (air) - never connect
b == null) {
return RedNetConnectionType.None;
} else if (// cables - always connect
blockId == MineFactoryReloadedCore.rednetCableBlock.blockID) {
return RedNetConnectionType.CableAll;
} else if (// cable-only, and not a cable - don't connct
_mode == 2) {
return RedNetConnectionType.None;
} else if (b instanceof IRedNetNoConnection) {
return RedNetConnectionType.None;
} else if (// API node - let them figure it out
b instanceof IConnectableRedNet) {
return ((IConnectableRedNet) b).getConnectionType(worldObj, bp.x, bp.y, bp.z, side.getOpposite());
} else if (_mode == 0 && (blockId <= _maxVanillaBlockId && !_connectionWhitelist.contains(blockId)) || _connectionBlackList.contains(blockId) || b.isAirBlock(worldObj, bp.x, bp.y, bp.z)) // standard connection logic, then figure out if we shouldn't connect
// mode 1 will skip this
{
return RedNetConnectionType.None;
} else if (// mode 1 forces plate mode for weak power
_mode == 0 && b.isBlockSolidOnSide(worldObj, bp.x, bp.y, bp.z, side.getOpposite())) {
return RedNetConnectionType.CableSingle;
} else {
return RedNetConnectionType.PlateSingle;
}
}
use of powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet in project MineFactoryReloaded by powercrystals.
the class TileEntityRedNetLogic method updateEntity.
@Override
public void updateEntity() {
if (worldObj.isRemote) {
return;
}
int[][] lastOuput = new int[6][];
for (int i = 0; i < 6; i++) {
lastOuput[i] = _buffers[i + 6];
_buffers[i + 6] = new int[16];
}
for (int circuitNum = 0; circuitNum < _circuits.length; circuitNum++) {
if (_circuits[circuitNum] instanceof Noop) {
continue;
}
int[] input = new int[_circuits[circuitNum].getInputCount()];
for (int pinNum = 0; pinNum < input.length; pinNum++) {
input[pinNum] = _buffers[_pinMappingInputs[circuitNum][pinNum].buffer][_pinMappingInputs[circuitNum][pinNum].pin];
}
int[] output = _circuits[circuitNum].recalculateOutputValues(worldObj.getTotalWorldTime(), input);
for (int pinNum = 0; pinNum < output.length; pinNum++) {
_buffers[_pinMappingOutputs[circuitNum][pinNum].buffer][_pinMappingOutputs[circuitNum][pinNum].pin] = output[pinNum];
}
}
for (int i = 0; i < 6; i++) {
if (!Arrays.areEqual(lastOuput[i], _buffers[i + 6])) {
BlockPosition bp = new BlockPosition(this);
bp.orientation = ForgeDirection.VALID_DIRECTIONS[i];
bp.moveForwards(1);
Block b = Block.blocksList[worldObj.getBlockId(bp.x, bp.y, bp.z)];
if (b instanceof IRedNetNetworkContainer) {
((IRedNetNetworkContainer) b).updateNetwork(worldObj, bp.x, bp.y, bp.z);
} else if (b instanceof IConnectableRedNet) {
((IConnectableRedNet) b).onInputsChanged(worldObj, bp.x, bp.y, bp.z, bp.orientation.getOpposite(), _buffers[i + 6]);
}
}
}
}
Aggregations