Search in sources :

Example 1 with IRedNetNetworkContainer

use of powercrystals.minefactoryreloaded.api.rednet.IRedNetNetworkContainer 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]);
            }
        }
    }
}
Also used : IRedNetNetworkContainer(powercrystals.minefactoryreloaded.api.rednet.IRedNetNetworkContainer) Noop(powercrystals.minefactoryreloaded.circuits.Noop) BlockPosition(powercrystals.core.position.BlockPosition) Block(net.minecraft.block.Block) IConnectableRedNet(powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet)

Aggregations

Block (net.minecraft.block.Block)1 BlockPosition (powercrystals.core.position.BlockPosition)1 IConnectableRedNet (powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet)1 IRedNetNetworkContainer (powercrystals.minefactoryreloaded.api.rednet.IRedNetNetworkContainer)1 Noop (powercrystals.minefactoryreloaded.circuits.Noop)1