Skip to content

Commit

Permalink
Fix SLAM (Antimatter Generator) produce 0 in wireless mode. Add avg e…
Browse files Browse the repository at this point in the history
…fficiency of 10 last cycles. (#3339)

Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
lordIcocain and Dream-Master authored Oct 13, 2024
1 parent 125f764 commit 0d87030
Showing 1 changed file with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<>() {

Expand Down Expand Up @@ -178,6 +178,12 @@ public CheckRecipeResult checkProcessing() {
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;
Expand All @@ -203,11 +209,23 @@ public void createEU(long antimatter, FluidStack catalyst) {
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);
Expand All @@ -224,12 +242,6 @@ public void createEU(long antimatter, FluidStack catalyst) {

@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);
}

Expand Down Expand Up @@ -431,7 +443,12 @@ public String[] getInfoData() {
+ 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() {
Expand All @@ -442,8 +459,31 @@ private float getEfficiency() {
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;
Expand Down Expand Up @@ -478,7 +518,17 @@ protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inve
+ 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
Expand Down

0 comments on commit 0d87030

Please sign in to comment.