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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
package gtPlusPlus.xmod.gregtech.api.gui;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.gui.GT_ContainerMetaTile_Machine;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GT_Recipe;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
* <p/>
* The Container I use for all my Basic Machines
*/
public class CONTAINER_MultiMachine extends GT_ContainerMetaTile_Machine {
public String[] mTileDescription;
private String[] oTileDescription;
private GregtechMeta_MultiBlockBase mMCTEI;
private boolean mControllerSet = false;
public CONTAINER_MultiMachine(final InventoryPlayer aInventoryPlayer, final IGregTechTileEntity aTileEntity) {
super(aInventoryPlayer, aTileEntity);
}
public CONTAINER_MultiMachine(final InventoryPlayer aInventoryPlayer, final IGregTechTileEntity aTileEntity, final boolean bindInventory) {
super(aInventoryPlayer, aTileEntity, bindInventory);
}
public static void setControllerInstance(CONTAINER_MultiMachine aContainer, IGregTechTileEntity aTile) {
if (aTile == null) {
return;
}
final IMetaTileEntity aMetaTileEntity = aTile.getMetaTileEntity();
if (aMetaTileEntity == null) {
return;
}
if (aMetaTileEntity instanceof GregtechMeta_MultiBlockBase) {
aContainer.mMCTEI = (GregtechMeta_MultiBlockBase) aMetaTileEntity;
}
}
public int aTotalTickTime = 0;
public int aMaxParallel = 0;
public int aPollutionTick = 0;
public int aMaxInputVoltage = 0;
public int aInputTier = 0;
public int aOutputTier = 0;
public int aRecipeDuration = 0;
public int aRecipeEU = 0;
public int aRecipeSpecial = 0;
public int aPollutionReduction = 0;
public int aStoredEnergy = 0;
public int aMaxEnergy = 0;
public int aEfficiency = 0;
private int oTotalTickTime = 0;
private int oMaxParallel = 0;
private int oPollutionTick = 0;
private int oMaxInputVoltage = 0;
private int oInputTier = 0;
private int oOutputTier = 0;
private int oRecipeDuration = 0;
private int oRecipeEU = 0;
private int oRecipeSpecial = 0;
private int oPollutionReduction = 0;
private int oStoredEnergy = 0;
private int oMaxEnergy = 0;
private int oEfficiency = 0;
private static Field timer;
//private static Field crafters;
@Override
public final void detectAndSendChanges() {
super.detectAndSendChanges();
if (this.mTileEntity.isClientSide() || this.mTileEntity.getMetaTileEntity() == null) {
return;
}
if (!mControllerSet) {
setControllerInstance(this, this.mTileEntity);
}
mControllerSet = (mMCTEI != null);
if (timer == null) {
timer = ReflectionUtils.getField(getClass(), "mTimer");
}
if (crafters == null) {
//crafters = ReflectionUtils.getField(getClass(), "crafters");
}
if (timer != null && crafters != null && mControllerSet) {
//Logger.INFO("Trying to update clientside GUI data");
try {
//Logger.INFO("0");
int aTimer = (int) ReflectionUtils.getFieldValue(timer, this);
//List crafters1List = (List) crafters1;
List<ICrafting> crafters2 = new ArrayList<ICrafting>();
//Logger.INFO("1");
for (Object o : crafters) {
if (o instanceof ICrafting) {
crafters2.add((ICrafting) o);
}
}
//Logger.INFO("2");
if (!crafters2.isEmpty()) {
//Logger.INFO("3");
handleInitialFieldSetting();
try {
//Logger.INFO("4");
for (final ICrafting var3 : crafters2) {
handleCraftingEvent(aTimer, var3);
}
//Logger.INFO("5");
handleInternalFieldSetting();
//Logger.INFO("6");
} catch (Throwable t) {
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
else {
Logger.INFO("Failed.");
}
}
public void handleInitialFieldSetting() {
this.aTotalTickTime = MathUtils.balance((int) mMCTEI.getTotalRuntimeInTicks(), Integer.MIN_VALUE, Integer.MAX_VALUE);
this.aMaxParallel = mMCTEI.getMaxParallelRecipes();
this.aPollutionTick = mMCTEI.getPollutionPerTick(null);
this.aMaxInputVoltage = MathUtils.balance((int) mMCTEI.getMaxInputVoltage(), Integer.MIN_VALUE, Integer.MAX_VALUE);
this.aInputTier = MathUtils.balance((int) mMCTEI.getInputTier(), Integer.MIN_VALUE, Integer.MAX_VALUE);
this.aOutputTier = MathUtils.balance((int) mMCTEI.getOutputTier(), Integer.MIN_VALUE, Integer.MAX_VALUE);
if (mMCTEI.mLastRecipe != null) {
GT_Recipe aRecipe = mMCTEI.mLastRecipe;
this.aRecipeDuration = MathUtils.balance(aRecipe.mDuration, Integer.MIN_VALUE, Integer.MAX_VALUE);
this.aRecipeEU = MathUtils.balance(aRecipe.mEUt, Integer.MIN_VALUE, Integer.MAX_VALUE);
this.aRecipeSpecial = MathUtils.balance(aRecipe.mSpecialValue, Integer.MIN_VALUE, Integer.MAX_VALUE);
}
this.aPollutionReduction = mMCTEI.getPollutionReductionForAllMufflers();
this.aStoredEnergy = MathUtils.balance((int) mMCTEI.getStoredEnergyInAllEnergyHatches(), Integer.MIN_VALUE, Integer.MAX_VALUE);
this.aMaxEnergy = MathUtils.balance((int) mMCTEI.getMaxEnergyStorageOfAllEnergyHatches(), Integer.MIN_VALUE, Integer.MAX_VALUE);
this.aEfficiency = MathUtils.balance(mMCTEI.mEfficiency, Integer.MIN_VALUE, Integer.MAX_VALUE);
}
public void handleCraftingEvent(int aTimer, ICrafting aCrafter) {
int aID = 750;
if (aTimer % 500 == 10 || this.oTotalTickTime != this.aTotalTickTime) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aTotalTickTime);
}
if (aTimer % 500 == 10 || this.oMaxParallel != this.aMaxParallel) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aMaxParallel);
}
if (aTimer % 500 == 10 || this.oPollutionTick != this.aPollutionTick) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aPollutionTick);
}
if (aTimer % 500 == 10 || this.oMaxInputVoltage != this.aMaxInputVoltage) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aMaxInputVoltage);
}
if (aTimer % 500 == 10 || this.oInputTier != this.aInputTier) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aInputTier);
}
if (aTimer % 500 == 10 || this.oOutputTier != this.aOutputTier) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aOutputTier);
}
if (aTimer % 500 == 10 || this.oRecipeDuration != this.aRecipeDuration) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aRecipeDuration);
}
if (aTimer % 500 == 10 || this.oRecipeEU != this.aRecipeEU) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aRecipeEU);
}
if (aTimer % 500 == 10 || this.oRecipeSpecial != this.aRecipeSpecial) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aRecipeSpecial);
}
if (aTimer % 500 == 10 || this.oPollutionReduction != this.aPollutionReduction) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aPollutionReduction);
}
if (aTimer % 500 == 10 || this.oStoredEnergy != this.aStoredEnergy) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aStoredEnergy);
}
if (aTimer % 500 == 10 || this.oMaxEnergy != this.aMaxEnergy) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aMaxEnergy);
}
if (aTimer % 500 == 10 || this.oEfficiency != this.aEfficiency) {
aCrafter.sendProgressBarUpdate((Container) this, aID++, this.aEfficiency);
}
}
public void handleInternalFieldSetting() {
this.oTotalTickTime = this.aTotalTickTime;
this.oMaxParallel = this.aMaxParallel;
this.oPollutionTick = this.aPollutionTick;
this.oMaxInputVoltage = this.aMaxInputVoltage;
this.oInputTier = this.aInputTier;
this.oOutputTier = this.aOutputTier;
this.oRecipeDuration = this.aRecipeDuration;
this.oRecipeEU = this.aRecipeEU;
this.oRecipeSpecial = this.aRecipeSpecial;
this.oPollutionReduction = this.aPollutionReduction;
this.oStoredEnergy = this.aStoredEnergy;
this.oMaxEnergy = this.aMaxEnergy;
this.oEfficiency = this.aEfficiency;
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(final int par1, final int par2) {
super.updateProgressBar(par1, par2);
int shiftedSwitch = par1 - 750;
switch (shiftedSwitch) {
case 0: {
this.aTotalTickTime = par2;
break;
}
case 1: {
this.aMaxParallel = par2;
break;
}
case 2: {
this.aPollutionTick = par2;
break;
}
case 3: {
this.aMaxInputVoltage = par2;
break;
}
case 4: {
this.aInputTier = par2;
break;
}
case 5: {
this.aOutputTier = par2;
break;
}
case 6: {
this.aRecipeDuration = par2;
break;
}
case 7: {
this.aRecipeEU = par2;
break;
}
case 8: {
this.aRecipeSpecial = par2;
break;
}
case 9: {
this.aPollutionReduction = par2;
break;
}
case 10: {
this.aStoredEnergy = par2;
break;
}
case 11: {
this.aMaxEnergy = par2;
break;
}
case 12: {
this.aEfficiency = par2;
break;
}
}
}
}
|