aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/enderio/conduit/gas/GasUtil.java
blob: fcc02ca9422efafd1aead7f42b9979069e650216 (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
70
71
72
73
74
75
76
77
78
79
80
81
package crazypants.enderio.conduit.gas;

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

public final class GasUtil
{
  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 = ((ModContainer)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;
  }
}