Search in sources :

Example 1 with ICustomPipeConnection

use of buildcraft.api.transport.pipe.ICustomPipeConnection in project BuildCraft by BuildCraft.

the class Pipe method updateConnections.

private void updateConnections() {
    if (holder.getPipeWorld().isRemote) {
        return;
    }
    updateMarked = false;
    EnumMap<EnumFacing, Float> old = connected.clone();
    connected.clear();
    types.clear();
    textures.clear();
    for (EnumFacing facing : EnumFacing.VALUES) {
        PipePluggable plug = getHolder().getPluggable(facing);
        if (plug != null && plug.isBlocking()) {
            continue;
        }
        TileEntity oTile = getHolder().getNeighbourTile(facing);
        if (oTile == null) {
            continue;
        }
        IPipe oPipe = getHolder().getNeighbourPipe(facing);
        if (oPipe != null) {
            PipeBehaviour oBehaviour = oPipe.getBehaviour();
            if (oBehaviour == null) {
                continue;
            }
            PipePluggable oPlug = oTile.getCapability(PipeApi.CAP_PLUG, facing.getOpposite());
            if (oPlug == null || !oPlug.isBlocking()) {
                if (canPipesConnect(facing, this, oPipe)) {
                    connected.put(facing, DEFAULT_CONNECTION_DISTANCE);
                    types.put(facing, ConnectedType.PIPE);
                    textures.put(facing, behaviour.getTextureIndex(facing));
                }
                continue;
            }
        }
        BlockPos nPos = holder.getPipePos().offset(facing);
        IBlockState neighbour = holder.getPipeWorld().getBlockState(nPos);
        ICustomPipeConnection cust = PipeConnectionAPI.getCustomConnection(neighbour.getBlock());
        if (cust == null) {
            cust = DefaultPipeConnection.INSTANCE;
        }
        float ext = DEFAULT_CONNECTION_DISTANCE + cust.getExtension(holder.getPipeWorld(), nPos, facing.getOpposite(), neighbour);
        if (behaviour.canConnect(facing, oTile) & flow.canConnect(facing, oTile)) {
            connected.put(facing, ext);
            types.put(facing, ConnectedType.TILE);
            textures.put(facing, behaviour.getTextureIndex(facing));
        }
    }
    if (!old.equals(connected)) {
        for (EnumFacing face : EnumFacing.VALUES) {
            boolean o = old.containsKey(face);
            boolean n = connected.containsKey(face);
            if (o != n) {
                IPipe oPipe = getHolder().getNeighbourPipe(face);
                if (oPipe != null) {
                    oPipe.markForUpdate();
                }
            }
        }
    }
    getHolder().scheduleNetworkUpdate(PipeMessageReceiver.BEHAVIOUR);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) BlockPos(net.minecraft.util.math.BlockPos) ICustomPipeConnection(buildcraft.api.transport.pipe.ICustomPipeConnection) IPipe(buildcraft.api.transport.pipe.IPipe) PipeBehaviour(buildcraft.api.transport.pipe.PipeBehaviour)

Aggregations

ICustomPipeConnection (buildcraft.api.transport.pipe.ICustomPipeConnection)1 IPipe (buildcraft.api.transport.pipe.IPipe)1 PipeBehaviour (buildcraft.api.transport.pipe.PipeBehaviour)1 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)1 IBlockState (net.minecraft.block.state.IBlockState)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1