aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/enderio/conduit/GregTech/GtUtil.java
blob: 16408ca88c9bd7c013f11b7630730b93adde72c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package miscutil.enderio.conduit.GregTech;

import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasHandler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.common.Loader;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.config.Config;
import crazypants.util.BlockCoord;

public final class GtUtil {

  private static boolean useCheckPerformed = false;
  private static boolean isGasConduitEnabled = false;

  public static boolean isGasConduitEnabled() {
    if (!useCheckPerformed) {
      String configOption = Config.isGasConduitEnabled;
      if (configOption.equalsIgnoreCase("auto")) {
        isGasConduitEnabled = Loader.isModLoaded("Mekanism");
        if (isGasConduitEnabled) {
          isGasConduitEnabled = Loader.instance().getIndexedModList().get("Mekanism").getVersion().startsWith("7");
        }
      } else if (configOption.equalsIgnoreCase("true")) {
        isGasConduitEnabled = true;
      } else {
        isGasConduitEnabled = false;
      }
      useCheckPerformed = true;
    }
    return isGasConduitEnabled;
  }

  public static IGasHandler getExternalGasHandler(IBlockAccess world, BlockCoord bc) {
    IGasHandler con = getGasHandler(world, bc);
    return (con != null && !(con instanceof IConduitBundle)) ? con : null;
  }

  public static IGasHandler getGasHandler(IBlockAccess world, BlockCoord bc) {
    return getGasHandler(world, bc.x, bc.y, bc.z);
  }

  public static IGasHandler getGasHandler(IBlockAccess world, int x, int y, int z) {
    TileEntity te = world.getTileEntity(x, y, z);
    return getGasHandler(te);
  }

  public static IGasHandler getGasHandler(TileEntity te) {
    if(te instanceof IGasHandler) {
      return (IGasHandler) te;
    }
    return null;
  }

  public static boolean isGasValid(GasStack gas) {
    if(gas != null) {
      String name = gas.getGas().getLocalizedName();
      if(name != null && !name.trim().isEmpty()) {
        return true;
      }
    }
    return false;
  }

  private GtUtil() {
  }

}