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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
package goodgenerator.blocks.tileEntity;
import java.util.ArrayList;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import goodgenerator.crossmod.thaumcraft.LargeEssentiaEnergyData;
import thaumcraft.api.ThaumcraftApiHelper;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.aspects.IAspectContainer;
import thaumcraft.api.aspects.IEssentiaTransport;
public class MTEEssentiaHatch extends TileEntity implements IAspectContainer, IEssentiaTransport {
private Aspect mLocked;
private AspectList current = new AspectList();
public int mState = 0;
public void setLockedAspect(Aspect aAspect) {
this.mLocked = aAspect;
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
this.mLocked = Aspect.getAspect(tagCompound.getString("mLocked"));
this.mState = tagCompound.getInteger("mState");
current = new AspectList();
NBTTagList tlist = tagCompound.getTagList("Aspects", 10);
for (int j = 0; j < tlist.tagCount(); ++j) {
NBTTagCompound rs = tlist.getCompoundTagAt(j);
if (rs.hasKey("key")) {
current.add(Aspect.getAspect(rs.getString("key")), rs.getInteger("amount"));
}
}
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tagCompound.setString("mLocked", this.mLocked == null ? "" : this.mLocked.getTag());
tagCompound.setInteger("mState", mState);
NBTTagList tlist = new NBTTagList();
Aspect[] aspectA = current.getAspects();
for (Aspect aspect : aspectA) {
if (aspect != null) {
NBTTagCompound f = new NBTTagCompound();
f.setString("key", aspect.getTag());
f.setInteger("amount", current.getAmount(aspect));
tlist.appendTag(f);
}
}
tagCompound.setTag("Aspects", tlist);
}
public final Packet getDescriptionPacket() {
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt);
}
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
NBTTagCompound nbt = pkt.func_148857_g();
readFromNBT(nbt);
}
public void markDirty() {
super.markDirty();
if (this.worldObj.isRemote) {
return;
}
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
@Override
public void updateEntity() {
fillfrompipe();
}
public void fillfrompipe() {
if (getEssentiaAmount(null) >= 1000) return;
TileEntity[] te = new TileEntity[ForgeDirection.VALID_DIRECTIONS.length];
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
te[i] = ThaumcraftApiHelper.getConnectableTile(
this.worldObj,
this.xCoord,
this.yCoord,
this.zCoord,
ForgeDirection.VALID_DIRECTIONS[i]);
if (te[i] != null) {
IEssentiaTransport pipe = (IEssentiaTransport) te[i];
if (!pipe.canOutputTo(ForgeDirection.VALID_DIRECTIONS[i])) {
continue;
}
if ((pipe.getEssentiaType(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()) != null)
&& (pipe.getSuctionAmount(ForgeDirection.VALID_DIRECTIONS[i])
< getSuctionAmount(ForgeDirection.VALID_DIRECTIONS[i]))) {
Aspect readyInput = pipe.getEssentiaType(ForgeDirection.VALID_DIRECTIONS[i].getOpposite());
int type = LargeEssentiaEnergyData.getAspectTypeIndex(readyInput);
if (type != -1 && (mState & (1 << type)) == 0) continue;
if (readyInput.equals(mLocked)) {
addToContainer(mLocked, pipe.takeEssentia(mLocked, 1, ForgeDirection.VALID_DIRECTIONS[i]));
}
if (mLocked == null) addToContainer(
pipe.getEssentiaType(ForgeDirection.VALID_DIRECTIONS[i]),
pipe.takeEssentia(
pipe.getEssentiaType(ForgeDirection.VALID_DIRECTIONS[i]),
1,
ForgeDirection.VALID_DIRECTIONS[i]));
}
}
}
}
@Override
public AspectList getAspects() {
return current;
}
@Override
public void setAspects(AspectList aspectList) {
this.current.add(aspectList);
}
@Override
public boolean doesContainerAccept(Aspect aspect) {
int type = LargeEssentiaEnergyData.getAspectTypeIndex(aspect);
if (type != -1 && (mState & (1 << type)) == 0) return false;
return (mLocked == null || mLocked.equals(aspect)) && getEssentiaAmount(null) <= 1000;
}
@Override
public int addToContainer(Aspect aspect, int i) {
int type = LargeEssentiaEnergyData.getAspectTypeIndex(aspect);
if (type != -1 && (mState & (1 << type)) == 0) return i;
int ready = Math.min(1000 - getEssentiaAmount(null), i);
if ((mLocked == null || mLocked.equals(aspect)) && ready > 0) {
current.add(aspect, ready);
this.markDirty();
return i - ready;
}
this.markDirty();
return i;
}
@Override
public boolean takeFromContainer(Aspect aspect, int i) {
return false;
}
@Override
public boolean takeFromContainer(AspectList aspectList) {
return false;
}
@Override
public boolean doesContainerContainAmount(Aspect aspect, int i) {
return current.aspects.containsKey(aspect) && i <= current.getAmount(aspect);
}
@Override
public boolean doesContainerContain(AspectList aspectList) {
ArrayList<Boolean> ret = new ArrayList<Boolean>();
for (Aspect a : aspectList.aspects.keySet()) ret.add(current.aspects.containsKey(a));
return !ret.contains(false);
}
@Override
public int containerContains(Aspect aspect) {
return current.aspects.containsKey(aspect) ? current.getAmount(aspect) : 0;
}
@Override
public boolean isConnectable(ForgeDirection forgeDirection) {
return true;
}
@Override
public boolean canInputFrom(ForgeDirection forgeDirection) {
return true;
}
@Override
public boolean canOutputTo(ForgeDirection forgeDirection) {
return false;
}
@Override
public void setSuction(Aspect aspect, int i) {}
@Override
public Aspect getSuctionType(ForgeDirection forgeDirection) {
return this.mLocked;
}
@Override
public int getSuctionAmount(ForgeDirection forgeDirection) {
return 256;
}
@Override
public int takeEssentia(Aspect aspect, int i, ForgeDirection forgeDirection) {
return 0;
}
@Override
public int addEssentia(Aspect aspect, int i, ForgeDirection forgeDirection) {
return i - addToContainer(aspect, i);
}
@Override
public Aspect getEssentiaType(ForgeDirection forgeDirection) {
if (current == null || current.size() < 1) return null;
return current.getAspects()[0];
}
@Override
public int getEssentiaAmount(ForgeDirection forgeDirection) {
int ret = 0;
for (final Aspect A : current.aspects.keySet()) {
ret += current.getAmount(A);
}
return ret;
}
@Override
public int getMinimumSuction() {
return Integer.MAX_VALUE;
}
@Override
public boolean renderExtendedTube() {
return true;
}
}
|