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
|
package gregtech.common.tileentities.boilers;
import static mcp.mobius.waila.api.SpecialChars.GOLD;
import static mcp.mobius.waila.api.SpecialChars.RESET;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import com.gtnewhorizons.modularui.api.widget.Widget;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import gregtech.api.enums.Dyes;
import gregtech.api.enums.SteamVariant;
import gregtech.api.enums.Textures.BlockIcons;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTLanguageManager;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;
import gregtech.common.config.MachineStats;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
public class MTEBoilerSolar extends MTEBoiler {
public static final String LPS_FMT = "%s L/s";
private static final String localizedDescFormat = GTLanguageManager.addStringLocalization(
"gt.blockmachines.boiler.solar.desc.format",
"Steam Power by the Sun%n" + "Produces %sL of Steam per second%n"
+ "Calcifies over time, reducing Steam output to %sL/s%n"
+ "Break and replace to descale");
protected int calcificationTicks = MachineStats.bronzeSolarBoiler.calcificationTicks;
protected int cooldownTicks = MachineStats.bronzeSolarBoiler.cooldownTicks;
protected int maxOutputPerSecond = MachineStats.bronzeSolarBoiler.maxOutputPerSecond;
protected int minOutputPerSecond = MachineStats.bronzeSolarBoiler.minOutputPerSecond;
protected final int basicTemperatureMod = 5; // Base Celsius gain or loss
private int mRunTimeTicks = 0;
public MTEBoilerSolar(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional, new String[0]);
}
public MTEBoilerSolar(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {
super(aName, aTier, aDescription, aTextures);
}
public MTEBoilerSolar(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, aDescription, aTextures);
}
public int getMaxOutputPerSecond() {
return maxOutputPerSecond;
}
@Override
public String[] getDescription() {
return String
.format(
localizedDescFormat,
GTUtility.formatNumbers(getMaxOutputPerSecond()),
GTUtility.formatNumbers(getMinOutputPerSecond()))
.split("\\R");
}
public int getMinOutputPerSecond() {
return minOutputPerSecond;
}
@Override
public ITexture[][][] getTextureSet(ITexture[] aTextures) {
ITexture[][][] rTextures = new ITexture[4][17][];
for (int color = -1; color < 16; color++) {
int i = color + 1;
short[] colorModulation = Dyes.getModulation(color, Dyes._NULL.mRGBa);
rTextures[0][i] = new ITexture[] {
TextureFactory.of(BlockIcons.MACHINE_BRONZEBRICKS_BOTTOM, colorModulation) };
rTextures[1][i] = new ITexture[] { TextureFactory.of(BlockIcons.MACHINE_BRONZEBRICKS_TOP, colorModulation),
TextureFactory.of(BlockIcons.BOILER_SOLAR) };
rTextures[2][i] = new ITexture[] {
TextureFactory.of(BlockIcons.MACHINE_BRONZEBRICKS_SIDE, colorModulation) };
rTextures[3][i] = new ITexture[] { TextureFactory.of(BlockIcons.MACHINE_BRONZEBRICKS_SIDE, colorModulation),
TextureFactory.of(BlockIcons.OVERLAY_PIPE) };
}
return rTextures;
}
@Override
public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection sideDirection,
ForgeDirection facingDirection, int colorIndex, boolean active, boolean redstoneLevel) {
final int i = colorIndex + 1;
if ((sideDirection.flag & (ForgeDirection.UP.flag | ForgeDirection.DOWN.flag)) == 0) { // Horizontal
if (sideDirection != facingDirection) return mTextures[2][i];
return mTextures[3][i];
}
return mTextures[sideDirection.ordinal()][i];
}
@Override
public int maxProgresstime() {
return 500;
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setInteger("mRunTime", mRunTimeTicks);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
mRunTimeTicks = aNBT.getInteger("mRunTime");
}
@Override
protected void produceSteam(int aAmount) {
super.produceSteam(aAmount);
// Disable calcification when using distilled water
if (mFluid.isFluidEqual(GTModHandler.getWater(1))) {
// produceSteam is getting called every 10 ticks
if (mRunTimeTicks >= 0 && mRunTimeTicks < (Integer.MAX_VALUE - 10)) mRunTimeTicks += 10;
else mRunTimeTicks = Integer.MAX_VALUE; // Prevent Integer overflow wrap
}
}
@Override
protected void pushSteamToInventories(IGregTechTileEntity aBaseMetaTileEntity) {
if (mSteam == null || mSteam.amount == 0) return;
pushSteamToSide(aBaseMetaTileEntity, aBaseMetaTileEntity.getFrontFacing());
}
@Override
protected int getPollution() {
return 0;
}
@Override
public int getProductionPerSecond() {
if (mTemperature < 100) {
return 0;
}
if (mRunTimeTicks > getMaxRuntimeTicks()) {
return getMinOutputPerSecond();
} else if (mRunTimeTicks > getCalcificationTicks()) {
/*
* When reaching calcification ticks; discount the proportion of run-time spent on calcification from the
* maximum output per second, and return this or the minimum output per second
*/
return getMaxOutputPerSecond()
- getMaxOutputPerSecond() * (mRunTimeTicks - getCalcificationTicks()) / getCalcificationTicks();
} else {
return getMaxOutputPerSecond();
}
}
protected int getCalcificationTicks() {
return calcificationTicks;
}
protected int getCooldownTicks() {
return cooldownTicks;
}
protected int getMaxRuntimeTicks() {
// After which min output is reached.
return (getMaxOutputPerSecond() - getMinOutputPerSecond()) * getCalcificationTicks() / getMaxOutputPerSecond()
+ getCalcificationTicks();
}
@Override
protected int getMaxTemperature() {
return 500;
}
@Override
protected int getEnergyConsumption() {
return basicTemperatureMod;
}
@Override
protected int getCooldownInterval() {
return getCooldownTicks() / basicTemperatureMod;
}
@Override
protected int getHeatUpAmount() {
return basicTemperatureMod;
}
@Override
protected void updateFuel(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
World world = aBaseMetaTileEntity.getWorld();
// Heat-up every 12s (240 ticks), has to be multiple of 20 ticks
if ((aTick % 240L != 0L) || (world.isThundering())) {
return;
}
if (!aBaseMetaTileEntity.getSkyAtSide(ForgeDirection.UP)) {
return;
}
boolean weatherClear = !world.isRaining() || aBaseMetaTileEntity.getBiome().rainfall == 0.0F;
if (!weatherClear && world.skylightSubtracted >= 4) {
return;
}
if (weatherClear) {
if (world.isDaytime()) {
mProcessingEnergy += 8 * basicTemperatureMod;
} else {
mProcessingEnergy += basicTemperatureMod;
}
} else {
mProcessingEnergy += basicTemperatureMod;
}
}
@Override
public SteamVariant getSteamVariant() {
return SteamVariant.BRONZE;
}
@Override
public boolean isGivingInformation() {
return true;
}
@Override
public String[] getInfoData() {
return String
.format(
"Heat Capacity: " + EnumChatFormatting.GREEN
+ "%s %%"
+ EnumChatFormatting.RESET
+ " Hot time: "
+ EnumChatFormatting.RED
+ "%s s"
+ EnumChatFormatting.RESET
+ "%n"
+ "Min output: "
+ EnumChatFormatting.RED
+ LPS_FMT
+ EnumChatFormatting.RESET
+ " Max output: "
+ EnumChatFormatting.RED
+ LPS_FMT
+ EnumChatFormatting.RESET
+ "%n"
+ "Current Output: "
+ EnumChatFormatting.YELLOW
+ LPS_FMT
+ EnumChatFormatting.RESET,
GTUtility.formatNumbers(getHeatCapacityPercent()),
GTUtility.formatNumbers(getHotTimeSeconds()),
GTUtility.formatNumbers(getMinOutputPerSecond()),
GTUtility.formatNumbers(getMaxOutputPerSecond()),
GTUtility.formatNumbers(getProductionPerSecond()))
.split("\\R");
}
public int getHeatCapacityPercent() {
return mTemperature * 100 / maxProgresstime();
}
public int getHotTimeSeconds() {
return mRunTimeTicks / 20;
}
@Override
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTEBoilerSolar(mName, mTier, mDescriptionArray, mTextures);
}
@Override
protected Widget createFuelSlot() {
return null;
}
@Override
protected SlotWidget createAshSlot() {
return null;
}
@Override
public void getWailaBody(ItemStack itemStack, List<String> currentTip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
final NBTTagCompound tag = accessor.getNBTData();
currentTip.add(
String.format(
(GOLD + "Solar Boiler Output: " + RESET + "%d/%d L/s"),
tag.getInteger("calcificationOutput"),
tag.getInteger("maxCalcificationOutput")));
super.getWailaBody(itemStack, currentTip, accessor, config);
}
@Override
public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y,
int z) {
super.getWailaNBTData(player, tile, tag, world, x, y, z);
tag.setInteger("calcificationOutput", (getProductionPerSecond()));
tag.setInteger("maxCalcificationOutput", (getMaxOutputPerSecond()));
}
}
|