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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
package gregtech.api.metatileentity.implementations;
import static gregtech.api.enums.GTValues.V;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.IFluidHandler;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.Textures;
import gregtech.api.gui.modularui.GTUIInfos;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.interfaces.tileentity.RecipeMapWorkable;
import gregtech.api.objects.ItemData;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.recipe.maps.FuelBackend;
import gregtech.api.util.GTOreDictUnificator;
import gregtech.api.util.GTRecipe;
import gregtech.api.util.GTUtility;
import gregtech.common.Pollution;
public abstract class MTEBasicGenerator extends MTEBasicTank implements RecipeMapWorkable {
public MTEBasicGenerator(int aID, String aName, String aNameRegional, int aTier, String aDescription,
ITexture... aTextures) {
super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures);
}
public MTEBasicGenerator(int aID, String aName, String aNameRegional, int aTier, String[] aDescription,
ITexture... aTextures) {
super(aID, aName, aNameRegional, aTier, 3, aDescription, aTextures);
}
public MTEBasicGenerator(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 3, aDescription, aTextures);
}
public MTEBasicGenerator(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 3, aDescription, aTextures);
}
@Override
public ITexture[][][] getTextureSet(ITexture[] aTextures) {
ITexture[][][] rTextures = new ITexture[10][17][];
for (byte i = -1; i < 16; i++) {
rTextures[0][i + 1] = getFront(i);
rTextures[1][i + 1] = getBack(i);
rTextures[2][i + 1] = getBottom(i);
rTextures[3][i + 1] = getTop(i);
rTextures[4][i + 1] = getSides(i);
rTextures[5][i + 1] = getFrontActive(i);
rTextures[6][i + 1] = getBackActive(i);
rTextures[7][i + 1] = getBottomActive(i);
rTextures[8][i + 1] = getTopActive(i);
rTextures[9][i + 1] = getSidesActive(i);
}
return rTextures;
}
@Override
public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection side,
ForgeDirection facingDirection, int colorIndex, boolean active, boolean redstoneLevel) {
return mTextures[(active ? 5 : 0) + (side == facingDirection ? 0
: side == facingDirection.getOpposite() ? 1
: side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][colorIndex + 1];
}
@Override
public String[] getDescription() {
String[] desc = new String[mDescriptionArray.length + 1];
System.arraycopy(mDescriptionArray, 0, desc, 0, mDescriptionArray.length);
desc[mDescriptionArray.length] = "Fuel Efficiency: " + getEfficiency() + "%";
return desc;
}
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
GTUIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer);
return true;
}
public ITexture[] getFront(byte aColor) {
return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1] };
}
public ITexture[] getBack(byte aColor) {
return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1] };
}
public ITexture[] getBottom(byte aColor) {
return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1] };
}
public ITexture[] getTop(byte aColor) {
return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1] };
}
public ITexture[] getSides(byte aColor) {
return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1] };
}
public ITexture[] getFrontActive(byte aColor) {
return getFront(aColor);
}
public ITexture[] getBackActive(byte aColor) {
return getBack(aColor);
}
public ITexture[] getBottomActive(byte aColor) {
return getBottom(aColor);
}
public ITexture[] getTopActive(byte aColor) {
return getTop(aColor);
}
public ITexture[] getSidesActive(byte aColor) {
return getSides(aColor);
}
@Override
public boolean isFacingValid(ForgeDirection side) {
return true;
}
@Override
public boolean isSimpleMachine() {
return false;
}
@Override
public boolean isValidSlot(int aIndex) {
return aIndex < 2;
}
@Override
public boolean isEnetOutput() {
return true;
}
@Override
public boolean isOutputFacing(ForgeDirection side) {
return true;
}
@Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
@Override
public long maxEUOutput() {
return getBaseMetaTileEntity().isAllowedToWork() ? V[mTier] : 0L;
}
@Override
public long maxEUStore() {
return Math.max(getEUVar(), V[mTier] * 80L + getMinimumStoredEU());
}
@Override
public boolean doesFillContainers() {
return getBaseMetaTileEntity().isAllowedToWork();
// return false;
}
@Override
public boolean doesEmptyContainers() {
return getBaseMetaTileEntity().isAllowedToWork();
}
@Override
public boolean canTankBeFilled() {
return getBaseMetaTileEntity().isAllowedToWork();
}
@Override
public boolean canTankBeEmptied() {
return getBaseMetaTileEntity().isAllowedToWork();
}
@Override
public boolean displaysItemStack() {
return true;
}
@Override
public boolean displaysStackSize() {
return false;
}
@Override
public boolean isFluidInputAllowed(FluidStack aFluid) {
return getFuelValue(aFluid) > 0;
}
@Override
public boolean isLiquidOutput(ForgeDirection side) {
// return super.isLiquidOutput(aSide);
return false;
}
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && aTick % 10 == 0) {
if (mFluid != null) {
long tFuelValue = getFuelValue(mFluid), tConsumed = consumedFluidPerOperation(mFluid);
if (tFuelValue > 0 && tConsumed > 0 && mFluid.amount >= tConsumed) {
long tFluidAmountToUse = Math.min(
mFluid.amount / tConsumed,
(maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue);
if (tFluidAmountToUse > 0
&& aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true)) {
// divided by two because this is called every 10 ticks, not 20
Pollution.addPollution(getBaseMetaTileEntity(), getPollution() / 2);
mFluid.amount -= tFluidAmountToUse * tConsumed;
}
}
}
if (mInventory[getInputSlot()] != null
&& aBaseMetaTileEntity.getUniversalEnergyStored() < (maxEUOutput() * 20 + getMinimumStoredEU())
&& ((GTUtility.getFluidForFilledItem(mInventory[getInputSlot()], true) != null)
|| solidFuelOverride(mInventory[getInputSlot()]))) {
long tFuelValue = getFuelValue(mInventory[getInputSlot()]);
if (tFuelValue <= 0) tFuelValue = getFuelValue(mInventory[getInputSlot()], true);
// System.out.println(" tFuelValue : " + tFuelValue );
if (tFuelValue > 0) {
ItemStack tEmptyContainer = getEmptyContainer(mInventory[getInputSlot()]);
if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), tEmptyContainer)) {
aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true);
aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1);
// divided by two because this is called every 10 ticks, not 20
Pollution.addPollution(getBaseMetaTileEntity(), getPollution() / 2);
}
}
}
}
if (aBaseMetaTileEntity.isServerSide()) aBaseMetaTileEntity.setActive(
aBaseMetaTileEntity.isAllowedToWork()
&& aBaseMetaTileEntity.getUniversalEnergyStored() >= maxEUOutput() + getMinimumStoredEU());
}
/**
* @param stack the fuel stack
* @return if the stack is a solid fuel
*/
public boolean solidFuelOverride(ItemStack stack) {
// this could be used for a coal generator for example aswell...
ItemData association = GTOreDictUnificator.getAssociation(stack);
// if it is a gregtech Item, make sure its not a VOLUMETRIC_FLASK or any type of cell, else do vanilla checks
if (association != null) {
return !OrePrefixes.CELL_TYPES.contains(association.mPrefix)
&& !GTUtility.areStacksEqual(ItemList.VOLUMETRIC_FLASK.get(1L), stack, true);
} else {
return stack != null && // when the stack is null its not a solid
stack.getItem() != null && // when the item in the stack is null its not a solid
!(stack.getItem() instanceof IFluidContainerItem) && // when the item is a fluid container its not a
// solid...
!(stack.getItem() instanceof IFluidHandler) && // when the item is a fluid handler its not a
// solid...
!stack.getItem()
.getUnlocalizedName()
.contains("bucket"); // since we cant really check for
// buckets...
}
}
public abstract int getPollution();
@Override
public abstract RecipeMap<?> getRecipeMap();
public abstract int getEfficiency();
public int consumedFluidPerOperation(FluidStack aLiquid) {
return 1;
}
public int getFuelValue(FluidStack aLiquid) {
long value = getFuelValue(aLiquid, true);
return (value > Integer.MAX_VALUE) ? 0 : (int) value;
}
public long getFuelValue(FluidStack aLiquid, boolean aLong) {
RecipeMap<?> tRecipes = getRecipeMap();
if (aLiquid == null || !(tRecipes.getBackend() instanceof FuelBackend tFuels)) return 0;
GTRecipe tFuel = tFuels.findFuel(aLiquid);
if (tFuel == null) return 0;
return (long) tFuel.mSpecialValue * getEfficiency() * consumedFluidPerOperation(aLiquid) / 100;
}
public int getFuelValue(ItemStack aStack) {
long value = getFuelValue(aStack, true);
return (value > Integer.MAX_VALUE) ? 0 : (int) value;
}
public long getFuelValue(ItemStack aStack, boolean aLong) {
if (GTUtility.isStackInvalid(aStack) || getRecipeMap() == null) return 0;
GTRecipe tFuel = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack);
if (tFuel == null) return 0;
long liters = 10L; // 1000mb/100
return (long) tFuel.mSpecialValue * liters * getEfficiency();
}
public ItemStack getEmptyContainer(ItemStack aStack) {
if (GTUtility.isStackInvalid(aStack) || getRecipeMap() == null) return null;
GTRecipe tFuel = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, Long.MAX_VALUE, null, aStack);
if (tFuel != null) return GTUtility.copyOrNull(tFuel.getOutput(0));
return GTUtility.getContainerItem(aStack, true);
}
@Override
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
return super.allowPutStack(aBaseMetaTileEntity, aIndex, side, aStack) && (getFuelValue(aStack, true) > 0
|| getFuelValue(GTUtility.getFluidForFilledItem(aStack, true), true) > 0);
}
@Override
public int getCapacity() {
return 16000;
}
@Override
public int getTankPressure() {
return -100;
}
}
|