aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/enderio/conduit/GregTech/AbstractGtTankConduitNetwork.java
blob: 8cd720fa18b0123ffe0dbffd0467408ff0ec83f4 (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
package miscutil.enderio.conduit.GregTech;

import mekanism.api.gas.GasStack;
import crazypants.enderio.conduit.AbstractConduitNetwork;

public class AbstractGtTankConduitNetwork<T extends AbstractGtTankConduit> extends AbstractConduitNetwork<IGtConduit, T> {

  protected GasStack gasType;

  protected AbstractGtTankConduitNetwork(Class<T> cl) {
    super(cl);
  }

  public GasStack getGasType() {
    return gasType;
  }

  @Override
  public Class<IGtConduit> getBaseConduitType() {
    return IGtConduit.class;
  }

  @Override
  public void addConduit(T con) {
    super.addConduit(con);
    con.setGasType(gasType);
  }

  public boolean setGasType(GasStack newType) {
    if(gasType != null && gasType.isGasEqual(newType)) {
      return false;
    }
    if(newType != null) {
      gasType = newType.copy();
      gasType.amount = 0;
    } else {
      gasType = null;
    }
    for (AbstractGtTankConduit conduit : conduits) {
      conduit.setGasType(gasType);
    }
    return true;
  }

  public boolean canAcceptGas(GasStack acceptable) {
    return areGassCompatable(gasType, acceptable);
  }

  public static boolean areGassCompatable(GasStack a, GasStack b) {
    if(a == null || b == null) {
      return true;
    }
    return a.isGasEqual(b);
  }

  public int getTotalVolume() {
    int totalVolume = 0;
    for (T con : conduits) {
      totalVolume += con.getTank().getStored();
    }
    return totalVolume;
  }

}