Skip to content

Commit

Permalink
THTR
Browse files Browse the repository at this point in the history
Use checkProcessing() over checkRecipe()
Rename some variables for readability
  • Loading branch information
purebluez authored and serenibyss committed Dec 23, 2024
1 parent c466bc6 commit c06de25
Showing 1 changed file with 69 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.NotNull;

import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
Expand All @@ -43,13 +45,25 @@
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.MTEEnhancedMultiBlockBase;
import gregtech.api.metatileentity.implementations.MTEHatchInput;
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTUtility;
import gregtech.api.util.MultiblockTooltipBuilder;

public class MTEThoriumHighTempReactor extends MTEEnhancedMultiBlockBase<MTEThoriumHighTempReactor> {

private static final int BASECASINGINDEX = 44;
private int mCasingAmount = 0;

private static final int HELIUM_NEEDED = 730000;
private static final int powerUsage = (int) TierEU.RECIPE_IV / 2;
private static final int maxCapacity = 675000;
private static final int minCapacityToStart = 100000;
private int HeliumSupply;
private int fuelSupply;
private boolean emptyingMode;
private int coolingPerTick = 0;

private static final String STRUCTURE_PIECE_MAIN = "main";
private static final IStructureDefinition<MTEThoriumHighTempReactor> STRUCTURE_DEFINITION = StructureDefinition
Expand Down Expand Up @@ -82,33 +96,23 @@ public class MTEThoriumHighTempReactor extends MTEEnhancedMultiBlockBase<MTEThor
"c---------c", "c---------c", "c---------c", " c-------c ", " ccccccc " },
{ " bbb~bbb ", " bbbbbbbbb ", "bbbbbbbbbbb", "bbbbbbbbbbb", "bbbbbbbbbbb", "bbbbbbbbbbb",
"bbbbbbbbbbb", "bbbbbbbbbbb", "bbbbbbbbbbb", " bbbbbbbbb ", " bbbbbbb " }, }))
.addElement('c', onElementPass(x -> x.mCasing++, ofBlock(GregTechAPI.sBlockCasings3, 12)))
.addElement('c', onElementPass(x -> x.mCasingAmount++, ofBlock(GregTechAPI.sBlockCasings3, 12)))
.addElement(
'b',
ofChain(
ofHatchAdder(MTEThoriumHighTempReactor::addOutputToMachineList, BASECASINGINDEX, 1),
ofHatchAdder(MTEThoriumHighTempReactor::addMaintenanceToMachineList, BASECASINGINDEX, 1),
ofHatchAdder(MTEThoriumHighTempReactor::addEnergyInputToMachineList, BASECASINGINDEX, 1),
onElementPass(x -> x.mCasing++, ofBlock(GregTechAPI.sBlockCasings3, 12))))
onElementPass(x -> x.mCasingAmount++, ofBlock(GregTechAPI.sBlockCasings3, 12))))
.addElement(
'B',
ofChain(
ofHatchAdder(MTEThoriumHighTempReactor::addInputToMachineList, BASECASINGINDEX, 2),
onElementPass(x -> x.mCasing++, ofBlock(GregTechAPI.sBlockCasings3, 12))))
onElementPass(x -> x.mCasingAmount++, ofBlock(GregTechAPI.sBlockCasings3, 12))))
// ofHatchAdderOptional(GT_TileEntity_THTR::addInputToMachineList, BASECASINGINDEX, 2,
// GregTechAPI.sBlockCasings3, 12))
.build();

private static final int HELIUM_NEEDED = 730000;
private static final int powerUsage = (int) TierEU.RECIPE_IV / 2;
private static final int maxcapacity = 675000;
private static final int mincapacity = 100000;
private int HeliumSupply;
private int fuelsupply;
private boolean empty;
private int coolanttaking = 0;
private int mCasing = 0;

