aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java
diff options
context:
space:
mode:
authorAbdiel Kavash <19243993+AbdielKavash@users.noreply.github.com>2024-11-20 11:08:11 -0600
committerGitHub <noreply@github.com>2024-11-20 18:08:11 +0100
commit36acbb9baed7dae4e19fde7a95852b7d002b2f5c (patch)
tree373ef20415a65c444a214a5398b6c550cfc2b5df /src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java
parent4ecb0005608fb5774dee56eb751c850d862fa98d (diff)
downloadGT5-Unofficial-36acbb9baed7dae4e19fde7a95852b7d002b2f5c.tar.gz
GT5-Unofficial-36acbb9baed7dae4e19fde7a95852b7d002b2f5c.tar.bz2
GT5-Unofficial-36acbb9baed7dae4e19fde7a95852b7d002b2f5c.zip
Follow up fixes for multiple muffler hatches. (#3505)
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java84
1 files changed, 62 insertions, 22 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java
index 0550e8da7d..1e29d797a4 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java
@@ -632,23 +632,73 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity
}
public boolean polluteEnvironment(int aPollutionLevel) {
+ final int VENT_AMOUNT = 10_000;
// Early exit if pollution is disabled
if (!GTMod.gregtechproxy.mPollution) return true;
mPollution += aPollutionLevel;
- if (mPollution < 10000) return true;
- var validMufflers = new ArrayList<MTEHatchMuffler>(mMufflerHatches.size());
- validMTEList(mMufflerHatches).forEach(validMufflers::add);
- Collections.shuffle(validMufflers);
- for (MTEHatchMuffler tHatch : validMufflers) {
- if (mPollution >= 10000) {
- if (tHatch.polluteEnvironment(this)) {
- mPollution -= 10000;
- }
+ if (mPollution < VENT_AMOUNT) return true;
+ if (mMufflerHatches.size() == 0) {
+ // No muffler present. Fail.
+ return false;
+ } else if (mMufflerHatches.size() == 1) {
+ // One muffler, use simple method for performance.
+ MTEHatchMuffler muffler = mMufflerHatches.get(0);
+ if (muffler == null || !muffler.isValid()) {
+ // Muffler invalid. Fail.
+ mMufflerHatches.remove(0);
+ return false;
} else {
- break;
+ if (muffler.polluteEnvironment(this, VENT_AMOUNT)) {
+ mPollution -= VENT_AMOUNT;
+ } else {
+ // Muffler blocked. Fail.
+ return false;
+ }
}
+ } else {
+ // Multiple mufflers, split pollution output evenly between all of them.
+ int mufflerCount = 0;
+ int ventAmount = 0; // Allow venting of up to VENT_AMOUNT of pollution per muffler.
+ for (MTEHatchMuffler muffler : validMTEList(mMufflerHatches)) {
+ mufflerCount++;
+ if (ventAmount + VENT_AMOUNT <= mPollution) {
+ ventAmount += VENT_AMOUNT;
+ }
+ }
+ // This might lose some small amount of pollution due to rounding, this is fine.
+ ventAmount /= mufflerCount;
+
+ for (MTEHatchMuffler muffler : validMTEList(mMufflerHatches)) {
+ if (muffler.polluteEnvironment(this, ventAmount)) {
+ mPollution -= ventAmount;
+ } else {
+ // Muffler blocked. Fail.
+ return false;
+ }
+ }
+ }
+ return mPollution < VENT_AMOUNT;
+ }
+
+ /**
+ * How much pollution this outputs to the environment. 100 = outputs all, 0 = outputs none. Calculated as an average
+ * across all muffler hatches.
+ *
+ * @return Fraction of pollution output to the environment (out of 100).
+ */
+ public int getAveragePollutionPercentage() {
+ int pollutionPercent = 0;
+ int mufflerCount = 0;
+ for (MTEHatchMuffler muffler : validMTEList(mMufflerHatches)) {
+ pollutionPercent += muffler.calculatePollutionReduction(100);
+ mufflerCount++;
+ }
+ if (mufflerCount > 0) {
+ pollutionPercent /= mufflerCount;
+ } else {
+ pollutionPercent = 100;
}
- return mPollution < 10000;
+ return pollutionPercent;
}
protected void sendStartMultiBlockSoundLoop() {
@@ -1826,16 +1876,6 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity
@Override
public String[] getInfoData() {
- int mPollutionReduction = 0;
- var validMufflers = new ArrayList<MTEHatchMuffler>(mMufflerHatches.size());
- validMTEList(mMufflerHatches).forEach(validMufflers::add);
- if (validMufflers.size() > 0) {
- for (MTEHatchMuffler tHatch : validMufflers) {
- mPollutionReduction += tHatch.calculatePollutionReduction(100);
- }
- mPollutionReduction /= validMufflers.size();
- }
-
long storedEnergy = 0;
long maxEnergy = 0;
for (MTEHatchEnergy tHatch : validMTEList(mEnergyHatches)) {
@@ -1891,7 +1931,7 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity
+ " %",
/* 6 */ StatCollector.translateToLocal("GT5U.multiblock.pollution") + ": "
+ EnumChatFormatting.GREEN
- + mPollutionReduction
+ + getAveragePollutionPercentage()
+ EnumChatFormatting.RESET
+ " %" };
}