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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
package miscutil.enderio.conduit.gas;
import java.util.List;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.ConduitUtil;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.enderio.conduit.RaytraceResult;
import crazypants.enderio.tool.ToolUtil;
import crazypants.util.BlockCoord;
public abstract class AbstractGasTankConduit
extends AbstractGasConduit
{
protected ConduitGasTank tank = new ConduitGasTank(0);
protected boolean stateDirty = false;
protected long lastEmptyTick = 0L;
protected int numEmptyEvents = 0;
public boolean onBlockActivated(EntityPlayer player, RaytraceResult res, List<RaytraceResult> all)
{
if (player.getCurrentEquippedItem() == null) {
return false;
}
if (ToolUtil.isToolEquipped(player))
{
if (!getBundle().getEntity().getWorldObj().isRemote) {
if ((res != null) && (res.component != null))
{
ForgeDirection connDir = res.component.dir;
ForgeDirection faceHit = ForgeDirection.getOrientation(res.movingObjectPosition.sideHit);
if ((connDir == ForgeDirection.UNKNOWN) || (connDir == faceHit))
{
if (getConnectionMode(faceHit) == ConnectionMode.DISABLED)
{
setConnectionMode(faceHit, getNextConnectionMode(faceHit));
return true;
}
BlockCoord loc = getLocation().getLocation(faceHit);
IGasConduit n = (IGasConduit)ConduitUtil.getConduit(getBundle().getEntity().getWorldObj(), loc.x, loc.y, loc.z, IGasConduit.class);
if (n == null) {
return false;
}
if (!canJoinNeighbour(n)) {
return false;
}
if (!(n instanceof AbstractGasTankConduit)) {
return false;
}
AbstractGasTankConduit neighbour = (AbstractGasTankConduit)n;
if ((neighbour.getGasType() == null) || (getGasType() == null))
{
GasStack type = getGasType();
type = type != null ? type : neighbour.getGasType();
neighbour.setGasTypeOnNetwork(neighbour, type);
setGasTypeOnNetwork(this, type);
}
return ConduitUtil.joinConduits(this, faceHit);
}
if (containsExternalConnection(connDir))
{
setConnectionMode(connDir, getNextConnectionMode(connDir));
}
else if (containsConduitConnection(connDir))
{
GasStack curGasType = null;
if (getTankNetwork() != null) {
curGasType = getTankNetwork().getGasType();
}
ConduitUtil.disconectConduits(this, connDir);
setGasType(curGasType);
}
}
}
return true;
}
return false;
}
private void setGasTypeOnNetwork(AbstractGasTankConduit con, GasStack type)
{
AbstractConduitNetwork<?, ?> n = con.getNetwork();
if (n != null)
{
AbstractGasTankConduitNetwork<?> network = (AbstractGasTankConduitNetwork)n;
network.setGasType(type);
}
}
protected abstract boolean canJoinNeighbour(IGasConduit paramIGasConduit);
public abstract AbstractGasTankConduitNetwork<? extends AbstractGasTankConduit> getTankNetwork();
public void setGasType(GasStack gasType)
{
if ((this.tank.getGas() != null) && (this.tank.getGas().isGasEqual(gasType))) {
return;
}
if (gasType != null) {
gasType = gasType.copy();
} else if (this.tank.getGas() == null) {
return;
}
this.tank.setGas(gasType);
this.stateDirty = true;
}
public ConduitGasTank getTank()
{
return this.tank;
}
public GasStack getGasType()
{
GasStack result = null;
if (getTankNetwork() != null) {
result = getTankNetwork().getGasType();
}
if (result == null) {
result = this.tank.getGas();
}
return result;
}
public boolean canOutputToDir(ForgeDirection dir)
{
if (super.canOutputToDir(dir))
{
IGasHandler ext = getExternalHandler(dir);
return (ext != null) && (ext.canReceiveGas(dir.getOpposite(), this.tank.getGasType()));
}
return false;
}
protected abstract void updateTank();
public void readFromNBT(NBTTagCompound nbtRoot, short nbtVersion)
{
super.readFromNBT(nbtRoot, nbtVersion);
updateTank();
if (nbtRoot.hasKey("tank"))
{
GasStack gas = GasStack.readFromNBT(nbtRoot.getCompoundTag("tank"));
this.tank.setGas(gas);
}
else
{
this.tank.setGas(null);
}
}
public void writeToNBT(NBTTagCompound nbtRoot)
{
super.writeToNBT(nbtRoot);
GasStack gt = getGasType();
if (GasUtil.isGasValid(gt))
{
updateTank();
gt = gt.copy();
gt.amount = this.tank.getStored();
nbtRoot.setTag("tank", gt.write(new NBTTagCompound()));
}
}
}
|