Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
Cleanup isValidMetaTileEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
miozune authored and Dream-Master committed Oct 30, 2023
1 parent 31f8e0d commit 08b19f5
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 72 deletions.
44 changes: 33 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
.gradle/
.idea/
out/
.gradle
.settings
/.idea/
/.vscode/
/run/
/build/
/eclipse/
.classpath
.project
/bin/
/config/
/crash-reports/
/logs/
options.txt
/saves/
usernamecache.json
banned-ips.json
banned-players.json
eula.txt
ops.json
server.properties
servers.dat
usercache.json
whitelist.json
/out/
*.iml
*.ipr
*.iws
run/
bin/
build/
src/main/resources/mixins.*([!.]).json
*.bat
layout.json
.settings/
.vscode/
.classpath
.project
*.DS_Store
!gradlew.bat
.factorypath
addon.local.gradle
addon.local.gradle.kts
addon.late.local.gradle
addon.late.local.gradle.kts
layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static goodgenerator.util.DescTextLocalization.BLUE_PRINT_INFO;
import static gregtech.api.enums.Textures.BlockIcons.*;
import static gregtech.api.util.GT_StructureUtility.*;
import static gregtech.api.util.GT_Utility.filterValidMTEs;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -196,15 +197,14 @@ public boolean onRunningTick(ItemStack aStack) {
this.mMaxProgresstime = 20;
int steam = 0;

for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) {
for (GT_MetaTileEntity_Hatch_Input tHatch : filterValidMTEs(mInputHatches)) {
steam += maybeDrainHatch(tHatch);
}
addOutput(GT_ModHandler.getDistilledWater(steam / 160));
return CheckRecipeResultRegistry.SUCCESSFUL;
}

