Gregtech++ [GT++] [GTplusplus]

Gregtech++ [GT++] [GTplusplus]

94.1k Downloads

LFTR Logic.

draknyte1 opened this issue ยท 3 comments

commented

So, this general approach 'works', but it's rather wrong and I feel as though I'm overlooking something minor. If anyone wanted to give me a hand in either rewriting it or some suggestions for a better implementation, it would be hugely appreciated. the Recipe Map is simply for display, I don't actually use the recipes as shown in NEI.

Most of this was written on my laptop which I cannot actually run the game on, upon testing today on my desktop, it is functional, but it's meh.

@Techlone @Muramasa- @Blood-Asp @codewarrior0 @Dragon2488 @Technus @Namikon

public boolean checkRecipe(final ItemStack aStack) {
		final ArrayList<FluidStack> tFluids = this.getStoredFluids();
		final Collection<GT_Recipe> tRecipeList = Recipe_GT.Gregtech_Recipe_Map.sLiquidFluorineThoriumReactorRecipes.mRecipeList;
		if((tFluids.size() > 0) && (tRecipeList != null)) { //Does input hatch have a LFTR fuel?
			Utils.LOG_INFO("Found more than one input fluid and a list of valid recipes.");
			final boolean containsFLIBE = false;
			final boolean containsPrimarySalt = false;
			for (final FluidStack hatchFluid1 : tFluids) { //Loops through hatches
				Utils.LOG_INFO("Looping through Input hatches - Found "+hatchFluid1.getLocalizedName());
				for(final GT_Recipe aFuel : tRecipeList) { //Loops through LFTR fuel recipes
					Utils.LOG_INFO("Looping through Recipes. "+aFuel.mSpecialValue);
					FluidStack tLiquid;
					final FluidStack testStack = aFuel.mFluidInputs[1];
					if ((tLiquid = testStack) != null) { //Create fluidstack from current recipe
						Utils.LOG_INFO("Creating a fluidstack from the current recipe. "+testStack.getLocalizedName());
						if (hatchFluid1.isFluidEqual(tLiquid)) { //Has a LFTR fluid
							this.fuelConsumption = tLiquid.amount = this.boostEu ? (aFuel.mSpecialValue/4096) : (aFuel.mSpecialValue/2048); //Calc fuel consumption
							Utils.LOG_INFO("Input hatch contains some FLiBe Fuel, using "+this.fuelConsumption);
							if(this.depleteInput(tLiquid)) { //Deplete that amount
								Utils.LOG_INFO("Depleted some FLiBe fluid");

								this.mMaxProgresstime = 500;
								
								if(tFluids.contains(NUCLIDE.LiFBeF2ThF4UF4.getFluid(1)) ||
										tFluids.contains(NUCLIDE.LiFBeF2ZrF4UF4.getFluid(2)) ||
										tFluids.contains(NUCLIDE.LiFBeF2ZrF4U235.getFluid(10))) { //Has a Primary fuel salt?
									//Deplete Primary Salt. 1000L should = 1 hour of runtime (if baseEU = 2048) && using 1l each time
									if(((this.mRuntime % 72) == 0) || (this.mRuntime == 0)){
										//U235 fuel is 10x less efficient than UF4 with Thorium, UF4 with Zirconium is only 2x less efficient than UF4 with Thorium.
										//Most Efficient
										if(tFluids.contains(NUCLIDE.LiFBeF2ThF4UF4.getFluid(2))){
											this.depleteInput(NUCLIDE.LiFBeF2ThF4UF4.getFluid(this.boostEu ? 2 : 1));
											Utils.LOG_INFO("Depleted "+(this.boostEu ? 2 : 1)+"L of LiFBeF2ThF4UF4 fluid");
										}
										//1/2 as Efficient
										if (tFluids.contains(NUCLIDE.LiFBeF2ZrF4UF4.getFluid(4))){
											this.depleteInput(NUCLIDE.LiFBeF2ZrF4UF4.getFluid(this.boostEu ? 4 : 2));
											Utils.LOG_INFO("Depleted "+(this.boostEu ? 4 : 2)+"L of LiFBeF2ZrF4UF4 fluid");
										}
										//10x less Efficient.
										if (tFluids.contains(NUCLIDE.LiFBeF2ZrF4U235.getFluid(20))) {
											this.depleteInput(NUCLIDE.LiFBeF2ZrF4U235.getFluid(this.boostEu ? 20 : 10));
											Utils.LOG_INFO("Depleted "+(this.boostEu ? 20 : 10)+"L of LiFBeF2ZrF4U235 fluid");
										}
									}
								} else {
									return false;
								}


								//Try Sparge Noble Gases
								if (this.heliumSparging){
									if (this.depleteInput(Materials.Helium.getGas(1000L))){
										//Make an empty fluid stack for possible sparging output
										FluidStack[] spargeOutput = new FluidStack[]{};
										Utils.LOG_INFO("Doing a Sparge with Helium - "+this.heliumSparging);
										this.heliumSparging = false;
										spargeOutput = this.getByproductsOfSparge(Materials.Helium.getGas(1000L));
										
										//If Sparging occurred, try add the outputs to the output hatches.
										try {
											if (spargeOutput.length >= 1){
												for (final FluidStack F : spargeOutput){
													Utils.LOG_INFO("Adding Sparge Output - "+F.getLocalizedName());
													this.addOutput(F);
												}
											}
										} catch (final Throwable T){}
									}
								}
								//Try Sparge Fluorides
								else {
									if (this.depleteInput(Materials.Fluorine.getGas(100L))){
										//Make an empty fluid stack for possible sparging output
										FluidStack[] spargeOutput = new FluidStack[]{};
										Utils.LOG_INFO("Doing a Sparge with Fluorine");
										spargeOutput = this.getByproductsOfSparge(Materials.Fluorine.getGas(100L));
										this.heliumSparging = true;
										//If Sparging occurred, try add the outputs to the output hatches.
										if (spargeOutput.length > 0){
											for (final FluidStack F : spargeOutput){
												Utils.LOG_INFO("Adding Sparge Output - "+F.getLocalizedName());
												this.addOutput(F);
											}
										}
									}
								}


								if (aFuel != null){
									//Utils.LOG_INFO("Saving previous Recipe.");
									//this.mLastRecipe = aFuel;
								}


								this.fuelValue = aFuel.mSpecialValue;
								this.fuelRemaining = hatchFluid1.amount; //Record available fuel

								if (this.mEfficiency < 500){
									this.mEfficiency++;
									this.mMaxProgresstime = 500;
								}
								else if (this.mEfficiency == 500) {
									this.mMaxProgresstime = 300;
								}
								Utils.LOG_INFO("Efficiency == "+this.mEfficiency);

								this.mEUt = (this.mEfficiency < 500 ? 2048 : (8196*4)); //Output 0 if startup is less than 20%
								Utils.LOG_INFO("Generating "+this.mEUt+"EU/t @ an efficiency level of "+this.mEfficiency);

								this.mProgresstime = 1;
								this.mMaxProgresstime = 1;
								this.mEfficiencyIncrease = 15;

								//Best output some Fluids
								//this.mOutputFluids = this.mLastRecipe.mFluidOutputs;

								return true;
							}
						}
					}
				}
			}
		}
		this.mEUt = 0;
		this.mEfficiency = 0;
		return false;
	}
commented
if (this.mEfficiency < 500){
	this.mEfficiency++;
	this.mMaxProgresstime = 500;
}
else if (this.mEfficiency == 500) {
	this.mMaxProgresstime = 300;
}
Utils.LOG_INFO("Efficiency == "+this.mEfficiency);

this.mEUt = (this.mEfficiency < 500 ? 2048 : (8196*4)); //Output 0 if startup is less than 20%
Utils.LOG_INFO("Generating "+this.mEUt+"EU/t @ an efficiency level of "+this.mEfficiency);

this.mProgresstime = 1; //???
this.mMaxProgresstime = 1; //???
this.mEfficiencyIncrease = 15;

one does not simply make the recipe one tick long, or is it only for testing purposes?

if you feel like making it less meh, think about custom hatches for extra control. (like flow/cooling/ etc. regulation)

You are looking for suggestions for mechanics or optimization?

commented

Optimisation ~
Not sure how to go about this after writing it without testing, then testing and having it work rather shoddy.

commented

finished in a35fbfb