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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
package com.elisis.gtnhlanth.common.tileentity;
import static com.elisis.gtnhlanth.util.DescTextLocalization.BLUEPRINT_INFO;
import static com.elisis.gtnhlanth.util.DescTextLocalization.addDotText;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock;
import static gregtech.api.enums.GT_HatchElement.Energy;
import static gregtech.api.enums.GT_HatchElement.InputBus;
import static gregtech.api.enums.GT_HatchElement.Maintenance;
import static gregtech.api.enums.GT_HatchElement.OutputBus;
import static gregtech.api.enums.GT_Values.VN;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER_ACTIVE;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER_ACTIVE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import com.elisis.gtnhlanth.common.beamline.BeamInformation;
import com.elisis.gtnhlanth.common.beamline.BeamLinePacket;
import com.elisis.gtnhlanth.common.beamline.Particle;
import com.elisis.gtnhlanth.common.hatch.TileHatchOutputBeamline;
import com.elisis.gtnhlanth.common.register.LanthItemList;
import com.elisis.gtnhlanth.common.tileentity.recipe.beamline.BeamlineRecipeAdder2;
import com.elisis.gtnhlanth.common.tileentity.recipe.beamline.RecipeSC;
import com.elisis.gtnhlanth.util.DescTextLocalization;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import gregtech.api.GregTech_API;
import gregtech.api.enums.GT_Values;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.shutdown.SimpleShutDownReason;
public class SourceChamber extends GT_MetaTileEntity_EnhancedMultiBlockBase<SourceChamber>
implements ISurvivalConstructable {
private static final IStructureDefinition<SourceChamber> STRUCTURE_DEFINITION;
private ArrayList<TileHatchOutputBeamline> mOutputBeamline = new ArrayList<>();
private static final int CASING_INDEX = GT_Utility.getCasingTextureIndex(GregTech_API.sBlockCasings5, 14);
private float outputEnergy;
private int outputRate;
private int outputParticle;
private float outputFocus;
static {
STRUCTURE_DEFINITION = StructureDefinition.<SourceChamber>builder()
.addShape(
"sc",
new String[][] { { "ccccc", "ckkkc", "ckikc", "ckkkc", "dd~dd" },
{ "ckkkc", "keeek", "ke-ek", "keeek", "ccocc" }, { "ckkkc", "k---k", "k---k", "k---k", "ccccc" },
{ "ckkkc", "k---k", "k---k", "k---k", "ccccc" }, { "ckkkc", "keeek", "ke-ek", "keeek", "ccccc" },
{ "ccccc", "ckkkc", "ckbkc", "ckkkc", "ccccc" } })
.addElement('c', ofBlock(LanthItemList.SHIELDED_ACCELERATOR_CASING, 0))
.addElement('k', ofBlock(LanthItemList.SHIELDED_ACCELERATOR_GLASS, 0))
.addElement('e', ofBlock(LanthItemList.ELECTRODE_CASING, 0))
.addElement(
'b',
buildHatchAdder(SourceChamber.class).hatchClass(TileHatchOutputBeamline.class)
.casingIndex(CASING_INDEX)
.dot(4)
.adder(SourceChamber::addBeamLineOutputHatch)
.build())
.addElement(
'i',
buildHatchAdder(SourceChamber.class).atLeast(InputBus)
.casingIndex(CASING_INDEX)
.dot(1)
.build())
.addElement(
'o',
buildHatchAdder(SourceChamber.class).atLeast(OutputBus)
.casingIndex(CASING_INDEX)
.dot(2)
.build())
.addElement(
'd',
buildHatchAdder(SourceChamber.class).atLeast(Maintenance, Energy)
.casingIndex(CASING_INDEX)
.dot(3)
.buildAndChain(ofBlock(LanthItemList.SHIELDED_ACCELERATOR_CASING, 0)))
.build();
}
public SourceChamber(int id, String name, String nameRegional) {
super(id, name, nameRegional);
}
public SourceChamber(String name) {
super(name);
}
@Override
public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) {
if (mMachine) return -1;
return survivialBuildPiece("sc", stackSize, 2, 4, 0, elementBudget, env, false, true);
}
@Override
public IMetaTileEntity newMetaEntity(IGregTechTileEntity te) {
return new SourceChamber(this.mName);
}
@Override
protected GT_Multiblock_Tooltip_Builder createTooltip() {
final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder();
tt.addMachineType("Particle Source")
.addInfo("Controller block for the Source Chamber")
.addInfo(BLUEPRINT_INFO)
.addInfo(DescTextLocalization.BEAMLINE_SCANNER_INFO)
.addSeparator()
.beginStructureBlock(5, 5, 6, true)
.addController("Front bottom")
.addCasingInfoExactly(LanthItemList.SHIELDED_ACCELERATOR_CASING.getLocalizedName(), 56, false)
.addCasingInfoExactly(LanthItemList.SHIELDED_ACCELERATOR_GLASS.getLocalizedName(), 52, false)
.addCasingInfoExactly(LanthItemList.ELECTRODE_CASING.getLocalizedName(), 16, false)
.addOtherStructurePart("Beamline Output Hatch", addDotText(4))
.addEnergyHatch(addDotText(3))
.addMaintenanceHatch(addDotText(3))
.addInputBus(addDotText(1))
.addOutputBus(addDotText(2))
.toolTipFinisher("GTNH: Lanthanides");
return tt;
}
private boolean addBeamLineOutputHatch(IGregTechTileEntity te, int casingIndex) {
if (te == null) return false;
IMetaTileEntity mte = te.getMetaTileEntity();
if (mte == null) return false;
if (mte instanceof TileHatchOutputBeamline) {
return this.mOutputBeamline.add((TileHatchOutputBeamline) mte);
}
return false;
}
/*
* protected OverclockDescriber createOverclockDescriber() { return new EUNoTotalOverclockDescriber((byte) 4, 1); }
*/
@Override
public boolean checkRecipe(ItemStack itemStack) {
// GT_Log.out.print("In checkRecipe");
// No input particle, so no input quantities
outputFocus = 0;
outputEnergy = 0;
outputParticle = 0;
outputRate = 0;
ItemStack[] tItems = this.getStoredInputs()
.toArray(new ItemStack[0]);
// GT_Log.out.print(Arrays.toString(tItems));
long tVoltageMaxTier = this.getMaxInputVoltage(); // Used to keep old math the same
long tVoltageActual = GT_Values.VP[(int) this.getInputVoltageTier()];
RecipeSC tRecipe = (RecipeSC) BeamlineRecipeAdder2.instance.SourceChamberRecipes
.findRecipe(this.getBaseMetaTileEntity(), false, tVoltageActual, new FluidStack[] {}, tItems);
if (tRecipe == null || !tRecipe.isRecipeInputEqual(true, new FluidStack[] {}, tItems)) return false; // Consumes
// input
// item
this.mEfficiency = (10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
this.mMaxProgresstime = tRecipe.mDuration;
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && this.mEUt == Integer.MAX_VALUE - 1) return false;
mEUt = (int) -tVoltageActual;
if (this.mEUt > 0) this.mEUt = (-this.mEUt);
outputParticle = tRecipe.particleId;
float maxParticleEnergy = Particle.getParticleFromId(outputParticle)
.maxSourceEnergy(); // The maximum energy a
// particle can possess
// when produced by this
// multiblock
float maxMaterialEnergy = tRecipe.maxEnergy; // The maximum energy for the recipe processed
outputEnergy = (float) Math.min(
(-maxMaterialEnergy) * Math.pow(1.001, -(tRecipe.energyRatio) * (tVoltageMaxTier - tRecipe.mEUt))
+ maxMaterialEnergy,
maxParticleEnergy);
if (outputEnergy <= 0) {
stopMachine(SimpleShutDownReason.ofCritical("gtnhlanth.scerror"));
return false;
}
outputFocus = tRecipe.focus;
outputRate = tRecipe.rate;
this.mOutputItems = tRecipe.mOutputs;
this.updateSlots();
outputAfterRecipe();
return true;
}
@Override
public String[] getStructureDescription(ItemStack arg0) {
return DescTextLocalization.addText("SourceChamber.hint", 7); // Generate 7 localised hint strings in structure
// description
}
private void outputAfterRecipe() {
if (!mOutputBeamline.isEmpty()) {
BeamLinePacket packet = new BeamLinePacket(
new BeamInformation(outputEnergy, outputRate, outputParticle, outputFocus));
for (TileHatchOutputBeamline o : mOutputBeamline) {
o.q = packet;
}
}
}
@Override
public void stopMachine() {
outputFocus = 0;
outputEnergy = 0;
outputParticle = 0;
outputRate = 0;
super.stopMachine();
}
@Override
public RecipeMap<?> getRecipeMap() {
return BeamlineRecipeAdder2.instance.SourceChamberRecipes;
}
@Override
public String[] getInfoData() {
long storedEnergy = 0;
long maxEnergy = 0;
for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) {
if (tHatch.isValid()) {
storedEnergy += tHatch.getBaseMetaTileEntity()
.getStoredEU();
maxEnergy += tHatch.getBaseMetaTileEntity()
.getEUCapacity();
}
}
return new String[] {
/* 1 */ StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": "
+ EnumChatFormatting.GREEN
+ GT_Utility.formatNumbers(mProgresstime / 20)
+ EnumChatFormatting.RESET
+ " s / "
+ EnumChatFormatting.YELLOW
+ GT_Utility.formatNumbers(mMaxProgresstime / 20)
+ EnumChatFormatting.RESET
+ " s",
/* 2 */ StatCollector.translateToLocal("GT5U.multiblock.energy") + ": "
+ EnumChatFormatting.GREEN
+ GT_Utility.formatNumbers(storedEnergy)
+ EnumChatFormatting.RESET
+ " EU / "
+ EnumChatFormatting.YELLOW
+ GT_Utility.formatNumbers(maxEnergy)
+ EnumChatFormatting.RESET
+ " EU",
/* 3 */ StatCollector.translateToLocal("GT5U.multiblock.usage") + ": "
+ EnumChatFormatting.RED
+ GT_Utility.formatNumbers(getActualEnergyUsage())
+ EnumChatFormatting.RESET
+ " EU/t",
/* 4 */ StatCollector.translateToLocal("GT5U.multiblock.mei") + ": "
+ EnumChatFormatting.YELLOW
+ GT_Utility.formatNumbers(getMaxInputVoltage())
+ EnumChatFormatting.RESET
+ " EU/t(*2A) "
+ StatCollector.translateToLocal("GT5U.machines.tier")
+ ": "
+ EnumChatFormatting.YELLOW
+ VN[GT_Utility.getTier(getMaxInputVoltage())]
+ EnumChatFormatting.RESET,
/* 5 */ StatCollector.translateToLocal("GT5U.multiblock.problems") + ": "
+ EnumChatFormatting.RED
+ (getIdealStatus() - getRepairStatus())
+ EnumChatFormatting.RESET
+ " "
+ StatCollector.translateToLocal("GT5U.multiblock.efficiency")
+ ": "
+ EnumChatFormatting.YELLOW
+ Float.toString(mEfficiency / 100.0F)
+ EnumChatFormatting.RESET
+ " %",
EnumChatFormatting.BOLD + StatCollector.translateToLocal("beamline.out_pre")
+ ": "
+ EnumChatFormatting.RESET,
StatCollector.translateToLocal("beamline.particle") + ": "
+ EnumChatFormatting.GOLD
+ Particle.getParticleFromId(this.outputParticle)
.getLocalisedName()
+ " "
+ EnumChatFormatting.RESET,
StatCollector.translateToLocal("beamline.energy") + ": "
+ EnumChatFormatting.DARK_RED
+ this.outputEnergy
+ EnumChatFormatting.RESET
+ " keV",
StatCollector.translateToLocal(
"beamline.focus") + ": " + EnumChatFormatting.BLUE + this.outputFocus + " " + EnumChatFormatting.RESET,
StatCollector.translateToLocal("beamline.amount") + ": "
+ EnumChatFormatting.LIGHT_PURPLE
+ this.outputRate, };
}
@Override
public void construct(ItemStack stackSize, boolean hintsOnly) {
buildPiece("sc", stackSize, hintsOnly, 2, 4, 0);
}
@Override
public IStructureDefinition<SourceChamber> getStructureDefinition() {
return STRUCTURE_DEFINITION;
}
@Override
public boolean isCorrectMachinePart(ItemStack aStack) {
return true;
}
@Override
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
this.mOutputBeamline.clear(); // Necessary due to the nature of the beamline hatch adder
return checkPiece("sc", 2, 4, 0) && this.mMaintenanceHatches.size() == 1
&& this.mInputBusses.size() == 1
&& this.mOutputBusses.size() == 1
&& this.mOutputBeamline.size() == 1
&& this.mEnergyHatches.size() == 1;
}
@Override
public int getMaxEfficiency(ItemStack aStack) {
return 10000;
}
@Override
public int getDamageToComponent(ItemStack aStack) {
return 0;
}
@Override
public boolean explodesOnComponentBreak(ItemStack aStack) {
return false;
}
@Override
public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection side, ForgeDirection facing,
int colorIndex, boolean active, boolean redstoneLevel) {
// Placeholder
if (side == facing) {
if (active) return new ITexture[] { casingTexturePages[1][14], TextureFactory.builder()
.addIcon(OVERLAY_FRONT_OIL_CRACKER_ACTIVE)
.extFacing()
.build(),
TextureFactory.builder()
.addIcon(OVERLAY_FRONT_OIL_CRACKER_ACTIVE_GLOW)
.extFacing()
.glow()
.build() };
return new ITexture[] { casingTexturePages[1][14], TextureFactory.builder()
.addIcon(OVERLAY_FRONT_OIL_CRACKER)
.extFacing()
.build(),
TextureFactory.builder()
.addIcon(OVERLAY_FRONT_OIL_CRACKER_GLOW)
.extFacing()
.glow()
.build() };
}
return new ITexture[] { casingTexturePages[1][14] };
}
}
|