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
|
package gregtech.common.tileentities.machines.multi;
import static gregtech.api.enums.GTValues.STEAM_PER_WATER;
import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_NEW5;
import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_NEW_ACTIVE5;
import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_NEW_EMPTY5;
import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS;
import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages;
import static gregtech.api.objects.XSTR.XSTR_INSTANCE;
import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import gregtech.GTMod;
import gregtech.api.GregTechAPI;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;
import gregtech.api.util.MultiblockTooltipBuilder;
public class MTELargeTurbineSteam extends MTELargeTurbine {
private int excessWater;
private boolean achievement = false;
private boolean looseFit = false;
public MTELargeTurbineSteam(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}
public MTELargeTurbineSteam(String aName) {
super(aName);
}
@Override
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection aFacing,
int colorIndex, boolean aActive, boolean redstoneLevel) {
return new ITexture[] { MACHINE_CASINGS[1][colorIndex + 1],
aFacing == side ? (aActive ? TextureFactory.builder()
.addIcon(LARGETURBINE_NEW_ACTIVE5)
.build()
: hasTurbine() ? TextureFactory.builder()
.addIcon(LARGETURBINE_NEW5)
.build()
: TextureFactory.builder()
.addIcon(LARGETURBINE_NEW_EMPTY5)
.build())
: casingTexturePages[0][57] };
}
@Override
protected MultiblockTooltipBuilder createTooltip() {
final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder();
tt.addMachineType("Steam Turbine")
.addInfo("Controller block for the Large Steam Turbine")
.addInfo("Needs a Turbine, place inside controller")
.addInfo("Outputs Distilled Water as well as producing power")
.addInfo("Power output depends on turbine and fitting")
.addInfo("Use screwdriver to adjust fitting of turbine")
.addSeparator()
.beginStructureBlock(3, 3, 4, true)
.addController("Front center")
.addCasingInfoRange("Turbine Casing", 8, 31, false)
.addDynamoHatch("Back center", 1)
.addMaintenanceHatch("Side centered", 2)
.addInputHatch("Steam, Side centered", 2)
.addOutputHatch("Distilled Water, Side centered", 2)
.toolTipFinisher("Gregtech");
return tt;
}
@Override
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTELargeTurbineSteam(mName);
}
@Override
public Block getCasingBlock() {
return GregTechAPI.sBlockCasings4;
}
@Override
public byte getCasingMeta() {
return 9;
}
@Override
public int getCasingTextureIndex() {
return 16;
}
@Override
public boolean isNewStyleRendering() {
return true;
}
private int condenseSteam(int steam) {
excessWater += steam;
int water = excessWater / STEAM_PER_WATER;
excessWater %= STEAM_PER_WATER;
return water;
}
@Override
int fluidIntoPower(ArrayList<FluidStack> aFluids, int aOptFlow, int aBaseEff, int overflowEfficiency,
float[] flowMultipliers) {
if (looseFit) {
float[] calculatedFlow = calculateLooseFlow(aOptFlow, aBaseEff);
aOptFlow = GTUtility.safeInt((long) calculatedFlow[0]);
aBaseEff = GTUtility.safeInt((long) calculatedFlow[1]);
}
int tEU = 0;
int totalFlow = 0; // Byproducts are based on actual flow
int flow = 0;
// Allowed to use up to 250% optimal flow rate, depending on the value of overflowMultiplier.
// This value is chosen because the highest EU/t possible depends on the overflowMultiplier, and the formula
// used
// makes it so the flow rate for that max, per value of overflowMultiplier, is (percentage of optimal flow
// rate):
// - 150% if it is 1
// - 200% if it is 2
// - 250% if it is 3
// Variable required outside of loop for multi-hatch scenarios.
this.realOptFlow = aOptFlow * flowMultipliers[0];
int remainingFlow = GTUtility.safeInt((long) (realOptFlow * (0.5f * overflowMultiplier + 1)));
storedFluid = 0;
for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { // loop through each hatch; extract inputs and
// track totals.
final FluidStack aFluidStack = aFluids.get(i);
if (GTModHandler.isAnySteam(aFluidStack)) {
flow = Math.min(aFluidStack.amount, remainingFlow); // try to use up to the max flow defined just above
depleteInput(new FluidStack(aFluidStack, flow)); // deplete that amount
this.storedFluid += aFluidStack.amount;
remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches
totalFlow += flow; // track total input used
if (!achievement) {
GTMod.achievements.issueAchievement(
this.getBaseMetaTileEntity()
.getWorld()
.getPlayerEntityByName(
this.getBaseMetaTileEntity()
.getOwnerName()),
"muchsteam");
achievement = true;
}
} else if (GTModHandler.isSuperHeatedSteam(aFluidStack)) {
depleteInput(new FluidStack(aFluidStack, aFluidStack.amount));
}
}
if (totalFlow <= 0) return 0;
tEU = totalFlow;
int waterToOutput = condenseSteam(totalFlow);
addOutput(GTModHandler.getDistilledWater(waterToOutput));
if (totalFlow == (GTUtility.safeInt((long) realOptFlow))) {
tEU = GTUtility.safeInt((long) tEU * (long) aBaseEff / 20000L);
} else {
float efficiency = getOverflowEfficiency(
totalFlow,
(GTUtility.safeInt((long) realOptFlow)),
overflowMultiplier);
tEU *= efficiency;
tEU = Math.max(1, GTUtility.safeInt((long) tEU * (long) aBaseEff / 20000L));
}
// If next output is above the maximum the dynamo can handle, set it to the maximum instead of exploding the
// turbine
// Raising the maximum allowed flow rate to account for the efficiency changes beyond the optimal flow rate can
// explode turbines on world load
if (tEU > getMaximumOutput()) {
tEU = GTUtility.safeInt(getMaximumOutput());
}
return tEU;
}
@Override
float getOverflowEfficiency(int totalFlow, int actualOptimalFlow, int overflowMultiplier) {
// overflowMultiplier changes how quickly the turbine loses efficiency after flow goes beyond the optimal value
// At the default value of 1, any flow will generate less EU/t than optimal flow, regardless of the amount of
// fuel used
// The bigger this number is, the slower efficiency loss happens as flow moves beyond the optimal value
// Steam is the least efficient out of all turbine fuels in this regard
float efficiency = 0;
if (totalFlow > actualOptimalFlow) {
efficiency = 1.0f
- Math.abs((totalFlow - actualOptimalFlow)) / ((float) actualOptimalFlow * (overflowMultiplier + 1));
} else {
efficiency = 1.0f - Math.abs((totalFlow - actualOptimalFlow) / (float) actualOptimalFlow);
}
return efficiency;
}
public static float[] calculateLooseFlow(float aOptFlow, float aBaseEff) {
aOptFlow *= 4f;
if (aBaseEff >= 26000f) {
aOptFlow = aOptFlow * (float) Math.pow(1.1f, ((aBaseEff - 8000f) / 10000f) * 20f);
aBaseEff = aBaseEff * 0.6f;
} else if (aBaseEff > 22000f) {
aOptFlow = aOptFlow * (float) Math.pow(1.1f, ((aBaseEff - 7000f) / 10000f) * 20f);
aBaseEff = aBaseEff * 0.65f;
} else if (aBaseEff > 18000f) {
aOptFlow = aOptFlow * (float) Math.pow(1.1f, ((aBaseEff - 6000f) / 10000f) * 20f);
aBaseEff = aBaseEff * 0.70f;
} else if (aBaseEff > 14000f) {
aOptFlow = aOptFlow * (float) Math.pow(1.1f, ((aBaseEff - 5000f) / 10000f) * 20f);
aBaseEff = aBaseEff * 0.75f;
} else if (aBaseEff > 10000f) {
aOptFlow = aOptFlow * (float) Math.pow(1.1f, ((aBaseEff - 4000f) / 10000f) * 20f);
aBaseEff = aBaseEff * 0.8f;
} else if (aBaseEff > 6000f) {
aOptFlow = aOptFlow * (float) Math.pow(1.1f, ((aBaseEff - 3000f) / 10000f) * 20f);
aBaseEff = aBaseEff * 0.85f;
} else {
aBaseEff = aBaseEff * 0.9f;
}
if (aBaseEff % 100 != 0) {
aBaseEff -= aBaseEff % 100;
}
float[] looseFlow = new float[2];
looseFlow[0] = aOptFlow;
looseFlow[1] = aBaseEff;
return looseFlow;
}
@Override
public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {
if (side == getBaseMetaTileEntity().getFrontFacing()) {
looseFit ^= true;
GTUtility.sendChatToPlayer(
aPlayer,
looseFit ? GTUtility.trans("500", "Fitting: Loose - More Flow")
: GTUtility.trans("501", "Fitting: Tight - More Efficiency"));
}
}
@Override
public int getDamageToComponent(ItemStack aStack) {
return (looseFit && XSTR_INSTANCE.nextInt(4) == 0) ? 0 : 1;
}
@Override
public String[] getInfoData() {
super.looseFit = looseFit;
return super.getInfoData();
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setBoolean("turbineFitting", looseFit);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
looseFit = aNBT.getBoolean("turbineFitting");
}
}
|