public MTEThoriumHighTempReactor(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}
Expand Down Expand Up @@ -165,8 +169,8 @@ public void construct(ItemStack stackSize, boolean hintsOnly) {

@Override
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack itemStack) {
this.mCasing = 0;
return this.checkPiece(STRUCTURE_PIECE_MAIN, 5, 11, 0) && this.mCasing >= 500
this.mCasingAmount = 0;
return this.checkPiece(STRUCTURE_PIECE_MAIN, 5, 11, 0) && this.mCasingAmount >= 500
&& this.mMaintenanceHatches.size() == 1
&& !this.mInputHatches.isEmpty()
&& !this.mOutputHatches.isEmpty()
Expand All @@ -179,24 +183,24 @@ public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack i
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
this.HeliumSupply = aNBT.getInteger("HeliumSupply");
this.fuelsupply = aNBT.getInteger("fuelsupply");
this.coolanttaking = aNBT.getInteger("coolanttaking");
this.empty = aNBT.getBoolean("EmptyMode");
this.fuelSupply = aNBT.getInteger("fuelsupply");
this.coolingPerTick = aNBT.getInteger("coolanttaking");
this.emptyingMode = aNBT.getBoolean("EmptyMode");
}

@Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setInteger("HeliumSupply", this.HeliumSupply);
aNBT.setInteger("fuelsupply", this.fuelsupply);
aNBT.setInteger("coolanttaking", this.coolanttaking);
aNBT.setBoolean("EmptyMode", this.empty);
aNBT.setInteger("fuelsupply", this.fuelSupply);
aNBT.setInteger("coolanttaking", this.coolingPerTick);
aNBT.setBoolean("EmptyMode", this.emptyingMode);
}

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
if (aBaseMetaTileEntity.isServerSide() && !this.empty) {
if (aBaseMetaTileEntity.isServerSide() && !this.emptyingMode) {
if (this.HeliumSupply < MTEThoriumHighTempReactor.HELIUM_NEEDED) {
for (FluidStack fluidStack : this.getStoredFluids()) {
if (fluidStack.isFluidEqual(Materials.Helium.getGas(1))) {
Expand All @@ -207,16 +211,16 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}
}
}
if (this.fuelsupply < maxcapacity) {
if (this.fuelSupply < maxCapacity) {
this.startRecipeProcessing();
for (ItemStack itemStack : this.getStoredInputs()) {
if (GTUtility.areStacksEqual(
itemStack,
new ItemStack(THTRMaterials.aTHTR_Materials, 1, THTRMaterials.MATERIAL_FUEL_INDEX))) {
int toget = Math.min(maxcapacity - this.fuelsupply, itemStack.stackSize);
int toget = Math.min(maxCapacity - this.fuelSupply, itemStack.stackSize);
if (toget == 0) continue;
itemStack.stackSize -= toget;
this.fuelsupply += toget;
this.fuelSupply += toget;
}
}
this.endRecipeProcessing();
Expand All @@ -225,64 +229,64 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}
}

@Override
public boolean checkRecipe(ItemStack controllerStack) {

if (this.empty) {
if (this.HeliumSupply > 0 || this.fuelsupply > 0) {
this.mEfficiency = 10000;
this.mMaxProgresstime = 100;
return true;
}
return false;
}
if (this.HeliumSupply < MTEThoriumHighTempReactor.HELIUM_NEEDED || this.fuelsupply < mincapacity) return false;
private double getEfficiency() {
return Math.min(
Math.pow((this.fuelSupply - minCapacityToStart) / ((maxCapacity - minCapacityToStart) / 10D), 2D) + 1,
100D) / 100D - (this.getIdealStatus() - this.getRepairStatus()) / 10D;
}

double eff = Math
.min(Math.pow((this.fuelsupply - mincapacity) / ((maxcapacity - mincapacity) / 10D), 2D) + 1, 100D) / 100D
- (this.getIdealStatus() - this.getRepairStatus()) / 10D;
if (eff <= 0D) return false;
@Override
public @NotNull CheckRecipeResult checkProcessing() {
if (emptyingMode) {
if (!(HeliumSupply > 0 || fuelSupply > 0)) return CheckRecipeResultRegistry.NO_RECIPE;
this.mEfficiency = 10000;
this.mMaxProgresstime = 100;
} else {
if (this.HeliumSupply < MTEThoriumHighTempReactor.HELIUM_NEEDED || this.fuelSupply < minCapacityToStart)
return CheckRecipeResultRegistry.NO_RECIPE;

int toReduce = MathUtils.floorInt(this.fuelsupply * 0.005D * eff);
double efficiency = getEfficiency();
if (efficiency <= 0.0) return CheckRecipeResultRegistry.NO_RECIPE;

final int originalToReduce = toReduce;
int burnedballs = toReduce / 64;
if (burnedballs > 0) toReduce -= burnedballs * 64;
int toReduce = MathUtils.floorInt(this.fuelSupply * 0.005D * efficiency);

int meta = THTRMaterials.MATERIAL_USED_FUEL_INDEX;
final int originalToReduce = toReduce;
int burnedBalls = toReduce / 64;
if (burnedBalls > 0) toReduce -= burnedBalls * 64;

ItemStack[] toOutput = { new ItemStack(THTRMaterials.aTHTR_Materials, burnedballs, meta),
new ItemStack(THTRMaterials.aTHTR_Materials, toReduce, meta + 1) };
if (!this.canOutputAll(toOutput)) return false;
int meta = THTRMaterials.MATERIAL_USED_FUEL_INDEX;

this.fuelsupply -= originalToReduce;
this.mOutputItems = toOutput;
ItemStack[] toOutput = { new ItemStack(THTRMaterials.aTHTR_Materials, burnedBalls, meta),
new ItemStack(THTRMaterials.aTHTR_Materials, toReduce, meta + 1) };
if (!this.canOutputAll(toOutput)) return CheckRecipeResultRegistry.NO_RECIPE;

// this.updateSlots(); not needed ?
this.fuelSupply -= originalToReduce;
this.mOutputItems = toOutput;

this.coolanttaking = (int) (4800D * eff);
this.mEfficiency = (int) (eff * 10000D);
this.mEUt = -powerUsage;
this.mMaxProgresstime = 648000;
return true;
this.coolingPerTick = (int) (4800.0 * efficiency);
this.mEfficiency = (int) (efficiency * 10000.0);
this.mEUt = -powerUsage;
this.mMaxProgresstime = 648000;
}
return CheckRecipeResultRegistry.SUCCESSFUL;
}

@Override
public boolean onRunningTick(ItemStack aStack) {

if (this.empty) {
if (this.emptyingMode) {
this.addOutput(Materials.Helium.getGas(this.HeliumSupply));
this.addOutput(
new ItemStack(THTRMaterials.aTHTR_Materials, this.fuelsupply, THTRMaterials.MATERIAL_FUEL_INDEX));
new ItemStack(THTRMaterials.aTHTR_Materials, this.fuelSupply, THTRMaterials.MATERIAL_FUEL_INDEX));
this.HeliumSupply = 0;
this.fuelsupply = 0;
this.fuelSupply = 0;
this.updateSlots();
return true;
}

if (!super.onRunningTick(aStack)) return false;

int takecoolant = this.coolanttaking;
int takecoolant = this.coolingPerTick;
int drainedamount = 0;

for (MTEHatchInput tHatch : validMTEList(mInputHatches)) {
Expand Down Expand Up @@ -329,12 +333,12 @@ public String[] getInfoData() {
+ GTUtility.formatNumbers(this.mMaxProgresstime / 20)
+ "secs",
"TRISO-Pebbles:",
GTUtility.formatNumbers(this.fuelsupply) + "pcs. / " + GTUtility.formatNumbers(this.fuelsupply) + "psc.",
GTUtility.formatNumbers(this.fuelSupply) + "pcs. / " + GTUtility.formatNumbers(this.fuelSupply) + "psc.",
"Helium-Level:",
GTUtility.formatNumbers(this.HeliumSupply) + "L / "
+ GTUtility.formatNumbers(MTEThoriumHighTempReactor.HELIUM_NEEDED)
+ "L",
"Coolant/t:", GTUtility.formatNumbers(this.mProgresstime == 0 ? 0 : this.coolanttaking) + "L/t",
"Coolant/t:", GTUtility.formatNumbers(this.mProgresstime == 0 ? 0 : this.coolingPerTick) + "L/t",
"Problems:", String.valueOf(this.getIdealStatus() - this.getRepairStatus()) };
}

Expand Down Expand Up @@ -374,10 +378,10 @@ public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, f
GTUtility.sendChatToPlayer(aPlayer, "THTR mode cannot be changed while the machine is running.");
return;
}
this.empty = !this.empty;
this.emptyingMode = !this.emptyingMode;
GTUtility.sendChatToPlayer(
aPlayer,
"THTR is now running in " + (this.empty ? "emptying mode." : "normal Operation"));
"THTR is now running in " + (this.emptyingMode ? "emptying mode." : "normal Operation"));
}

@Override
Expand Down

0 comments on commit c06de25

Please sign in to comment.