Search in sources :

Example 1 with IConnector

use of micdoodle8.mods.galacticraft.api.transmission.tile.IConnector in project Galacticraft by micdoodle8.

the class TileBaseConductor method getAdjacentConnections.

@Override
public TileEntity[] getAdjacentConnections() {
    /**
     * Cache the adjacentConnections.
     */
    if (this.adjacentConnections == null) {
        this.adjacentConnections = new TileEntity[6];
        BlockVec3 thisVec = new BlockVec3(this);
        for (int i = 0; i < 6; i++) {
            EnumFacing side = EnumFacing.getFront(i);
            TileEntity tileEntity = thisVec.getTileEntityOnSide(this.worldObj, side);
            if (tileEntity instanceof IConnector) {
                if (((IConnector) tileEntity).canConnect(side.getOpposite(), NetworkType.POWER)) {
                    this.adjacentConnections[i] = tileEntity;
                }
            }
        }
    }
    return this.adjacentConnections;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IConnector(micdoodle8.mods.galacticraft.api.transmission.tile.IConnector) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 2 with IConnector

use of micdoodle8.mods.galacticraft.api.transmission.tile.IConnector in project Galacticraft by micdoodle8.

the class OxygenUtil method getAdjacentFluidConnections.

public static TileEntity[] getAdjacentFluidConnections(TileEntity tile, boolean ignoreConnect) {
    TileEntity[] adjacentConnections = new TileEntity[EnumFacing.VALUES.length];
    boolean isMekLoaded = EnergyConfigHandler.isMekanismLoaded();
    BlockVec3 thisVec = new BlockVec3(tile);
    for (EnumFacing direction : EnumFacing.VALUES) {
        TileEntity tileEntity = thisVec.getTileEntityOnSide(tile.getWorld(), direction);
        if (tileEntity instanceof IFluidHandler) {
            if (ignoreConnect || !(tileEntity instanceof IConnector) || ((IConnector) tileEntity).canConnect(direction.getOpposite(), NetworkType.FLUID)) {
                adjacentConnections[direction.ordinal()] = tileEntity;
            }
        }
    // else if (isMekLoaded)
    // {
    // if (tileEntity instanceof ITubeConnection && (!(tileEntity instanceof IGasTransmitter) || TransmissionType.checkTransmissionType(tileEntity, TransmissionType.GAS, tileEntity)))
    // {
    // if (((ITubeConnection) tileEntity).canTubeConnect(direction))
    // {
    // adjacentConnections[direction.ordinal()] = tileEntity;
    // }
    // }
    // }
    }
    return adjacentConnections;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IConnector(micdoodle8.mods.galacticraft.api.transmission.tile.IConnector) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 3 with IConnector

use of micdoodle8.mods.galacticraft.api.transmission.tile.IConnector in project Galacticraft by micdoodle8.

the class EnergyUtil method getAdjacentPowerConnections.

public static TileEntity[] getAdjacentPowerConnections(TileEntity tile) {
    final TileEntity[] adjacentConnections = new TileEntity[6];
    BlockVec3 thisVec = new BlockVec3(tile);
    for (EnumFacing direction : EnumFacing.VALUES) {
        if (tile instanceof IConductor && !((IConductor) tile).canConnect(direction, NetworkType.POWER)) {
            continue;
        }
        TileEntity tileEntity = thisVec.getTileEntityOnSide(tile.getWorld(), direction);
        if (tileEntity == null) {
            continue;
        }
        if (tileEntity instanceof IConnector) {
            if (((IConnector) tileEntity).canConnect(direction.getOpposite(), NetworkType.POWER)) {
                adjacentConnections[direction.ordinal()] = tileEntity;
            }
            continue;
        }
        if (isMekLoaded && (tileEntity instanceof IStrictEnergyAcceptor || tileEntity instanceof ICableOutputter)) {
            // Do not connect GC wires directly to Mek Universal Cables
            try {
                if (clazzMekCable != null && clazzMekCable.isInstance(tileEntity)) {
                    continue;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (tileEntity instanceof IStrictEnergyAcceptor && ((IStrictEnergyAcceptor) tileEntity).canReceiveEnergy(direction.getOpposite())) {
                adjacentConnections[direction.ordinal()] = tileEntity;
            } else if (tileEntity instanceof ICableOutputter && ((ICableOutputter) tileEntity).canOutputTo(direction.getOpposite())) {
                adjacentConnections[direction.ordinal()] = tileEntity;
            }
            continue;
        }
        if (isBCReallyLoaded) {
            // Do not connect GC wires directly to BC pipes of any type
            try {
                if (clazzPipeTile.isInstance(tileEntity)) {
                    continue;
                }
            } catch (Exception e) {
            }
        }
        if (isRFLoaded && tileEntity instanceof IEnergyConnection) {
            if (isRF2Loaded && (tileEntity instanceof IEnergyProvider || tileEntity instanceof IEnergyReceiver) || isRF1Loaded && tileEntity instanceof IEnergyHandler || clazzRailcraftEngine != null && clazzRailcraftEngine.isInstance(tileEntity)) {
                // Do not connect GC wires directly to power conduits
                if (clazzEnderIOCable != null && clazzEnderIOCable.isInstance(tileEntity)) {
                    continue;
                }
                if (clazzMFRRednetEnergyCable != null && clazzMFRRednetEnergyCable.isInstance(tileEntity)) {
                    continue;
                }
                if (((IEnergyConnection) tileEntity).canConnectEnergy(direction.getOpposite())) {
                    adjacentConnections[direction.ordinal()] = tileEntity;
                }
            }
            continue;
        }
        if (isIC2Loaded) {
            if (tileEntity instanceof IEnergyConductor) {
                continue;
            }
            if (!tile.getWorld().isRemote) {
                Object IC2tile = tileEntity;
                BlockPos checkingIC2 = thisVec.toBlockPos().offset(direction);
                try {
                    IC2tile = EnergyNet.instance.getSubTile(tile.getWorld(), checkingIC2);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (IC2tile instanceof IEnergyAcceptor && tile instanceof IEnergyEmitter) {
                    if (((IEnergyAcceptor) IC2tile).acceptsEnergyFrom((IEnergyEmitter) tile, direction.getOpposite())) {
                        adjacentConnections[direction.ordinal()] = tileEntity;
                    }
                    continue;
                }
                if (IC2tile instanceof IEnergyEmitter && tile instanceof IEnergyAcceptor) {
                    if (((IEnergyEmitter) IC2tile).emitsEnergyTo((IEnergyAcceptor) tile, direction.getOpposite())) {
                        adjacentConnections[direction.ordinal()] = tileEntity;
                    }
                    continue;
                }
            } else {
                try {
                    Class clazz = tileEntity.getClass();
                    if (clazz.getName().startsWith("ic2")) {
                        // Special case: IC2's transformers don't seem to setup their sink and source directions in Energy clientside
                        if (clazz.getName().startsWith("ic2.core.block.wiring.TileEntityTransformer")) {
                            adjacentConnections[direction.ordinal()] = tileEntity;
                            continue;
                        }
                        Field energyField = null;
                        fieldLoop: while (energyField == null && clazz != null) {
                            for (Field f : clazz.getDeclaredFields()) {
                                if (f.getName().equals("energy")) {
                                    energyField = f;
                                    break fieldLoop;
                                }
                            }
                            clazz = clazz.getSuperclass();
                        }
                        energyField.setAccessible(true);
                        Object energy = energyField.get(tileEntity);
                        Set<EnumFacing> connections;
                        if (tile instanceof IEnergyEmitter) {
                            connections = (Set<EnumFacing>) energy.getClass().getMethod("getSinkDirs").invoke(energy);
                            if (connections.contains(direction.getOpposite())) {
                                adjacentConnections[direction.ordinal()] = tileEntity;
                                continue;
                            }
                        }
                        if (tile instanceof IEnergyAcceptor) {
                            connections = (Set<EnumFacing>) energy.getClass().getMethod("getSourceDirs").invoke(energy);
                            if (connections.contains(direction.getOpposite())) {
                                adjacentConnections[direction.ordinal()] = tileEntity;
                                continue;
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return adjacentConnections;
}
Also used : IEnergyConnection(cofh.api.energy.IEnergyConnection) EnumFacing(net.minecraft.util.EnumFacing) TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) Field(java.lang.reflect.Field) IEnergyProvider(cofh.api.energy.IEnergyProvider) ICableOutputter(mekanism.api.energy.ICableOutputter) IStrictEnergyAcceptor(mekanism.api.energy.IStrictEnergyAcceptor) IEnergyHandler(cofh.api.energy.IEnergyHandler) IConnector(micdoodle8.mods.galacticraft.api.transmission.tile.IConnector) BlockPos(net.minecraft.util.BlockPos) IEnergyReceiver(cofh.api.energy.IEnergyReceiver) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Aggregations

IConnector (micdoodle8.mods.galacticraft.api.transmission.tile.IConnector)3 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 TileEntity (net.minecraft.tileentity.TileEntity)3 EnumFacing (net.minecraft.util.EnumFacing)3 IEnergyConnection (cofh.api.energy.IEnergyConnection)1 IEnergyHandler (cofh.api.energy.IEnergyHandler)1 IEnergyProvider (cofh.api.energy.IEnergyProvider)1 IEnergyReceiver (cofh.api.energy.IEnergyReceiver)1 Field (java.lang.reflect.Field)1 ICableOutputter (mekanism.api.energy.ICableOutputter)1 IStrictEnergyAcceptor (mekanism.api.energy.IStrictEnergyAcceptor)1 IConductor (micdoodle8.mods.galacticraft.api.transmission.tile.IConductor)1 BlockPos (net.minecraft.util.BlockPos)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1