private int maybeDrainHatch(GT_MetaTileEntity_Hatch_Input tHatch) {
if (!isValidMetaTileEntity(tHatch)) return 0;
if (tHatch instanceof GT_MetaTileEntity_Hatch_MultiInput) {
int drained = 0;
for (FluidStack maybeSteam : ((GT_MetaTileEntity_Hatch_MultiInput) tHatch).getStoredFluid()) {
Expand All @@ -216,7 +216,7 @@ private int maybeDrainHatch(GT_MetaTileEntity_Hatch_Input tHatch) {
}

private int maybeDrainSteam(GT_MetaTileEntity_Hatch_Input tHatch, FluidStack maybeSteam) {
if (!isValidMetaTileEntity(tHatch) || maybeSteam == null) return 0;
if (maybeSteam == null) return 0;
if (!GT_Utility.areFluidsEqual(maybeSteam, GT_ModHandler.getSteam(1))) return 0;
FluidStack defoSteam = tHatch.drain(ForgeDirection.UNKNOWN, maybeSteam, true);
return defoSteam.amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY;
import static gregtech.api.util.GT_StructureUtility.ofFrame;
import static gregtech.api.util.GT_Utility.filterValidMTEs;

import java.util.Collections;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -360,15 +361,11 @@ public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {

private int checkEnergyHatchTier() {
int tier = 0;
for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) {
if (isValidMetaTileEntity(tHatch)) {
tier = Math.max(tHatch.mTier, tier);
}
for (GT_MetaTileEntity_Hatch_Energy tHatch : filterValidMTEs(mEnergyHatches)) {
tier = Math.max(tHatch.mTier, tier);
}
for (GT_MetaTileEntity_Hatch tHatch : mExoticEnergyHatches) {
if (isValidMetaTileEntity(tHatch)) {
tier = Math.max(tHatch.mTier, tier);
}
for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mExoticEnergyHatches)) {
tier = Math.max(tHatch.mTier, tier);
}
return tier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static goodgenerator.util.DescTextLocalization.BLUE_PRINT_INFO;
import static gregtech.api.enums.Textures.BlockIcons.*;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import static gregtech.api.util.GT_Utility.filterValidMTEs;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -350,12 +351,10 @@ public int findLiquidAmount(FluidStack liquid, List<FluidStack> input) {
}

public void consumeAllLiquid(FluidStack liquid) {
for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) {
if (isValidMetaTileEntity(tHatch)) {
FluidStack tLiquid = tHatch.getFluid();
if (tLiquid != null && tLiquid.isFluidEqual(liquid)) {
tHatch.drain(tLiquid.amount, true);
}
for (GT_MetaTileEntity_Hatch_Input tHatch : filterValidMTEs(mInputHatches)) {
FluidStack tLiquid = tHatch.getFluid();
if (tLiquid != null && tLiquid.isFluidEqual(liquid)) {
tHatch.drain(tLiquid.amount, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.util.GT_StructureUtility.*;
import static gregtech.api.util.GT_Utility.filterValidMTEs;

import java.util.ArrayList;

Expand Down Expand Up @@ -224,23 +225,19 @@ public boolean explodesOnComponentBreak(ItemStack aStack) {

public long getMaximumOutput() {
long aTotal = 0;
for (GT_MetaTileEntity_Hatch_Dynamo aDynamo : mDynamoHatches) {
if (isValidMetaTileEntity(aDynamo)) {
long aVoltage = aDynamo.maxEUOutput();
aTotal = aDynamo.maxAmperesOut() * aVoltage;
break;
}
for (GT_MetaTileEntity_Hatch_Dynamo aDynamo : filterValidMTEs(mDynamoHatches)) {
long aVoltage = aDynamo.maxEUOutput();
aTotal = aDynamo.maxAmperesOut() * aVoltage;
break;
}
return aTotal;
}

@Override
public String[] getInfoData() {
int mPollutionReduction = 0;
for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) {
if (isValidMetaTileEntity(tHatch)) {
mPollutionReduction = Math.max(tHatch.calculatePollutionReduction(100), mPollutionReduction);
}
for (GT_MetaTileEntity_Hatch_Muffler tHatch : filterValidMTEs(mMufflerHatches)) {
mPollutionReduction = Math.max(tHatch.calculatePollutionReduction(100), mPollutionReduction);
}

String tRunning = mMaxProgresstime > 0
Expand All @@ -263,11 +260,9 @@ public String[] getInfoData() {

long storedEnergy = 0;
long maxEnergy = 0;
for (GT_MetaTileEntity_Hatch_Dynamo tHatch : mDynamoHatches) {
if (isValidMetaTileEntity(tHatch)) {
storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU();
maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity();
}
for (GT_MetaTileEntity_Hatch_Dynamo tHatch : filterValidMTEs(mDynamoHatches)) {
storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU();
maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity();
}
String[] ret = new String[] {
// 8 Lines available for information panels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.gtnewhorizon.structurelib.structure.StructureUtility.*;
import static gregtech.api.enums.Textures.BlockIcons.*;
import static gregtech.api.util.GT_StructureUtility.ofFrame;
import static gregtech.api.util.GT_Utility.filterValidMTEs;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayerMP;
Expand Down Expand Up @@ -263,38 +264,35 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if (mStartUpCheck < 0) {
if (mMachine) {
if (this.mEnergyHatches != null) {
for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches)
if (isValidMetaTileEntity(tHatch)) {
if (aBaseMetaTileEntity.getStoredEU()
+ (2048L * tierOverclock() * getMaxPara() * extraPara(100)) < maxEUStore()
&& tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(
2048L * tierOverclock() * getMaxPara() * extraPara(100),
false)) {
aBaseMetaTileEntity.increaseStoredEnergyUnits(
for (GT_MetaTileEntity_Hatch_Energy tHatch : filterValidMTEs(mEnergyHatches)) {
if (aBaseMetaTileEntity.getStoredEU()
+ (2048L * tierOverclock() * getMaxPara() * extraPara(100)) < maxEUStore()
&& tHatch.getBaseMetaTileEntity().decreaseStoredEnergyUnits(
2048L * tierOverclock() * getMaxPara() * extraPara(100),
true);
} else if (aBaseMetaTileEntity.getStoredEU() + (2048L * tierOverclock()) < maxEUStore()
&& tHatch.getBaseMetaTileEntity()
.decreaseStoredEnergyUnits(2048L * tierOverclock(), false)) {
aBaseMetaTileEntity
.increaseStoredEnergyUnits(2048L * tierOverclock(), true);
}
}
false)) {
aBaseMetaTileEntity.increaseStoredEnergyUnits(
2048L * tierOverclock() * getMaxPara() * extraPara(100),
true);
} else if (aBaseMetaTileEntity.getStoredEU() + (2048L * tierOverclock()) < maxEUStore()
&& tHatch.getBaseMetaTileEntity()
.decreaseStoredEnergyUnits(2048L * tierOverclock(), false)) {
aBaseMetaTileEntity
.increaseStoredEnergyUnits(2048L * tierOverclock(), true);
}
}
}
if (this.eEnergyMulti != null) {
for (GT_MetaTileEntity_Hatch_EnergyMulti tHatch : eEnergyMulti)
if (isValidMetaTileEntity(tHatch)) {
if (aBaseMetaTileEntity.getStoredEU() + getSingleHatchPower() < maxEUStore()
&& tHatch.getBaseMetaTileEntity()
.decreaseStoredEnergyUnits(getSingleHatchPower(), false)) {
aBaseMetaTileEntity.increaseStoredEnergyUnits(getSingleHatchPower(), true);
} else if (aBaseMetaTileEntity.getStoredEU() + (2048L * tierOverclock()) < maxEUStore()
&& tHatch.getBaseMetaTileEntity()
.decreaseStoredEnergyUnits(2048L * tierOverclock(), false)) {
aBaseMetaTileEntity
.increaseStoredEnergyUnits(2048L * tierOverclock(), true);
}
}
for (GT_MetaTileEntity_Hatch_EnergyMulti tHatch : filterValidMTEs(eEnergyMulti)) {
if (aBaseMetaTileEntity.getStoredEU() + getSingleHatchPower() < maxEUStore() && tHatch
.getBaseMetaTileEntity().decreaseStoredEnergyUnits(getSingleHatchPower(), false)) {
aBaseMetaTileEntity.increaseStoredEnergyUnits(getSingleHatchPower(), true);
} else if (aBaseMetaTileEntity.getStoredEU() + (2048L * tierOverclock()) < maxEUStore()
&& tHatch.getBaseMetaTileEntity()
.decreaseStoredEnergyUnits(2048L * tierOverclock(), false)) {
aBaseMetaTileEntity
.increaseStoredEnergyUnits(2048L * tierOverclock(), true);
}
}
}
if (aBaseMetaTileEntity.getStoredEU() <= 0 && mMaxProgresstime > 0) {
stopMachine();
Expand Down

0 comments on commit 08b19f5

Please sign in to comment.