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
|
package goodgenerator.blocks.tileEntity;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.util.GTStructureUtility.buildHatchAdder;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import org.jetbrains.annotations.NotNull;
import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import com.gtnewhorizon.structurelib.structure.StructureUtility;
import goodgenerator.api.recipe.GoodGeneratorRecipeMaps;
import goodgenerator.blocks.tileEntity.base.MTETooltipMultiBlockBaseEM;
import goodgenerator.loader.Loaders;
import goodgenerator.util.DescTextLocalization;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.logic.ProcessingLogic;
import gregtech.api.metatileentity.implementations.MTEHatch;
import gregtech.api.metatileentity.implementations.MTEHatchEnergy;
import gregtech.api.metatileentity.implementations.MTEHatchInput;
import gregtech.api.metatileentity.implementations.MTEHatchInputBus;
import gregtech.api.metatileentity.implementations.MTEHatchOutput;
import gregtech.api.objects.GTRenderedTexture;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTRecipe;
import gregtech.api.util.GTUtility;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.api.util.OverclockCalculator;
import tectech.thing.metaTileEntity.hatch.MTEHatchEnergyMulti;
public class MTEFuelRefineFactory extends MTETooltipMultiBlockBaseEM implements IConstructable, ISurvivalConstructable {
private IStructureDefinition<MTEFuelRefineFactory> multiDefinition = null;
private int Tier = -1;
private final int[] cnt = new int[] { 0, 0, 0, 0 };
private static final Block[] coils = new Block[] { Loaders.FRF_Coil_1, Loaders.FRF_Coil_2, Loaders.FRF_Coil_3,
Loaders.FRF_Coil_4 };
public MTEFuelRefineFactory(String name) {
super(name);
useLongPower = true;
}
public MTEFuelRefineFactory(int id, String name, String nameRegional) {
super(id, name, nameRegional);
useLongPower = true;
}
@Override
public boolean doRandomMaintenanceDamage() {
return true;
}
@Override
public void construct(ItemStack itemStack, boolean hintsOnly) {
structureBuild_EM(mName, 7, 12, 1, itemStack, hintsOnly);
}
@Override
public IStructureDefinition<MTEFuelRefineFactory> getStructure_EM() {
if (multiDefinition == null) {
multiDefinition = StructureDefinition.<MTEFuelRefineFactory>builder()
.addShape(
mName,
transpose(
new String[][] { { " ", " CCC ", " " },
{ " XGX ", " CCFFFCC ", " XGX " },
{ " CC CC ", " CFFCCCFFC ", " CC CC " },
{ " C C ", " CFCC CCFC ", " C C " },
{ " C C ", " CFC CFC ", " C C " },
{ " C C ", " CFC CFC ", " C C " },
{ " X X ", "CFC CFC", " X X " },
{ " G G ", "CFC CFC", " G G " },
{ " X X ", "CFC CFC", " X X " },
{ " C C ", " CFC CFC ", " C C " },
{ " C C ", " CFC CFC ", " C C " },
{ " C C ", " CFCC CCFC ", " C C " },
{ " CC CC ", " CFFC~CFFC ", " CC CC " },
{ " XGX ", " CCFFFCC ", " XGX " },
{ " ", " CCC ", " " } }))
.addElement(
'X',
buildHatchAdder(MTEFuelRefineFactory.class)
.atLeast(
gregtech.api.enums.HatchElement.Maintenance,
gregtech.api.enums.HatchElement.InputHatch,
gregtech.api.enums.HatchElement.InputBus,
gregtech.api.enums.HatchElement.OutputHatch,
tectech.thing.metaTileEntity.multi.base.TTMultiblockBase.HatchElement.EnergyMulti
.or(gregtech.api.enums.HatchElement.Energy))
.casingIndex(179)
.dot(1)
.buildAndChain(ofBlock(Loaders.FRF_Casings, 0)))
.addElement('C', ofBlock(Loaders.FRF_Casings, 0))
.addElement('G', ofBlock(Loaders.fieldRestrictingGlass, 0))
.addElement(
'F',
ofChain(
onElementPass(x -> ++x.cnt[0], ofFieldCoil(0)),
onElementPass(x -> ++x.cnt[1], ofFieldCoil(1)),
onElementPass(x -> ++x.cnt[2], ofFieldCoil(2)),
onElementPass(x -> ++x.cnt[3], ofFieldCoil(3))))
.build();
}
return multiDefinition;
}
public static <T> IStructureElement<T> ofFieldCoil(int aIndex) {
return new IStructureElement<>() {
@Override
public boolean check(T t, World world, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block.equals(coils[aIndex]);
}
@Override
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
StructureLibAPI.hintParticle(world, x, y, z, coils[getIndex(trigger)], 0);
return true;
}
private int getIndex(ItemStack trigger) {
int s = trigger.stackSize;
if (s > 4 || s <= 0) s = 4;
return s - 1;
}
@Override
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
return world.setBlock(x, y, z, coils[getIndex(trigger)], 0, 3);
}
@Override
public BlocksToPlace getBlocksToPlace(T t, World world, int x, int y, int z, ItemStack trigger,
AutoPlaceEnvironment env) {
return BlocksToPlace.create(coils[getIndex(trigger)], 0);
}
@Override
public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
AutoPlaceEnvironment env) {
if (check(t, world, x, y, z)) return PlaceResult.SKIP;
return StructureUtility.survivalPlaceBlock(
coils[getIndex(trigger)],
0,
world,
x,
y,
z,
env.getSource(),
env.getActor(),
env.getChatter());
}
};
}
@Override
protected MultiblockTooltipBuilder createTooltip() {
final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder();
tt.addMachineType("Naquadah Fuel Refinery")
.addInfo("But at what cost?")
.addInfo("Produces naquadah fuels.")
.addInfo("Needs field restriction coils to control the fatal radiation.")
.addInfo("Use higher tier coils to unlock more fuel types and reduce the processing times.")
.beginStructureBlock(3, 15, 15, false)
.addInputHatch("The casings adjacent to field restriction glass.")
.addInputBus("The casings adjacent to field restriction glass.", 1)
.addOutputHatch("The casings adjacent to field restriction glass.", 1)
.addEnergyHatch("The casings adjacent to field restriction glass.", 1)
.toolTipFinisher();
return tt;
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
this.Tier = aNBT.getInteger("mTier");
super.loadNBTData(aNBT);
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setInteger("mTier", this.Tier);
super.saveNBTData(aNBT);
}
@Override
public String[] getStructureDescription(ItemStack itemStack) {
return DescTextLocalization.addText("FuelRefineFactory.hint", 8);
}
@Override
public boolean checkMachine_EM(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
cnt[0] = 0;
cnt[1] = 0;
cnt[2] = 0;
cnt[3] = 0;
return structureCheck_EM(mName, 7, 12, 1) && getTier() != -1;
}
public int getTier() {
for (int i = 0; i < 4; i++) {
if (cnt[i] == 32) {
Tier = i + 1;
return i;
}
}
Tier = -1;
return -1;
}
@Override
public RecipeMap<?> getRecipeMap() {
return GoodGeneratorRecipeMaps.naquadahFuelRefineFactoryRecipes;
}
@Override
protected ProcessingLogic createProcessingLogic() {
return new ProcessingLogic() {
@NotNull
@Override
protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) {
if (recipe.mSpecialValue > Tier) {
return CheckRecipeResultRegistry.insufficientMachineTier(recipe.mSpecialValue);
}
return CheckRecipeResultRegistry.SUCCESSFUL;
}
@NotNull
@Override
protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) {
int overclockAmount = Tier - recipe.mSpecialValue;
return super.createOverclockCalculator(recipe).limitOverclockCount(overclockAmount);
}
}.setOverclock(4.0, 4.0); // Set Overclock to be 4/4
}
@Override
protected void setProcessingLogicPower(ProcessingLogic logic) {
logic.setAvailableVoltage(getMaxInputEu());
logic.setAvailableAmperage(1);
}
public final boolean addToFRFList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
if (aTileEntity == null) {
return false;
} else {
IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
if (aMetaTileEntity == null) {
return false;
} else {
if (aMetaTileEntity instanceof MTEHatch) {
((MTEHatch) aMetaTileEntity).updateTexture(aBaseCasingIndex);
}
if (aMetaTileEntity instanceof MTEHatchInput) {
return this.mInputHatches.add((MTEHatchInput) aMetaTileEntity);
} else if (aMetaTileEntity instanceof MTEHatchOutput) {
return this.mOutputHatches.add((MTEHatchOutput) aMetaTileEntity);
} else if (aMetaTileEntity instanceof MTEHatchInputBus) {
return this.mInputBusses.add((MTEHatchInputBus) aMetaTileEntity);
} else if (aMetaTileEntity instanceof MTEHatchEnergy) {
return this.mEnergyHatches.add((MTEHatchEnergy) aMetaTileEntity);
} else if (aMetaTileEntity instanceof MTEHatchEnergyMulti) {
return this.eEnergyMulti.add((MTEHatchEnergyMulti) aMetaTileEntity);
} else {
return false;
}
}
}
}
@Override
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTEFuelRefineFactory(this.mName);
}
@Override
public int getMaxEfficiency(ItemStack aStack) {
return 10000;
}
@Override
public int getPollutionPerTick(ItemStack aStack) {
return 0;
}
@Override
public int getDamageToComponent(ItemStack aStack) {
return 0;
}
@Override
public boolean explodesOnComponentBreak(ItemStack aStack) {
return true;
}
@Override
public boolean isCorrectMachinePart(ItemStack aStack) {
return true;
}
@Override
public String[] getInfoData() {
String[] infoData = new String[super.getInfoData().length + 1];
System.arraycopy(super.getInfoData(), 0, infoData, 0, super.getInfoData().length);
infoData[super.getInfoData().length] = StatCollector.translateToLocal("scanner.info.FRF") + " " + this.Tier;
return infoData;
}
@Override
public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer,
float aX, float aY, float aZ) {
batchMode = !batchMode;
if (batchMode) {
GTUtility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("misc.BatchModeTextOn"));
} else {
GTUtility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("misc.BatchModeTextOff"));
}
return true;
}
@Override
public boolean supportsBatchMode() {
return true;
}
@Override
public boolean supportsVoidProtection() {
return true;
}
@Override
@SuppressWarnings("ALL")
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection facing,
int colorIndex, boolean aActive, boolean aRedstone) {
if (side == facing) {
if (aActive) return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(179),
new GTRenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE_ACTIVE), TextureFactory.builder()
.addIcon(Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE_ACTIVE_GLOW)
.glow()
.build() };
return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(179),
new GTRenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE), TextureFactory.builder()
.addIcon(Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE_GLOW)
.glow()
.build() };
}
return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(179) };
}
@Override
public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) {
if (mMachine) return -1;
return survivialBuildPiece(mName, stackSize, 7, 12, 1, elementBudget, env, false, true);
}
@Override
public boolean getDefaultHasMaintenanceChecks() {
return false;
}
}
|