diff options
-rw-r--r-- | src/main/java/goodgenerator/blocks/tileEntity/AntimatterGenerator.java | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/src/main/java/goodgenerator/blocks/tileEntity/AntimatterGenerator.java b/src/main/java/goodgenerator/blocks/tileEntity/AntimatterGenerator.java index b299c0d502..9925ff7529 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/AntimatterGenerator.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/AntimatterGenerator.java @@ -74,10 +74,10 @@ public class AntimatterGenerator extends MTEExtendedPowerMultiBlockBase private UUID owner_uuid; private boolean wirelessEnabled = false; private boolean canUseWireless = true; - private long euCapacity = 0; private long euLastCycle = 0; private float annihilationEfficiency = 0f; public static final long ANTIMATTER_FUEL_VALUE = 1_000_000_000_000L; + private final List<Float> avgEff = new ArrayList<>(10); private static final ClassValue<IStructureDefinition<AntimatterGenerator>> STRUCTURE_DEFINITION = new ClassValue<>() { @@ -178,6 +178,12 @@ public class AntimatterGenerator extends MTEExtendedPowerMultiBlockBase if (i == 2 && containedAntimatter > 0 && catalystFluid != null) { createEU(containedAntimatter, catalystFluid); } + // Set stats if one fluid supplied. + if ((containedAntimatter == 0 && catalystFluid != null) || (containedAntimatter > 0 && catalystFluid == null)) { + this.annihilationEfficiency = 0; + this.euLastCycle = 0; + setAvgEff(0f); + } endRecipeProcessing(); return CheckRecipeResultRegistry.SUCCESSFUL; @@ -203,11 +209,23 @@ public class AntimatterGenerator extends MTEExtendedPowerMultiBlockBase float efficiency = Math .min(((float) antimatter / (float) catalystCount), ((float) catalystCount / (float) antimatter)); this.annihilationEfficiency = efficiency; + setAvgEff(efficiency); generatedEU = (long) ((Math.pow(antimatter, modifier) * ANTIMATTER_FUEL_VALUE) * efficiency); + } else { // Set stats and return if supplied antimatter with incorrect fluid. + this.annihilationEfficiency = 0; + this.euLastCycle = 0; + setAvgEff(0f); + return; } if (wirelessEnabled && modifier >= 1.03F) { // Clamp the EU to the maximum of the hatches so wireless cannot bypass the limitations + long euCapacity = 0; + for (MTEHatch tHatch : getExoticEnergyHatches()) { + if (tHatch instanceof MTEHatchDynamoTunnel tLaserSource) { + euCapacity += tLaserSource.maxEUStore(); + } + } generatedEU = Math.min(generatedEU, euCapacity); this.euLastCycle = generatedEU; addEUToGlobalEnergyMap(owner_uuid, generatedEU); @@ -224,12 +242,6 @@ public class AntimatterGenerator extends MTEExtendedPowerMultiBlockBase @Override public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - this.euCapacity = 0; - for (MTEHatch tHatch : getExoticEnergyHatches()) { - if (tHatch instanceof MTEHatchDynamoTunnel tLaserSource) { - this.euCapacity += tLaserSource.maxEUStore(); - } - } return checkPiece(MAIN_NAME, 17, 41, 0); } @@ -431,7 +443,12 @@ public class AntimatterGenerator extends MTEExtendedPowerMultiBlockBase + EnumChatFormatting.AQUA + GTUtility.formatNumbers(Math.ceil(this.annihilationEfficiency * 100)) + EnumChatFormatting.RESET - + " %" }; + + " %", + StatCollector.translateToLocal("gui.AntimatterGenerator.1") + ": ⟨ " + + EnumChatFormatting.AQUA + + GTUtility.formatNumbers(Math.ceil(this.avgEffCache * 100)) + + EnumChatFormatting.RESET + + " % ⟩₁₀" }; } private long getEnergyProduced() { @@ -442,8 +459,31 @@ public class AntimatterGenerator extends MTEExtendedPowerMultiBlockBase return this.annihilationEfficiency; } + private int n = 0; + + private void setAvgEff(float a) { + if (n == 10) n = 0; + if (this.avgEff.size() < 10) { + this.avgEff.add(a); + } else { + this.avgEff.set(n, a); + n++; + } + + float b = 0; + for (float c : this.avgEff) { + b += c; + } + this.avgEffCache = b == 0 ? 0 : b / this.avgEff.size(); + } + + private float getAvgEfficiency() { + return this.avgEffCache; + } + protected long energyProducedCache; protected float efficiencyCache; + protected float avgEffCache; protected static final NumberFormatMUI numberFormat = new NumberFormatMUI(); protected static DecimalFormat standardFormat; @@ -478,7 +518,17 @@ public class AntimatterGenerator extends MTEExtendedPowerMultiBlockBase + EnumChatFormatting.WHITE + " %") .setDefaultColor(COLOR_TEXT_WHITE.get())) - .widget(new FakeSyncWidget.FloatSyncer(this::getEfficiency, val -> efficiencyCache = val)); + .widget(new FakeSyncWidget.FloatSyncer(this::getEfficiency, val -> efficiencyCache = val)) + .widget( + new TextWidget() + .setStringSupplier( + () -> StatCollector.translateToLocal("gui.AntimatterGenerator.1") + ": ⟨ " + + EnumChatFormatting.RED + + numberFormat.format(Math.ceil(avgEffCache * 100)) + + EnumChatFormatting.WHITE + + " % ⟩₁₀") + .setDefaultColor(COLOR_TEXT_WHITE.get())) + .widget(new FakeSyncWidget.FloatSyncer(this::getAvgEfficiency, val -> avgEffCache = val)); } @Override |