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
|
package goodgenerator.blocks.tileEntity;
import java.util.Map;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.api.TileThaumcraft;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.aspects.IAspectContainer;
import thaumcraft.api.aspects.IEssentiaTransport;
public class MTEEssentiaOutputHatch extends TileThaumcraft implements IAspectContainer, IEssentiaTransport {
public static final int CAPACITY = 256;
protected AspectList mAspects = new AspectList();
public void clear() {
this.mAspects.aspects.clear();
}
@Override
public void markDirty() {
super.markDirty();
if (this.worldObj.isRemote) return;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.mAspects.aspects.clear();
NBTTagList tlist = nbttagcompound.getTagList("Aspects", 10);
for (int j = 0; j < tlist.tagCount(); ++j) {
NBTTagCompound rs = tlist.getCompoundTagAt(j);
if (rs.hasKey("key")) mAspects.add(Aspect.getAspect(rs.getString("key")), rs.getInteger("amount"));
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
Aspect[] aspectA = this.mAspects.getAspects();
NBTTagList nbtTagList = new NBTTagList();
for (Aspect aspect : aspectA) {
if (aspect != null) {
NBTTagCompound f = new NBTTagCompound();
f.setString("key", aspect.getTag());
f.setInteger("amount", this.mAspects.getAmount(aspect));
nbtTagList.appendTag(f);
}
}
nbttagcompound.setTag("Aspects", nbtTagList);
}
private int remainingCapacity() {
return CAPACITY - this.getEssentiaAmount(null);
}
@Override
public AspectList getAspects() {
return this.mAspects;
}
@Override
public void setAspects(AspectList aspectList) {
for (Map.Entry<Aspect, Integer> entry : aspectList.aspects.entrySet()) {
this.addEssentia(entry.getKey(), entry.getValue(), null);
}
}
@Override
public boolean doesContainerAccept(Aspect var1) {
return true;
}
@Override
public int addToContainer(Aspect aspect, int amount) {
int remaining = 0;
if (amount > this.remainingCapacity()) {
remaining = amount - this.remainingCapacity();
this.mAspects.add(aspect, this.remainingCapacity());
} else this.mAspects.add(aspect, amount);
this.markDirty();
return remaining;
}
@Override
public boolean takeFromContainer(Aspect aspect, int amount) {
if (this.mAspects != null && this.mAspects.getAmount(aspect) >= amount) {
this.mAspects.remove(aspect, amount);
this.markDirty();
return true;
} else return false;
}
@Override
public boolean takeFromContainer(AspectList aspects) {
return true;
}
@Override
public boolean doesContainerContainAmount(Aspect aspect, int amount) {
return this.mAspects.getAmount(aspect) >= amount;
}
@Override
public boolean doesContainerContain(AspectList aspectList) {
for (Map.Entry<Aspect, Integer> entry : aspectList.aspects.entrySet()) {
if (this.mAspects.getAmount(entry.getKey()) < entry.getValue()) return false;
}
return true;
}
@Override
public int containerContains(Aspect aspect) {
return this.mAspects.getAmount(aspect);
}
@Override
public boolean isConnectable(ForgeDirection var1) {
return true;
}
@Override
public boolean canInputFrom(ForgeDirection var1) {
return false;
}
@Override
public boolean canOutputTo(ForgeDirection var1) {
return true;
}
@Override
public void setSuction(Aspect var1, int var2) {}
@Override
public Aspect getSuctionType(ForgeDirection var1) {
return null;
}
@Override
public int getSuctionAmount(ForgeDirection var1) {
return 0;
}
@Override
public int takeEssentia(Aspect aspect, int amount, ForgeDirection var3) {
return this.takeFromContainer(aspect, amount) ? amount : 0;
}
@Override
public int addEssentia(Aspect aspect, int amount, ForgeDirection direction) {
return amount - addToContainer(aspect, amount);
}
@Override
public Aspect getEssentiaType(ForgeDirection var1) {
return this.mAspects.size() > 0 ? this.mAspects.getAspects()[0] : null;
}
@Override
public int getEssentiaAmount(ForgeDirection var1) {
return this.mAspects.visSize();
}
@Override
public int getMinimumSuction() {
return 0;
}
@Override
public boolean renderExtendedTube() {
return true;
}
}
|